Added form results
This commit is contained in:
@@ -9,6 +9,8 @@ import { EventEntity } from './events/events.entity';
|
|||||||
import { FormularModule } from './formular/formular.module';
|
import { FormularModule } from './formular/formular.module';
|
||||||
import { FormularEntity } from './formular/formular.entity';
|
import { FormularEntity } from './formular/formular.entity';
|
||||||
import { FieldEntity } from './formular/fields.entity';
|
import { FieldEntity } from './formular/fields.entity';
|
||||||
|
import { FormResultEntity } from './formular/result.entity';
|
||||||
|
import { FormResultsEntity } from './formular/results.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -26,7 +28,7 @@ import { FieldEntity } from './formular/fields.entity';
|
|||||||
password: process.env.DB_PASSWORD || 'root',
|
password: process.env.DB_PASSWORD || 'root',
|
||||||
database: process.env.DB_NAME || 'ritzenbergen',
|
database: process.env.DB_NAME || 'ritzenbergen',
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
entities: [EventEntity, FormularEntity,FieldEntity]
|
entities: [EventEntity, FormularEntity,FieldEntity,FormResultEntity,FormResultsEntity]
|
||||||
}),
|
}),
|
||||||
FormularModule,
|
FormularModule,
|
||||||
|
|
||||||
|
|||||||
2
src/dto
2
src/dto
Submodule src/dto updated: 7a379bf72e...12938c8125
@@ -27,4 +27,12 @@ export class FormularController {
|
|||||||
return await this.formularService.getFields(formularid);
|
return await this.formularService.getFields(formularid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("/submit/:formularid")
|
||||||
|
async submit(
|
||||||
|
@Param("formularid")
|
||||||
|
formularid:number
|
||||||
|
){
|
||||||
|
return await this.formularService.submit(formularid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { Field, ObjectType } from "@nestjs/graphql";
|
import { Field, ObjectType } from "@nestjs/graphql";
|
||||||
import { Formular, MyField } from "src/dto/formular.dto";
|
import { Formular, FormularResults, MyField } from "src/dto/formular.dto";
|
||||||
import { Column, Entity, OneToMany, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
import { Column, Entity, ManyToOne, OneToMany, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm";
|
||||||
import { FieldEntity } from "./fields.entity";
|
import { FieldEntity } from "./fields.entity";
|
||||||
|
import { FormResultsEntity } from "./results.entity";
|
||||||
|
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
@@ -30,4 +31,8 @@ export class FormularEntity implements Formular{
|
|||||||
@Field(()=>[FieldEntity])
|
@Field(()=>[FieldEntity])
|
||||||
@OneToMany(()=>FieldEntity,field=>field.formularObject)
|
@OneToMany(()=>FieldEntity,field=>field.formularObject)
|
||||||
public fields: FieldEntity[];
|
public fields: FieldEntity[];
|
||||||
|
|
||||||
|
@Field(()=>[FormResultsEntity])
|
||||||
|
@OneToMany(()=>FormResultsEntity,entity=>entity.formular)
|
||||||
|
public results: FormResultsEntity[];
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,12 @@ import { FormularEntity } from './formular.entity';
|
|||||||
import { FormularController } from './formular.controller';
|
import { FormularController } from './formular.controller';
|
||||||
import { FormularService } from './formular.service';
|
import { FormularService } from './formular.service';
|
||||||
import { FieldEntity } from './fields.entity';
|
import { FieldEntity } from './fields.entity';
|
||||||
|
import { FormResultEntity } from './result.entity';
|
||||||
|
import { FormResultsEntity } from './results.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports:[
|
imports:[
|
||||||
TypeOrmModule.forFeature([FormularEntity,FieldEntity])
|
TypeOrmModule.forFeature([FormularEntity,FieldEntity,FormResultEntity,FormResultsEntity])
|
||||||
],
|
],
|
||||||
controllers: [
|
controllers: [
|
||||||
FormularController
|
FormularController
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { 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';
|
||||||
@@ -11,16 +12,20 @@ export class FormularService {
|
|||||||
@InjectRepository(FormularEntity)
|
@InjectRepository(FormularEntity)
|
||||||
private readonly formularRepository: Repository<FormularEntity>,
|
private readonly formularRepository: Repository<FormularEntity>,
|
||||||
@InjectRepository(FieldEntity)
|
@InjectRepository(FieldEntity)
|
||||||
private readonly fieldRepository: Repository<FieldEntity>
|
private readonly fieldRepository: Repository<FieldEntity>,
|
||||||
){}
|
){}
|
||||||
|
|
||||||
async getFormulare(): Promise<Formular[]>{
|
async getFormulare(): Promise<Formular[]>{
|
||||||
return await this.formularRepository.find({relations: ['fields']});
|
return await this.formularRepository.find({relations: ['fields',"results","results.results"]});
|
||||||
}
|
}
|
||||||
async getFields(
|
async getFields(
|
||||||
formularid:number
|
formularid:number
|
||||||
): Promise<MyField[]>{
|
): Promise<MyField[]>{
|
||||||
return await this.fieldRepository.findBy({formular: formularid});
|
return await this.fieldRepository.findBy({formular: formularid});
|
||||||
|
}
|
||||||
|
async submit(
|
||||||
|
formularid:number
|
||||||
|
){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
src/formular/result.entity.ts
Normal file
32
src/formular/result.entity.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { Field, ObjectType } from "@nestjs/graphql";
|
||||||
|
import { FormularResult, FormularResults } from "src/dto/formular.dto";
|
||||||
|
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
import { FormResultsEntity } from "./results.entity";
|
||||||
|
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
@Entity()
|
||||||
|
export class FormResultEntity implements FormularResult{
|
||||||
|
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
@Field()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
@Field()
|
||||||
|
parentid: number;
|
||||||
|
|
||||||
|
@Field(()=>FormResultsEntity)
|
||||||
|
@ManyToOne(()=>FormResultsEntity,entity=>entity.id)
|
||||||
|
@JoinColumn({"name":"parentid"})
|
||||||
|
parentobj: FormResultsEntity;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
@Field()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
@Field()
|
||||||
|
value: string;
|
||||||
|
|
||||||
|
}
|
||||||
28
src/formular/results.entity.ts
Normal file
28
src/formular/results.entity.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { Field, ObjectType } from "@nestjs/graphql";
|
||||||
|
import { Formular, FormularResult, FormularResults } from "src/dto/formular.dto";
|
||||||
|
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn } from "typeorm";
|
||||||
|
import { FormularEntity } from "./formular.entity";
|
||||||
|
import { FormResultEntity } from "./result.entity";
|
||||||
|
|
||||||
|
|
||||||
|
@ObjectType()
|
||||||
|
@Entity()
|
||||||
|
export class FormResultsEntity implements FormularResults{
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
@Field()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@ManyToOne(()=>FormularEntity,entity=>entity.id)
|
||||||
|
@Field(()=>FormularEntity)
|
||||||
|
@JoinColumn({name:"formularid"})
|
||||||
|
formular: FormularEntity;
|
||||||
|
|
||||||
|
@Field()
|
||||||
|
@Column()
|
||||||
|
formularid: number;
|
||||||
|
|
||||||
|
@Field(()=>[FormResultEntity])
|
||||||
|
@OneToMany(()=>FormResultEntity,entity=>entity.parentobj)
|
||||||
|
results: FormResultEntity[];
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user