From 22e0bd2eaa6b336a77b4817ccee3d342d1f7d6fd Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Thu, 4 Feb 2021 18:25:16 +0100 Subject: [PATCH] feat: move structureType to back --- .../structure-type/structure-type.controller.ts | 13 +++++++++++++ .../structure-type/structure-type.dto.ts | 4 ++++ .../structure-type/structure-type.schema.ts | 15 +++++++++++++++ .../structure-type/structure-type.service.ts | 13 +++++++++++++ src/structures/structures.module.ts | 14 ++++++++++---- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/structures/structure-type/structure-type.controller.ts create mode 100644 src/structures/structure-type/structure-type.dto.ts create mode 100644 src/structures/structure-type/structure-type.schema.ts create mode 100644 src/structures/structure-type/structure-type.service.ts diff --git a/src/structures/structure-type/structure-type.controller.ts b/src/structures/structure-type/structure-type.controller.ts new file mode 100644 index 000000000..2e530a5dd --- /dev/null +++ b/src/structures/structure-type/structure-type.controller.ts @@ -0,0 +1,13 @@ +import { Controller, Get } from '@nestjs/common'; +import { StructureType } from './structure-type.schema'; +import { StructureTypeService } from './structure-type.service'; + +@Controller('structure-type') +export class StructureTypeController { + constructor(private readonly structureTypeService: StructureTypeService) {} + + @Get() + public async findAll(): Promise<StructureType[]> { + return this.structureTypeService.findAll(); + } +} diff --git a/src/structures/structure-type/structure-type.dto.ts b/src/structures/structure-type/structure-type.dto.ts new file mode 100644 index 000000000..0064714bc --- /dev/null +++ b/src/structures/structure-type/structure-type.dto.ts @@ -0,0 +1,4 @@ +export class CreateStructureType { + name: string; + values: string[]; +} diff --git a/src/structures/structure-type/structure-type.schema.ts b/src/structures/structure-type/structure-type.schema.ts new file mode 100644 index 000000000..faa2ecbb6 --- /dev/null +++ b/src/structures/structure-type/structure-type.schema.ts @@ -0,0 +1,15 @@ +import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; +import { Document } from 'mongoose'; + +export type StructureTypeDocument = StructureType & Document; + +@Schema({ collection: 'structuretype' }) +export class StructureType { + @Prop() + name: string; + + @Prop() + values: string[]; +} + +export const StructureTypeSchema = SchemaFactory.createForClass(StructureType); diff --git a/src/structures/structure-type/structure-type.service.ts b/src/structures/structure-type/structure-type.service.ts new file mode 100644 index 000000000..ea50e0c79 --- /dev/null +++ b/src/structures/structure-type/structure-type.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@nestjs/common'; +import { InjectModel } from '@nestjs/mongoose'; +import { Model } from 'mongoose'; +import { StructureType, StructureTypeDocument } from './structure-type.schema'; + +@Injectable() +export class StructureTypeService { + constructor(@InjectModel(StructureType.name) private structureTypeModel: Model<StructureTypeDocument>) {} + + public async findAll(): Promise<StructureType[]> { + return this.structureTypeModel.find().exec(); + } +} diff --git a/src/structures/structures.module.ts b/src/structures/structures.module.ts index 265eb4076..6494ea3a5 100644 --- a/src/structures/structures.module.ts +++ b/src/structures/structures.module.ts @@ -6,16 +6,22 @@ import { Structure, StructureSchema } from './schemas/structure.schema'; import { StructuresController } from './structures.controller'; import { StructuresService } from './services/structures.service'; import { ApticStructuresService } from './services/aptic-structures.service'; +import { StructureTypeController } from './structure-type/structure-type.controller'; +import { StructureTypeService } from './structure-type/structure-type.service'; +import { StructureType, StructureTypeSchema } from './structure-type/structure-type.schema'; @Module({ imports: [ - MongooseModule.forFeature([{ name: Structure.name, schema: StructureSchema }]), + MongooseModule.forFeature([ + { name: Structure.name, schema: StructureSchema }, + { name: StructureType.name, schema: StructureTypeSchema }, + ]), HttpModule, MailerModule, UsersModule, ], - controllers: [StructuresController], - exports: [StructuresService], - providers: [StructuresService, ApticStructuresService], + controllers: [StructuresController, StructureTypeController], + exports: [StructuresService, StructureTypeService], + providers: [StructuresService, StructureTypeService, ApticStructuresService], }) export class StructuresModule {} -- GitLab