From cef545168d9bdd6346767a55fe985459ff81b606 Mon Sep 17 00:00:00 2001 From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com> Date: Wed, 24 Feb 2021 18:53:48 +0100 Subject: [PATCH] fix: aptic structure init + admin structurename for claim validation --- src/admin/admin.controller.ts | 10 ++++++++-- src/admin/dto/pending-structure.dto.ts | 5 +++++ .../services/aptic-structures.service.ts | 15 ++++++++++++++- src/structures/services/structures.service.ts | 5 ++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/admin/admin.controller.ts b/src/admin/admin.controller.ts index fe16c656f..a3cb5fea6 100644 --- a/src/admin/admin.controller.ts +++ b/src/admin/admin.controller.ts @@ -16,8 +16,14 @@ export class AdminController { @Roles('admin') @Get('pendingStructures') @ApiOperation({ description: 'Get pending structre for validation' }) - public getPendingAttachments(): Promise<PendingStructureDto[]> { - return this.usersService.getPendingStructures(); + public async getPendingAttachments(): Promise<PendingStructureDto[]> { + const pendingStructure = await this.usersService.getPendingStructures(); + return await Promise.all( + pendingStructure.map(async (structure) => { + structure.structureName = (await this.structuresService.findOne(structure.structureId)).structureName; + return structure; + }) + ); } @UseGuards(JwtAuthGuard, RolesGuard) diff --git a/src/admin/dto/pending-structure.dto.ts b/src/admin/dto/pending-structure.dto.ts index 67db37105..e07fd91f8 100644 --- a/src/admin/dto/pending-structure.dto.ts +++ b/src/admin/dto/pending-structure.dto.ts @@ -11,4 +11,9 @@ export class PendingStructureDto { @IsString() @ApiProperty({ type: String }) readonly structureId: string; + + @IsNotEmpty() + @IsString() + @ApiProperty({ type: String }) + structureName: string; } diff --git a/src/structures/services/aptic-structures.service.ts b/src/structures/services/aptic-structures.service.ts index 854a83f04..fff5c3326 100644 --- a/src/structures/services/aptic-structures.service.ts +++ b/src/structures/services/aptic-structures.service.ts @@ -49,12 +49,25 @@ export class ApticStructuresService { if (!exist) { Logger.log(`Create structure : ${structure.presence_name}`, 'ApticStructuresService - createApticStructures'); const createdStructure = new this.structureModel(); - createdStructure.coord = [structure.gps_lng, structure.gps_lat]; + // Known fields createdStructure.structureName = structure.presence_name; createdStructure.contactPhone = structure.presence_phone; + // Unkown fields (but mandatory) + createdStructure.contactMail = 'unknown@unknown.com'; createdStructure.labelsQualifications = ['passNumerique']; + createdStructure.structureType = 'autre'; + createdStructure.pmrAccess = false; + createdStructure.accessModality = ['accesLibre']; + createdStructure.publics = ['toutPublic']; createdStructure.accountVerified = true; + createdStructure.freeWorkShop = false; + createdStructure.nbComputers = null; + createdStructure.nbPrinters = null; + createdStructure.nbScanners = null; + createdStructure.nbTablets = null; + createdStructure.nbNumericTerminal = null; // Address + createdStructure.coord = [structure.gps_lng, structure.gps_lat]; createdStructure.address = this.formatAddress(structure); createdStructure.save(); // Send admin weird structure mail diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 0de3143a2..045ac5a8a 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -122,7 +122,10 @@ export class StructuresService { if (address && address.geometry) { structure.coord = address.geometry.coordinates; } else { - Logger.error(`No coord found: ${structure.address.street}`, 'StructureService'); + Logger.error( + `No coord found for: ${structure.address.numero} ${structure.address.street} ${structure.address.commune}`, + 'StructureService' + ); structure.coord = []; } resolve(structure); -- GitLab