From 8fd705f5b4e769905c96496f064cf63b105aa8de Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Fri, 26 Feb 2021 14:37:07 +0100
Subject: [PATCH] fix: bug on admin validation

---
 src/admin/admin.controller.ts | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/admin/admin.controller.ts b/src/admin/admin.controller.ts
index a3cb5fea6..858a0dcdb 100644
--- a/src/admin/admin.controller.ts
+++ b/src/admin/admin.controller.ts
@@ -32,12 +32,19 @@ export class AdminController {
   @ApiOperation({ description: 'Validate structure ownership' })
   public async validatePendingStructure(@Body() pendingStructureDto: PendingStructureDto) {
     const structure = await this.structuresService.findOne(pendingStructureDto.structureId);
-    return this.usersService.validatePendingStructure(
+    await this.usersService.validatePendingStructure(
       pendingStructureDto.userEmail,
       pendingStructureDto.structureId,
       structure.structureName,
       true
     );
+    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)
@@ -46,11 +53,18 @@ export class AdminController {
   @ApiOperation({ description: 'Refuse structure ownership' })
   public async refusePendingStructure(@Body() pendingStructureDto: PendingStructureDto) {
     const structure = await this.structuresService.findOne(pendingStructureDto.structureId);
-    return this.usersService.validatePendingStructure(
+    await this.usersService.validatePendingStructure(
       pendingStructureDto.userEmail,
       pendingStructureDto.structureId,
       structure.structureName,
       false
     );
+    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;
+      })
+    );
   }
 }
-- 
GitLab