Compare commits
21 Commits
6b68570e46
...
renovate/n
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a96ec4007 | |||
| 82c374ed44 | |||
| 3935509b3a | |||
| 51b4cb736b | |||
| a4443cf8d8 | |||
| cd2bbfe240 | |||
| 4efc18c2d9 | |||
| df0a43ecc5 | |||
| 8a90fef0a5 | |||
| aeb0e126c1 | |||
| 29612c3e02 | |||
| e83e5da007 | |||
| 7f4155fcdf | |||
| d3d0d7f1d1 | |||
| b40ed36358 | |||
| 842783cae0 | |||
| 8f1e0cd204 | |||
| 690a640b31 | |||
| 623cdc6c37 | |||
| e9a0e12276 | |||
| 2a99323c91 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
||||
[submodule "src/dto"]
|
||||
path = src/dto
|
||||
url = git@github.com:R40fendt/ritzenbergen-dto.git
|
||||
url = https://git.ritzenbergen.de/Jonas/ritzenbergen-dto.git
|
||||
|
||||
1517
package-lock.json
generated
1517
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -32,24 +32,27 @@
|
||||
"graphql": "^16.12.0",
|
||||
"mercurius": "^16.7.0",
|
||||
"mysql2": "^3.16.2",
|
||||
"node-addon-api": "^8.7.0",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"sharp": "^0.34.5",
|
||||
"typeorm": "^0.3.28"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
"@eslint/js": "^9.18.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@nestjs/cli": "^11.0.0",
|
||||
"@nestjs/schematics": "^11.0.0",
|
||||
"@nestjs/testing": "^11.0.1",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.10.7",
|
||||
"@types/supertest": "^6.0.2",
|
||||
"eslint": "^9.18.0",
|
||||
"@types/node": "^25.0.0",
|
||||
"@types/supertest": "^7.0.0",
|
||||
"eslint": "^9.39.2",
|
||||
"eslint-config-prettier": "^10.0.1",
|
||||
"eslint-plugin-prettier": "^5.2.2",
|
||||
"globals": "^16.0.0",
|
||||
"jest": "^30.0.0",
|
||||
"node-gyp": "^12.3.0",
|
||||
"prettier": "^3.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
|
||||
@@ -11,6 +11,7 @@ import { FormularEntity } from './formular/formular.entity';
|
||||
import { FieldEntity } from './formular/fields.entity';
|
||||
import { FormResultEntity } from './formular/result.entity';
|
||||
import { FormResultsEntity } from './formular/results.entity';
|
||||
import { GalerieModule } from './galerie/galerie.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -31,6 +32,7 @@ import { FormResultsEntity } from './formular/results.entity';
|
||||
entities: [EventEntity, FormularEntity,FieldEntity,FormResultEntity,FormResultsEntity]
|
||||
}),
|
||||
FormularModule,
|
||||
GalerieModule
|
||||
|
||||
],
|
||||
controllers: [AppController],
|
||||
|
||||
2
src/dto
2
src/dto
Submodule src/dto updated: 12938c8125...78d9d15d64
@@ -1,9 +1,10 @@
|
||||
import { Controller, Get, Inject, Param } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Inject, Param, Post } from '@nestjs/common';
|
||||
import { FormularService } from './formular.service';
|
||||
import { Query } from '@nestjs/graphql';
|
||||
import { Formular, MyField } from 'src/dto/formular.dto';
|
||||
import { FormularEntity } from './formular.entity';
|
||||
import { FieldEntity } from './fields.entity';
|
||||
import { ApiBody } from '@nestjs/swagger';
|
||||
|
||||
@Controller('/api/formulare')
|
||||
export class FormularController {
|
||||
@@ -27,12 +28,23 @@ export class FormularController {
|
||||
return await this.formularService.getFields(formularid);
|
||||
}
|
||||
|
||||
@Get("/submit/:formularid")
|
||||
@Post("/submit/:formularid")
|
||||
@ApiBody({
|
||||
schema: {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
})
|
||||
async submit(
|
||||
@Param("formularid")
|
||||
formularid:number
|
||||
){
|
||||
return await this.formularService.submit(formularid);
|
||||
formularid:number,
|
||||
|
||||
@Body()
|
||||
body:any
|
||||
): Promise<boolean>{
|
||||
return await this.formularService.submit(<number>formularid,Object.keys(body),Object.values(body));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { FormularEntity } from './formular.entity';
|
||||
import { FormResultsEntity } from './results.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Formular, MyField } from 'src/dto/formular.dto';
|
||||
import { FieldEntity } from './fields.entity';
|
||||
import { FormResultEntity } from './result.entity';
|
||||
import { FormResultsEntity } from './results.entity';
|
||||
|
||||
@Injectable()
|
||||
export class FormularService {
|
||||
@@ -13,6 +14,10 @@ export class FormularService {
|
||||
private readonly formularRepository: Repository<FormularEntity>,
|
||||
@InjectRepository(FieldEntity)
|
||||
private readonly fieldRepository: Repository<FieldEntity>,
|
||||
@InjectRepository(FormResultsEntity)
|
||||
private readonly formularResultsRepository: Repository<FormResultsEntity>,
|
||||
@InjectRepository(FormResultEntity)
|
||||
private readonly formularResultRepository: Repository<FormResultEntity>
|
||||
){}
|
||||
|
||||
async getFormulare(): Promise<Formular[]>{
|
||||
@@ -24,8 +29,33 @@ export class FormularService {
|
||||
return await this.fieldRepository.findBy({formular: formularid});
|
||||
}
|
||||
async submit(
|
||||
formularid:number
|
||||
){
|
||||
formularid:number,
|
||||
names:string[],
|
||||
values:string[]
|
||||
): Promise<boolean>{
|
||||
|
||||
if(names.length!=values.length) return false;
|
||||
let formResult=await this.formularResultsRepository.create({
|
||||
formular: await this.formularRepository.findBy({id:formularid})[0],
|
||||
formularid: formularid
|
||||
} as FormResultsEntity);
|
||||
|
||||
await this.formularResultsRepository.save(formResult);
|
||||
|
||||
let entities=names.map((name,i)=>{
|
||||
return {
|
||||
name,
|
||||
value: values[i],
|
||||
parentobj: formResult,
|
||||
parentid: formResult.id
|
||||
} as FormResultEntity;
|
||||
});
|
||||
|
||||
const formularResult=this.formularResultRepository.create(entities);
|
||||
|
||||
|
||||
await this.formularResultRepository.save(formularResult);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { Field, ObjectType } from "@nestjs/graphql";
|
||||
import { FormularResult, FormularResults } from "src/dto/formular.dto";
|
||||
import { FormularResult } from "src/dto/formular.dto";
|
||||
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||
import { FormResultsEntity } from "./results.entity";
|
||||
import { FieldEntity } from "./fields.entity";
|
||||
import { RelationIdAttribute } from "typeorm/query-builder/relation-id/RelationIdAttribute.js";
|
||||
|
||||
|
||||
@ObjectType()
|
||||
@@ -21,8 +23,8 @@ export class FormResultEntity implements FormularResult{
|
||||
@JoinColumn({"name":"parentid"})
|
||||
parentobj: FormResultsEntity;
|
||||
|
||||
@Column()
|
||||
@Field()
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
|
||||
118
src/galerie/galerie.controller.ts
Normal file
118
src/galerie/galerie.controller.ts
Normal file
@@ -0,0 +1,118 @@
|
||||
import { Controller, Get, Header, Inject, Param, Res } from '@nestjs/common';
|
||||
import { GalerieService } from './galerie.service';
|
||||
import sharp from 'sharp';
|
||||
import path from 'path';
|
||||
import { Args, Field, ObjectType, Query, Resolver } from '@nestjs/graphql';
|
||||
import { JahrMitBild } from 'src/dto/galerie.dto';
|
||||
|
||||
@Controller('/api/galerie')
|
||||
export class GalerieController {
|
||||
constructor(
|
||||
@Inject()
|
||||
private readonly galerieService: GalerieService,
|
||||
) {}
|
||||
|
||||
@Get('/bilder/:event/:jahr')
|
||||
async getBilder(
|
||||
@Param('event') event: string,
|
||||
@Param('jahr') jahr: number,
|
||||
): Promise<string[]> {
|
||||
return this.galerieService.getBilder(event, jahr);
|
||||
}
|
||||
|
||||
@Get('/jahre/:event')
|
||||
async getJahre(@Param('event') event: string): Promise<JahrMitBild[]> {
|
||||
return this.galerieService.getJahre(event);
|
||||
}
|
||||
|
||||
@Get('/bild/:event/:jahr/:bild')
|
||||
@Header('Content-Type', 'image/png')
|
||||
async getBild(
|
||||
@Param('event')
|
||||
event: string,
|
||||
@Param('jahr')
|
||||
jahr: number,
|
||||
@Param('bild')
|
||||
bild: string,
|
||||
): Promise<Buffer> {
|
||||
const filePath =
|
||||
'/bilder/' +
|
||||
path.basename(event) +
|
||||
'/' +
|
||||
path.basename(jahr.toString()) +
|
||||
'/' +
|
||||
path.basename(bild);
|
||||
|
||||
return sharp(filePath).png().toBuffer();
|
||||
}
|
||||
@Get('/randomimage/:event')
|
||||
@Header('Content-Type', 'image/png')
|
||||
async getRandomImageOhneJahr(
|
||||
@Param('event')
|
||||
event: string,
|
||||
): Promise<Buffer> {
|
||||
const jahr=await this.galerieService.getRandomYear(event)
|
||||
const filePath =
|
||||
'/bilder/' +
|
||||
path.basename(event) +
|
||||
'/' +
|
||||
jahr+
|
||||
'/' +
|
||||
await this.galerieService.getRandomImage(event,jahr)
|
||||
|
||||
return sharp(filePath).png().toBuffer();
|
||||
}
|
||||
@Get('/randomimage/:event/:jahr')
|
||||
@Header('Content-Type', 'image/png')
|
||||
async getRandomImage(
|
||||
@Param('event')
|
||||
event: string,
|
||||
@Param('jahr')
|
||||
jahr: number,
|
||||
): Promise<Buffer> {
|
||||
const filePath =
|
||||
'/bilder/' +
|
||||
path.basename(event) +
|
||||
'/' +
|
||||
path.basename(jahr.toString()) +
|
||||
'/' +
|
||||
await this.galerieService.getRandomImage(event,jahr)
|
||||
|
||||
return sharp(filePath).png().toBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
@Resolver()
|
||||
export class GalerieResolver {
|
||||
constructor(private readonly galerieService: GalerieService) {}
|
||||
|
||||
@Query(() => [String])
|
||||
async getBilder(
|
||||
@Args('event', { type: () => String }) event: string,
|
||||
@Args('jahr', { type: () => Number }) jahr: number,
|
||||
): Promise<string[]> {
|
||||
return this.galerieService.getBilder(event, jahr);
|
||||
}
|
||||
|
||||
@Query(() => [JahrMitBildEntity])
|
||||
async bilder(
|
||||
@Args('event', { type: () => String }) event: string,
|
||||
@Args('jahr', { type: () => Number, nullable: true }) jahr: number,
|
||||
): Promise<JahrMitBildEntity[]> {
|
||||
if(jahr==null) return this.galerieService.getJahre(event);
|
||||
return (await this.galerieService.getJahre(event))
|
||||
.filter(jahrmitbild=>jahrmitbild.jahr==jahr);
|
||||
}
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class JahrMitBildEntity implements JahrMitBild {
|
||||
@Field(() => Number)
|
||||
jahr: number;
|
||||
@Field(() => [String])
|
||||
bild: string[];
|
||||
constructor(jahr: number, bild: string[]) {
|
||||
this.jahr = jahr;
|
||||
this.bild = bild;
|
||||
}
|
||||
}
|
||||
17
src/galerie/galerie.module.ts
Normal file
17
src/galerie/galerie.module.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { GalerieController, GalerieResolver } from './galerie.controller';
|
||||
import { GalerieService } from './galerie.service';
|
||||
|
||||
@Module({
|
||||
imports:[
|
||||
TypeOrmModule.forFeature([])
|
||||
],
|
||||
controllers: [
|
||||
GalerieController
|
||||
],
|
||||
providers: [
|
||||
GalerieService, GalerieResolver
|
||||
]
|
||||
})
|
||||
export class GalerieModule {}
|
||||
61
src/galerie/galerie.service.ts
Normal file
61
src/galerie/galerie.service.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { promises as fs } from 'fs';
|
||||
import * as path from 'path';
|
||||
import { JahrMitBild } from "src/dto/galerie.dto";
|
||||
|
||||
@Injectable()
|
||||
export class GalerieService {
|
||||
private readonly imagesPath = "/bilder";
|
||||
|
||||
constructor(
|
||||
){}
|
||||
|
||||
async getBilder(
|
||||
event: string,
|
||||
jahr: number
|
||||
): Promise<string[]> {
|
||||
const files= await fs.readdir(path.join(this.imagesPath,event, jahr.toString()));
|
||||
|
||||
// Nur Bilddateien filtern
|
||||
const imageFiles = files.filter(file =>
|
||||
/\.(jpg|jpeg|png|gif|webp)$/i.test(file)
|
||||
);
|
||||
|
||||
return imageFiles;
|
||||
}
|
||||
|
||||
async getJahre(
|
||||
event: string
|
||||
): Promise<JahrMitBild[]> {
|
||||
const files= await fs.readdir(path.join(this.imagesPath,event).toString());
|
||||
|
||||
// Nur Verzeichnisse filtern (Jahre)
|
||||
const directories: JahrMitBild[] = [];
|
||||
for (const file of files) {
|
||||
const filePath = path.join(this.imagesPath, event, file);
|
||||
const stat = await fs.stat(filePath);
|
||||
if (stat.isDirectory()) {
|
||||
directories.push(new JahrMitBild(parseInt(file), await this.getBilder(event,parseInt(file))));
|
||||
}
|
||||
}
|
||||
return directories;
|
||||
}
|
||||
|
||||
async getRandomImage(event: string, jahr: number): Promise<string>{
|
||||
|
||||
const bilder=await this.getBilder(event,jahr);
|
||||
|
||||
const index = Math.floor(Math.random() * bilder.length);
|
||||
|
||||
return bilder[index];
|
||||
|
||||
}
|
||||
|
||||
async getRandomYear(event:string): Promise<number>{
|
||||
const jahre=(await this.getJahre(event)).map((jahr)=>jahr.jahr);
|
||||
|
||||
const index = Math.floor(Math.random() * jahre.length);
|
||||
return jahre[index];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user