diff --git a/src/app.module.ts b/src/app.module.ts index e95b0b0..10eb378 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -6,11 +6,9 @@ import { MercuriusDriver, MercuriusDriverConfig } from '@nestjs/mercurius'; import { EventsModule } from './events/events.module'; import { TypeOrmModule } from '@nestjs/typeorm'; import { EventEntity } from './events/events.entity'; -import { FormularController } from './formular/formular.controller'; -import { FormularService } from './formular/formular.service'; -import { FieldsService } from './fields/fields.service'; import { FormularModule } from './formular/formular.module'; -import { FieldsModule } from './fields/fields.module'; +import { FormularEntity } from './formular/formular.entity'; +import { FieldEntity } from './formular/fields.entity'; @Module({ imports: [ @@ -28,15 +26,13 @@ import { FieldsModule } from './fields/fields.module'; password: process.env.DB_PASSWORD || 'root', database: process.env.DB_NAME || 'ritzenbergen', synchronize: true, - entities: [EventEntity] + entities: [EventEntity, FormularEntity,FieldEntity] }), FormularModule, - FieldsModule, - ], - controllers: [AppController, FormularController], - providers: [AppService, AppController, FormularService, FieldsService], + controllers: [AppController], + providers: [AppService, AppController], }) export class AppModule {} diff --git a/src/dto b/src/dto index d6ae29c..7a379bf 160000 --- a/src/dto +++ b/src/dto @@ -1 +1 @@ -Subproject commit d6ae29cd12d9e0bacad361aaeb33525ffc81abf8 +Subproject commit 7a379bf72e1969184e1369d0674b5bf20144bb44 diff --git a/src/events/events.controller.spec.ts b/src/events/events.controller.spec.ts deleted file mode 100644 index 6e45c1f..0000000 --- a/src/events/events.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { EventsController } from './events.controller'; - -describe('EventsController', () => { - let controller: EventsController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [EventsController], - }).compile(); - - controller = module.get(EventsController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/src/events/events.controller.ts b/src/events/events.controller.ts index 3df9203..c90f253 100644 --- a/src/events/events.controller.ts +++ b/src/events/events.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Inject, Injectable } from '@nestjs/common'; +import { Controller, Get } from '@nestjs/common'; import { Query } from '@nestjs/graphql'; import { EventsService } from './events.service'; import { EventEntity } from './events.entity'; diff --git a/src/events/events.service.spec.ts b/src/events/events.service.spec.ts deleted file mode 100644 index f26bdfe..0000000 --- a/src/events/events.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { EventsService } from './events.service'; - -describe('EventsService', () => { - let service: EventsService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [EventsService], - }).compile(); - - service = module.get(EventsService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/src/fields/fields.controller.spec.ts b/src/fields/fields.controller.spec.ts deleted file mode 100644 index f4d0ad1..0000000 --- a/src/fields/fields.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { FieldsController } from './fields.controller'; - -describe('FieldsController', () => { - let controller: FieldsController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [FieldsController], - }).compile(); - - controller = module.get(FieldsController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/src/fields/fields.controller.ts b/src/fields/fields.controller.ts deleted file mode 100644 index aeb8e44..0000000 --- a/src/fields/fields.controller.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Controller } from '@nestjs/common'; - -@Controller('fields') -export class FieldsController {} diff --git a/src/fields/fields.module.ts b/src/fields/fields.module.ts deleted file mode 100644 index 5d42d6b..0000000 --- a/src/fields/fields.module.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Module } from '@nestjs/common'; -import { FieldsController } from './fields.controller'; - -@Module({ - controllers: [FieldsController] -}) -export class FieldsModule {} diff --git a/src/fields/fields.service.spec.ts b/src/fields/fields.service.spec.ts deleted file mode 100644 index 571714b..0000000 --- a/src/fields/fields.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { FieldsService } from './fields.service'; - -describe('FieldsService', () => { - let service: FieldsService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [FieldsService], - }).compile(); - - service = module.get(FieldsService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/src/fields/fields.service.ts b/src/fields/fields.service.ts deleted file mode 100644 index b93e9c7..0000000 --- a/src/fields/fields.service.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { Injectable } from '@nestjs/common'; - -@Injectable() -export class FieldsService {} diff --git a/src/formular/fields.entity.ts b/src/formular/fields.entity.ts new file mode 100644 index 0000000..acab161 --- /dev/null +++ b/src/formular/fields.entity.ts @@ -0,0 +1,74 @@ +import { Field, ObjectType } from "@nestjs/graphql"; +import { FieldType, MyField } from "src/dto/formular.dto"; +import { Column, Entity, ForeignKey, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from "typeorm"; +import { FormularEntity } from "./formular.entity"; + + +@ObjectType() +@Entity() +export class FieldEntity implements MyField { + @Field() + @PrimaryGeneratedColumn() + id: number; + + @Field() + @Column() + formular: number; + + @Field(()=>FormularEntity) + @ManyToOne(()=>FormularEntity,entity=>entity.id) + @JoinColumn({name:'formular'}) + formularObject: FormularEntity; + + @Field() + @Column() + name: string; + + @Field({nullable:true}) + @Column({nullable:true}) + displayname: string; + + @Field() + @Column() + value: string; + + @Field({nullable:true}) + @Column({nullable: true}) + displayvalue: string; + + @Field({nullable:true}) + @Column({nullable: true}) + placeholder: string; + + @Field() + @Column("enum",{ + enum: FieldType + }) + type: FieldType; + + @Field({nullable:true}) + @Column({nullable: true}) + title: string; + + @Field() + @Column({default: false}) + required: boolean; + + @Field({nullable:true}) + @Column({nullable: true}) + maxlength: number; + + @Field({nullable:true}) + @Column({nullable: true}) + min: number; + + @Field({nullable:true}) + @Column({nullable: true}) + max: number; + + @Field({nullable:true}) + @Column({nullable: true}) + checked?: boolean; + + +} \ No newline at end of file diff --git a/src/formular/formular.controller.spec.ts b/src/formular/formular.controller.spec.ts deleted file mode 100644 index b89f456..0000000 --- a/src/formular/formular.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { FormularController } from './formular.controller'; - -describe('FormularController', () => { - let controller: FormularController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [FormularController], - }).compile(); - - controller = module.get(FormularController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/src/formular/formular.controller.ts b/src/formular/formular.controller.ts index 1d7a8e1..a56348a 100644 --- a/src/formular/formular.controller.ts +++ b/src/formular/formular.controller.ts @@ -1,6 +1,30 @@ -import { Controller } from '@nestjs/common'; +import { Controller, Get, Inject, Param } 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'; @Controller('/api/formulare') export class FormularController { + constructor( + @Inject() + private readonly formularService: FormularService + ){} + + @Get("/") + @Query(()=>[FormularEntity]) + async formulare(): Promise{ + return await this.formularService.getFormulare(); + } + + @Get("/:formularid") + @Query(()=>[FieldEntity]) + async fields( + @Param("formularid") + formularid:number + ): Promise{ + return await this.formularService.getFields(formularid); + } } diff --git a/src/formular/formular.entity.ts b/src/formular/formular.entity.ts new file mode 100644 index 0000000..a4fe4f8 --- /dev/null +++ b/src/formular/formular.entity.ts @@ -0,0 +1,33 @@ +import { Field, ObjectType } from "@nestjs/graphql"; +import { Formular, MyField } from "src/dto/formular.dto"; +import { Column, Entity, OneToMany, PrimaryColumn, PrimaryGeneratedColumn } from "typeorm"; +import { FieldEntity } from "./fields.entity"; + + +@ObjectType() +@Entity() +export class FormularEntity implements Formular{ + @Field() + @PrimaryGeneratedColumn() + public id: number; + + @Field() + @Column() + public name: string; + + @Field() + @Column() + public minitext: string; + + @Field() + @Column() + public ispublic: boolean; + + @Field() + @Column() + public multiple: boolean; + + @Field(()=>[FieldEntity]) + @OneToMany(()=>FieldEntity,field=>field.formularObject) + public fields: FieldEntity[]; +} \ No newline at end of file diff --git a/src/formular/formular.module.ts b/src/formular/formular.module.ts index 0904e7c..c4bc28d 100644 --- a/src/formular/formular.module.ts +++ b/src/formular/formular.module.ts @@ -1,4 +1,19 @@ import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { FormularEntity } from './formular.entity'; +import { FormularController } from './formular.controller'; +import { FormularService } from './formular.service'; +import { FieldEntity } from './fields.entity'; -@Module({}) +@Module({ + imports:[ + TypeOrmModule.forFeature([FormularEntity,FieldEntity]) + ], + controllers: [ + FormularController + ], + providers: [ + FormularService, FormularController + ] +}) export class FormularModule {} diff --git a/src/formular/formular.service.spec.ts b/src/formular/formular.service.spec.ts deleted file mode 100644 index 33f3d9e..0000000 --- a/src/formular/formular.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { FormularService } from './formular.service'; - -describe('FormularService', () => { - let service: FormularService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [FormularService], - }).compile(); - - service = module.get(FormularService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/src/formular/formular.service.ts b/src/formular/formular.service.ts index 92fa5fb..31a32e2 100644 --- a/src/formular/formular.service.ts +++ b/src/formular/formular.service.ts @@ -1,4 +1,26 @@ import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { FormularEntity } from './formular.entity'; +import { Repository } from 'typeorm'; +import { Formular, MyField } from 'src/dto/formular.dto'; +import { FieldEntity } from './fields.entity'; @Injectable() -export class FormularService {} +export class FormularService { + constructor( + @InjectRepository(FormularEntity) + private readonly formularRepository: Repository, + @InjectRepository(FieldEntity) + private readonly fieldRepository: Repository + ){} + + async getFormulare(): Promise{ + return await this.formularRepository.find({relations: ['fields']}); + } + async getFields( + formularid:number + ): Promise{ + return await this.fieldRepository.findBy({formular: formularid}); + + } +}