From 01392dae2d4d1f464e3b2c1b57c110eb068b8919 Mon Sep 17 00:00:00 2001
From: "Gomez Goiri, Aitor" <aitor.gomez@tecnalia.com>
Date: Fri, 10 Dec 2021 16:24:15 +0100
Subject: [PATCH] Fixing await related issues in user generation script

---
 scripts/create-users.js | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/scripts/create-users.js b/scripts/create-users.js
index ccb1e34..c3066f9 100644
--- a/scripts/create-users.js
+++ b/scripts/create-users.js
@@ -33,7 +33,7 @@ const modifyUser = async (
   return modUser
 }
 
-const createOrModifyUserIfNeeded = (
+const createOrModifyUserIfNeeded = async (
   apiClient,
   username,
   password,
@@ -42,7 +42,7 @@ const createOrModifyUserIfNeeded = (
 ) => {
   try {
     // Await is needed here to force the catch clausule if something goes wrong
-    return apiClient.createUser(
+    return await apiClient.createUser(
       username,
       password,
       organization,
@@ -62,7 +62,8 @@ const createUsers = async () => {
     process.env.TRACEBLOCK_CHAINCODE
   )
 
-  Object.entries(usersByOrg).forEach(async ([org, values]) => {
+  for (let el of Object.entries(usersByOrg)) {
+    const [org, values] = el
     const admin = values.find(v => v.role === "admin")
 
     await apiClient.signIn(admin.user, readPassword(admin.user, org), org)
@@ -81,7 +82,7 @@ const createUsers = async () => {
       )
 
     await Promise.all(prom)
-  })
+  }
 
   console.log("Users created")
 }
-- 
GitLab