Compare commits
1 Commits
6b68570e46
...
2a99323c91
| Author | SHA1 | Date | |
|---|---|---|---|
| 2a99323c91 |
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,3 +1,3 @@
|
|||||||
[submodule "src/dto"]
|
[submodule "src/dto"]
|
||||||
path = 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 { FormularService } from './formular.service';
|
||||||
import { Query } from '@nestjs/graphql';
|
import { Query } from '@nestjs/graphql';
|
||||||
import { Formular, MyField } from 'src/dto/formular.dto';
|
import { Formular, MyField } from 'src/dto/formular.dto';
|
||||||
import { FormularEntity } from './formular.entity';
|
import { FormularEntity } from './formular.entity';
|
||||||
import { FieldEntity } from './fields.entity';
|
import { FieldEntity } from './fields.entity';
|
||||||
|
import { ApiBody } from '@nestjs/swagger';
|
||||||
|
|
||||||
@Controller('/api/formulare')
|
@Controller('/api/formulare')
|
||||||
export class FormularController {
|
export class FormularController {
|
||||||
@@ -27,12 +28,23 @@ export class FormularController {
|
|||||||
return await this.formularService.getFields(formularid);
|
return await this.formularService.getFields(formularid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/submit/:formularid")
|
@Post("/submit/:formularid")
|
||||||
|
@ApiBody({
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
additionalProperties: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
async submit(
|
async submit(
|
||||||
@Param("formularid")
|
@Param("formularid")
|
||||||
formularid:number
|
formularid:number,
|
||||||
){
|
|
||||||
return await this.formularService.submit(formularid);
|
@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 { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { FormularEntity } from './formular.entity';
|
import { FormularEntity } from './formular.entity';
|
||||||
import { FormResultsEntity } from './results.entity';
|
|
||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { Formular, MyField } from 'src/dto/formular.dto';
|
import { Formular, MyField } from 'src/dto/formular.dto';
|
||||||
import { FieldEntity } from './fields.entity';
|
import { FieldEntity } from './fields.entity';
|
||||||
|
import { FormResultEntity } from './result.entity';
|
||||||
|
import { FormResultsEntity } from './results.entity';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FormularService {
|
export class FormularService {
|
||||||
@@ -13,6 +14,10 @@ export class FormularService {
|
|||||||
private readonly formularRepository: Repository<FormularEntity>,
|
private readonly formularRepository: Repository<FormularEntity>,
|
||||||
@InjectRepository(FieldEntity)
|
@InjectRepository(FieldEntity)
|
||||||
private readonly fieldRepository: Repository<FieldEntity>,
|
private readonly fieldRepository: Repository<FieldEntity>,
|
||||||
|
@InjectRepository(FormResultsEntity)
|
||||||
|
private readonly formularResultsRepository: Repository<FormResultsEntity>,
|
||||||
|
@InjectRepository(FormResultEntity)
|
||||||
|
private readonly formularResultRepository: Repository<FormResultEntity>
|
||||||
){}
|
){}
|
||||||
|
|
||||||
async getFormulare(): Promise<Formular[]>{
|
async getFormulare(): Promise<Formular[]>{
|
||||||
@@ -24,8 +29,33 @@ export class FormularService {
|
|||||||
return await this.fieldRepository.findBy({formular: formularid});
|
return await this.fieldRepository.findBy({formular: formularid});
|
||||||
}
|
}
|
||||||
async submit(
|
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 { 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 { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { FormResultsEntity } from "./results.entity";
|
import { FormResultsEntity } from "./results.entity";
|
||||||
|
import { FieldEntity } from "./fields.entity";
|
||||||
|
import { RelationIdAttribute } from "typeorm/query-builder/relation-id/RelationIdAttribute.js";
|
||||||
|
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@@ -21,8 +23,8 @@ export class FormResultEntity implements FormularResult{
|
|||||||
@JoinColumn({"name":"parentid"})
|
@JoinColumn({"name":"parentid"})
|
||||||
parentobj: FormResultsEntity;
|
parentobj: FormResultsEntity;
|
||||||
|
|
||||||
@Column()
|
|
||||||
@Field()
|
@Field()
|
||||||
|
@Column()
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
|
|||||||
Reference in New Issue
Block a user