From efb6769e309042ecb68ede7b454886b2a956c94c Mon Sep 17 00:00:00 2001 From: Vikram Date: Tue, 15 Nov 2022 20:51:39 +0000 Subject: [PATCH 1/2] fix(export-to-csv): implemented org users pagination --- .../src/util/index.js | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/contentstack-export-to-csv/src/util/index.js b/packages/contentstack-export-to-csv/src/util/index.js index e0fa408499..ba9b95863b 100644 --- a/packages/contentstack-export-to-csv/src/util/index.js +++ b/packages/contentstack-export-to-csv/src/util/index.js @@ -383,7 +383,7 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) { return new Promise((resolve, reject) => { managementAPIClient .getUser({ include_orgs_roles: true }) - .then((response) => { + .then(async (response) => { let organization = response.organizations.filter((org) => org.uid === orgUid).pop(); if (organization.is_owner === true) { let cma = ecsv.region.cma; @@ -396,12 +396,34 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) { if (!organization.getInvitations) { return reject(new Error(config.adminError)); } - organization.getInvitations().then((users) => resolve(users)); + try { + const users = await getUsers(organization, { skip: 0, page: 1, limit: 100 }); + return resolve(users); + } catch (error) { + return reject(error); + } }) .catch((error) => reject(error)); }); } +async function getUsers(organization, params, result = []) { + try { + const users = await organization.getInvitations(params); + if (!users.items || (users.items && !users.items.length)) { + return result; + } else { + result = result.concat(users.items); + params.skip = params.page * params.limit; + params.page++; + await wait(200); + return getUsers(organization, params, result); + } + } catch (error) { + throw error; + } +} + function getMappedUsers(users) { let mappedUsers = {}; users.items.forEach((user) => { @@ -528,6 +550,12 @@ function formatError(error) { return message; } +function wait(time) { + return new Promise(res => { + setTimeout(res, time); + }); +} + module.exports = { chooseOrganization: chooseOrganization, chooseStack: chooseStack, From fe1f920e1835e6c9b818fcec5b541956a3819905 Mon Sep 17 00:00:00 2001 From: Vikram Date: Tue, 15 Nov 2022 20:58:28 +0000 Subject: [PATCH 2/2] fix(export-to-csv): minor fix --- packages/contentstack-export-to-csv/src/util/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-export-to-csv/src/util/index.js b/packages/contentstack-export-to-csv/src/util/index.js index ba9b95863b..45480f805a 100644 --- a/packages/contentstack-export-to-csv/src/util/index.js +++ b/packages/contentstack-export-to-csv/src/util/index.js @@ -398,7 +398,7 @@ function getOrgUsers(managementAPIClient, orgUid, ecsv) { } try { const users = await getUsers(organization, { skip: 0, page: 1, limit: 100 }); - return resolve(users); + return resolve({ items: users }); } catch (error) { return reject(error); }