Added Formular and Field
This commit is contained in:
@@ -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 {}
|
||||
|
||||
2
src/dto
2
src/dto
Submodule src/dto updated: d6ae29cd12...7a379bf72e
@@ -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>(EventsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -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';
|
||||
|
||||
@@ -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>(EventsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -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>(FieldsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('fields')
|
||||
export class FieldsController {}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FieldsController } from './fields.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [FieldsController]
|
||||
})
|
||||
export class FieldsModule {}
|
||||
@@ -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>(FieldsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class FieldsService {}
|
||||
74
src/formular/fields.entity.ts
Normal file
74
src/formular/fields.entity.ts
Normal file
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
@@ -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>(FormularController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -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<Formular[]>{
|
||||
return await this.formularService.getFormulare();
|
||||
}
|
||||
|
||||
@Get("/:formularid")
|
||||
@Query(()=>[FieldEntity])
|
||||
async fields(
|
||||
@Param("formularid")
|
||||
formularid:number
|
||||
): Promise<MyField[]>{
|
||||
return await this.formularService.getFields(formularid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
src/formular/formular.entity.ts
Normal file
33
src/formular/formular.entity.ts
Normal file
@@ -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[];
|
||||
}
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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>(FormularService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -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<FormularEntity>,
|
||||
@InjectRepository(FieldEntity)
|
||||
private readonly fieldRepository: Repository<FieldEntity>
|
||||
){}
|
||||
|
||||
async getFormulare(): Promise<Formular[]>{
|
||||
return await this.formularRepository.find({relations: ['fields']});
|
||||
}
|
||||
async getFields(
|
||||
formularid:number
|
||||
): Promise<MyField[]>{
|
||||
return await this.fieldRepository.findBy({formular: formularid});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user