Compare commits
1 Commits
6b68570e46
...
2a99323c91
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user