From 315bb64371f8f333e9c9d17ddbb3017888b4f0e5 Mon Sep 17 00:00:00 2001 From: chavda-bhavik Date: Fri, 21 Jun 2024 14:52:14 +0530 Subject: [PATCH] feat: Improved payment user migrations to consider delay --- .../register-payment-users.migration.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/api/src/migrations/register-payment-users/register-payment-users.migration.ts b/apps/api/src/migrations/register-payment-users/register-payment-users.migration.ts index 4c98f2ebc..2de03cc40 100644 --- a/apps/api/src/migrations/register-payment-users/register-payment-users.migration.ts +++ b/apps/api/src/migrations/register-payment-users/register-payment-users.migration.ts @@ -20,13 +20,20 @@ export async function run() { if (users.length > 0) { // eslint-disable-next-line no-console - for (const user of users) { - await paymentAPIService.createUser({ - email: user.email, - externalId: user.email, - name: `${user.firstName} ${user.lastName}`, - }); - } + await Promise.all( + users.map(async (user) => { + try { + await paymentAPIService.createUser({ + email: user.email, + externalId: user.email, + name: `${user.firstName} ${user.lastName}`, + }); + await new Promise((resolve) => setTimeout(resolve, 1000)); + } catch (error) { + console.error(error); + } + }) + ); } // eslint-disable-next-line no-console