51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
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 {
|
|
constructor(
|
|
@Inject()
|
|
private readonly formularService: FormularService
|
|
){}
|
|
|
|
@Get("/")
|
|
@Query(()=>[FormularEntity])
|
|
async formulare(): Promise<Formular[]>{
|
|
return await this.formularService.getFormulare();
|
|
}
|
|
|
|
@Get("/:formularid")
|
|
@Query(()=>[FieldEntity])
|
|
async fields(
|
|
@Param("formularid")
|
|
formularid:number
|
|
): Promise<MyField[]>{
|
|
return await this.formularService.getFields(formularid);
|
|
}
|
|
|
|
@Post("/submit/:formularid")
|
|
@ApiBody({
|
|
schema: {
|
|
type: 'object',
|
|
additionalProperties: {
|
|
type: 'string',
|
|
},
|
|
},
|
|
})
|
|
async submit(
|
|
@Param("formularid")
|
|
formularid:number,
|
|
|
|
@Body()
|
|
body:any
|
|
): Promise<boolean>{
|
|
return await this.formularService.submit(<number>formularid,Object.keys(body),Object.values(body));
|
|
}
|
|
|
|
}
|