From d3b7e377d6b83d9b6b09f574f470268346135ba7 Mon Sep 17 00:00:00 2001
From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com>
Date: Wed, 21 Apr 2021 14:44:40 +0200
Subject: [PATCH] feat: change creation way for entities init

---
 src/services/initialization.service.ts | 33 ++++++++++----------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts
index 37296f77e..ec3330a2d 100644
--- a/src/services/initialization.service.ts
+++ b/src/services/initialization.service.ts
@@ -188,11 +188,9 @@ export default class InitializationService {
     ) {
       // Populate the doctype with data
       try {
-        await Promise.all(
-          ecogestureData.map(async ecogesture => {
-            await this._client.create(ECOGESTURE_DOCTYPE, ecogesture)
-          })
-        )
+        for (let i = 0; i <= ecogestureData.length - 1; i++) {
+          await this._client.create(ECOGESTURE_DOCTYPE, ecogestureData[i])
+        }
         // Check of created document based on count
         const checkCount = await ecogestureService.getAllEcogestures()
         if (
@@ -266,11 +264,10 @@ export default class InitializationService {
     ) {
       // Populate the doctype with data
       try {
-        await Promise.all(
-          challengeEntityData.map(async challengeEntity => {
-            await this._client.create(CHALLENGE_DOCTYPE, challengeEntity)
-          })
-        )
+        for (let i = 0; i <= challengeEntityData.length - 1; i++) {
+          await this._client.create(CHALLENGE_DOCTYPE, challengeEntityData[i])
+        }
+
         // Check of created document
         const checkCount = await challengeService.getAllChallengeEntities()
         if (
@@ -340,11 +337,9 @@ export default class InitializationService {
     if (!loadedDuelTypes || (loadedDuelTypes && loadedDuelTypes.length === 0)) {
       // Populate the doctype with data
       try {
-        await Promise.all(
-          duelEntityData.map(async duelEntity => {
-            await this._client.create(DUEL_DOCTYPE, duelEntity)
-          })
-        )
+        for (let i = 0; i <= duelEntityData.length - 1; i++) {
+          await this._client.create(DUEL_DOCTYPE, duelEntityData[i])
+        }
         // Check of created document
         const checkCount = await duelService.getAllDuelEntities()
         if (
@@ -417,11 +412,9 @@ export default class InitializationService {
     ) {
       // Populate the doctype with data
       try {
-        await Promise.all(
-          quizEntityData.map(async quizEntity => {
-            await this._client.create(QUIZ_DOCTYPE, quizEntity)
-          })
-        )
+        for (let i = 0; i <= quizEntityData.length - 1; i++) {
+          await this._client.create(QUIZ_DOCTYPE, quizEntityData[i])
+        }
         // Check of created document
         const checkCount = await quizService.getAllQuizEntities()
         if (
-- 
GitLab