Skip to content
Snippets Groups Projects
Commit 638d5cac authored by Jérémie BRISON's avatar Jérémie BRISON
Browse files

feat(createStructure) : link structure to a profil

parent 138e4d8e
No related branches found
No related tags found
3 merge requests!27Recette,!26Dev,!10Feat/create structure
import { Type } from 'class-transformer';
import { ArrayNotEmpty, IsNotEmpty, ValidateNested } from 'class-validator';
import { Address } from '../schemas/address.schema';
import { Week } from '../schemas/week.schema';
import { IsNotEmpty, ValidateNested } from 'class-validator';
import { structureDto } from './structure.dto';
export class CreateStructureDto {
id: number;
numero: string;
createdAt: string;
updatedAt: string;
@IsNotEmpty()
structureRepresentation: string;
@IsNotEmpty()
structureName: string;
@ArrayNotEmpty()
structureType: string[];
@IsNotEmpty()
description: string;
@ValidateNested({ each: true })
@Type(() => Address)
address: Address;
@IsNotEmpty()
contactPhone: string;
@Type(() => structureDto)
structure: structureDto;
@IsNotEmpty()
contactMail: string;
website: string;
facebook: string;
twitter: string;
instagram: string;
gender: string;
contactName: string;
contactSurname: string;
fonction: string;
lockdownActivity: string;
pmrAccess: boolean;
publicsAccompaniment: string[];
proceduresAccompaniment: string[];
@ArrayNotEmpty()
accessModality: string[];
documentsMeeting: string;
labelsQualifications: string[];
@ArrayNotEmpty()
publics: string[];
nbComputers: number;
nbPrinters: number;
nbTablets: number;
nbNumericTerminal: number;
exceptionalClosures: string;
equipmentsAndServices: string[];
hours: Week;
equipmentsDetails: string;
equipmentsAccessType: string[];
baseSkills: string[];
accessRight: string[];
parentingHelp: string[];
socialAndProfessional: string[];
digitalCultureSecurity: string[];
coord: number[];
idUser: string;
}
import { Type } from 'class-transformer';
import { ArrayNotEmpty, IsNotEmpty, ValidateNested } from 'class-validator';
import { Address } from '../schemas/address.schema';
import { Week } from '../schemas/week.schema';
export class structureDto {
id: number;
numero: string;
createdAt: string;
updatedAt: string;
@IsNotEmpty()
structureRepresentation: string;
@IsNotEmpty()
structureName: string;
@ArrayNotEmpty()
structureType: string[];
@IsNotEmpty()
description: string;
@ValidateNested({ each: true })
@Type(() => Address)
address: Address;
@IsNotEmpty()
contactPhone: string;
@IsNotEmpty()
contactMail: string;
website: string;
facebook: string;
twitter: string;
instagram: string;
gender: string;
contactName: string;
contactSurname: string;
fonction: string;
lockdownActivity: string;
pmrAccess: boolean;
publicsAccompaniment: string[];
proceduresAccompaniment: string[];
@ArrayNotEmpty()
accessModality: string[];
documentsMeeting: string;
labelsQualifications: string[];
@ArrayNotEmpty()
publics: string[];
nbComputers: number;
nbPrinters: number;
nbTablets: number;
nbNumericTerminal: number;
exceptionalClosures: string;
equipmentsAndServices: string[];
hours: Week;
equipmentsDetails: string;
equipmentsAccessType: string[];
baseSkills: string[];
accessRight: string[];
parentingHelp: string[];
socialAndProfessional: string[];
digitalCultureSecurity: string[];
coord: number[];
}
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
import { CreateStructureDto } from './dto/create-structure.dto';
import { QueryStructure } from './dto/query-structure.dto';
import { structureDto } from './dto/structure.dto';
import { Structure } from './schemas/structure.schema';
import { StructuresService } from './structures.service';
......@@ -10,7 +11,7 @@ export class StructuresController {
@Post()
public async create(@Body() createStructureDto: CreateStructureDto): Promise<Structure> {
return this.structureService.create(createStructureDto);
return this.structureService.create(createStructureDto.idUser, createStructureDto.structure);
}
@Post('search')
......@@ -19,7 +20,7 @@ export class StructuresController {
}
@Post(':id')
public async update(@Param('id') id: number, @Body() body: CreateStructureDto) {
public async update(@Param('id') id: number, @Body() body: structureDto) {
return this.structureService.update(id, body);
}
......
import { HttpModule, Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { MailerModule } from '../mailer/mailer.module';
import { UsersModule } from '../users/users.module';
import { Structure, StructureSchema } from './schemas/structure.schema';
import { StructuresController } from './structures.controller';
import { StructuresService } from './structures.service';
@Module({
imports: [MongooseModule.forFeature([{ name: Structure.name, schema: StructureSchema }]), HttpModule, MailerModule],
imports: [
MongooseModule.forFeature([{ name: Structure.name, schema: StructureSchema }]),
HttpModule,
MailerModule,
UsersModule,
],
controllers: [StructuresController],
providers: [StructuresService],
})
......
......@@ -3,21 +3,29 @@ import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Observable } from 'rxjs';
import { AxiosResponse } from 'axios';
import { CreateStructureDto } from './dto/create-structure.dto';
import { Structure, StructureDocument } from './schemas/structure.schema';
import { Logger } from '@nestjs/common';
import { structureDto } from './dto/structure.dto';
import { UsersService } from '../users/users.service';
@Injectable()
export class StructuresService {
constructor(
private readonly httpService: HttpService,
private readonly usersService: UsersService,
@InjectModel(Structure.name) private structureModel: Model<StructureDocument>
) {}
public async create(createStructrureDto: CreateStructureDto): Promise<Structure> {
let createdStructure = new this.structureModel(createStructrureDto);
public async create(idUser: string, structureDto: structureDto): Promise<Structure> {
const user = await this.usersService.findOne(idUser);
if (!user) {
throw new HttpException('Invalid profile', HttpStatus.NOT_FOUND);
}
let createdStructure = new this.structureModel(structureDto);
createdStructure.id = (await this.getNumberStructures()) + 1;
createdStructure.save();
user.structuresLink.push(createdStructure.id);
user.save();
return createdStructure;
}
......@@ -78,7 +86,7 @@ export class StructuresService {
return this.structureModel.find().exec();
}
public async update(idStructure: number, structure: CreateStructureDto): Promise<Structure> {
public async update(idStructure: number, structure: structureDto): Promise<Structure> {
const result = await this.structureModel.update({ id: idStructure }, structure);
if (!result) {
throw new HttpException('Invalid structure id', HttpStatus.BAD_REQUEST);
......
......@@ -10,4 +10,5 @@ export interface IUser extends Document {
role: number;
changeEmailToken: string;
newEmail: string;
structuresLink: number[];
}
......@@ -25,6 +25,8 @@ export class User {
@Prop({ default: null })
newEmail: string;
@Prop({ default: null })
structuresLink: number[];
}
export const UserSchema = SchemaFactory.createForClass(User);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment