From 44adce894275cb171649632701098f2cd6a32d8a Mon Sep 17 00:00:00 2001 From: JettTech Date: Fri, 19 Jul 2024 22:43:59 -0500 Subject: [PATCH 1/4] update endpoint to match hbs endpoint edit --- src/services/hbs.js | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/services/hbs.js b/src/services/hbs.js index f653e18..e1db977 100644 --- a/src/services/hbs.js +++ b/src/services/hbs.js @@ -72,13 +72,39 @@ async function registrationFetchHostCriteria(payload, environment, hbsServicePor } } -export async function fetchHostCriteria(hostIds, environment, hbsServicePort) { - const payload = { - "ids": hostIds || [] - } +// Returns: +// [ +// { +// "_id": "string", +// "jurisdiction": "string", +// "kyc": "string", // Note: Either holo_kyc_1 or holo_kyc_2 +// "error": "string", +// "pubkey": "string" +// } +// ] +export async function fetchHostCriteria(hostIds, environment, hbsServicePort, page = 0, itemsPerPage = 50) { + let currentPageNumber = page; + let hostsWithCriteria, totalItems, currentItems + do { + console.log(`Fetching next page (p${currentPageNumber}) from uptime records...`) + const payload = { + "page": currentPageNumber, + "itemsPerPage": itemsPerPage, + "ids": hostIds || [] + } + + const result = await registrationFetchHostCriteria(payload, environment, hbsServicePort) - const result = await registrationFetchHostCriteria(payload, environment, hbsServicePort) - return result + for (item in result.items) { + hostsWithCriteria.push(item) + } + + currentPageNumber = result.page + 1; // NB: the first page starts at 0, not 1 + currentItems = currentPageNumber * result.itemsPerPage; + totalItems = result.totalItems; + } while (totalItems > currentItems); + + return hostsWithCriteria } export async function registrationFetchJurisdictions(environment, hbsServicePort) { From a4224b83f2c9d3db2916365f7bc2041d4d1f1486 Mon Sep 17 00:00:00 2001 From: JettTech Date: Sat, 20 Jul 2024 00:57:14 -0500 Subject: [PATCH 2/4] clean --- src/services/hbs.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/services/hbs.js b/src/services/hbs.js index e1db977..eb62d90 100644 --- a/src/services/hbs.js +++ b/src/services/hbs.js @@ -77,31 +77,38 @@ async function registrationFetchHostCriteria(payload, environment, hbsServicePor // { // "_id": "string", // "jurisdiction": "string", -// "kyc": "string", // Note: Either holo_kyc_1 or holo_kyc_2 +// "kyc": "string", // Note: Either `holo_kyc_1` or `holo_kyc_2` // "error": "string", // "pubkey": "string" // } // ] -export async function fetchHostCriteria(hostIds, environment, hbsServicePort, page = 0, itemsPerPage = 50) { +export async function fetchHostCriteria(hostIds = [], environment, hbsServicePort, page = 0, itemsPerPage = 50) { let currentPageNumber = page; - let hostsWithCriteria, totalItems, currentItems + let hostsWithCriteria = []; + let currentItems = 0 + let totalItems = itemsPerPage + do { - console.log(`Fetching next page (p${currentPageNumber}) from uptime records...`) + console.log(`Fetching page ${currentPageNumber} from uptime records...`) const payload = { "page": currentPageNumber, "itemsPerPage": itemsPerPage, "ids": hostIds || [] } - const result = await registrationFetchHostCriteria(payload, environment, hbsServicePort) + // TODO: This endpoint needs to be update in HBS to return the standard hbs "pagination" type, + // which returns a result obj containing 3 things: items, page, & totalItems. + // Note: This currently endpoint implementation seems to return ALL results still, which means it doesn't matter right now + // that the result obj isn't reutrning the total number of items, as we get the full run the first time + const items = await registrationFetchHostCriteria(payload, environment, hbsServicePort) - for (item in result.items) { + for (let item of items) { hostsWithCriteria.push(item) } - - currentPageNumber = result.page + 1; // NB: the first page starts at 0, not 1 - currentItems = currentPageNumber * result.itemsPerPage; - totalItems = result.totalItems; + + currentPageNumber++; // result.page + 1 // NB: the first page starts at 0, not 1 + currentItems = currentPageNumber * itemsPerPage; // result.itemsPerPage + totalItems = totalItems; // result.totalItems } while (totalItems > currentItems); return hostsWithCriteria From 98e281d31c081e92d971487fc17a163249e9d2a2 Mon Sep 17 00:00:00 2001 From: JettTech Date: Sat, 20 Jul 2024 00:58:18 -0500 Subject: [PATCH 3/4] small edit --- src/services/hbs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/hbs.js b/src/services/hbs.js index eb62d90..1d675d5 100644 --- a/src/services/hbs.js +++ b/src/services/hbs.js @@ -93,7 +93,7 @@ export async function fetchHostCriteria(hostIds = [], environment, hbsServicePor const payload = { "page": currentPageNumber, "itemsPerPage": itemsPerPage, - "ids": hostIds || [] + "ids": hostIds } // TODO: This endpoint needs to be update in HBS to return the standard hbs "pagination" type, From 853667350694a5224129111adb29c0eba68d6f7d Mon Sep 17 00:00:00 2001 From: JettTech Date: Sun, 21 Jul 2024 22:51:08 -0500 Subject: [PATCH 4/4] update fetch-host-criteria endpoint with hbs update --- src/services/hbs.js | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/services/hbs.js b/src/services/hbs.js index 1d675d5..b7b52ce 100644 --- a/src/services/hbs.js +++ b/src/services/hbs.js @@ -83,32 +83,29 @@ async function registrationFetchHostCriteria(payload, environment, hbsServicePor // } // ] export async function fetchHostCriteria(hostIds = [], environment, hbsServicePort, page = 0, itemsPerPage = 50) { - let currentPageNumber = page; let hostsWithCriteria = []; let currentItems = 0 - let totalItems = itemsPerPage + // Initialize `totalItems` with the page number for first HBS loop + // ...once first loop is complete, `totalItems` will be updated with full number of records in the collection + let totalItems = itemsPerPage; do { - console.log(`Fetching page ${currentPageNumber} from uptime records...`) + console.log(`Fetching page ${page} from uptime records...`) const payload = { - "page": currentPageNumber, + "page": page, "itemsPerPage": itemsPerPage, "ids": hostIds } - // TODO: This endpoint needs to be update in HBS to return the standard hbs "pagination" type, - // which returns a result obj containing 3 things: items, page, & totalItems. - // Note: This currently endpoint implementation seems to return ALL results still, which means it doesn't matter right now - // that the result obj isn't reutrning the total number of items, as we get the full run the first time - const items = await registrationFetchHostCriteria(payload, environment, hbsServicePort) + const result = await registrationFetchHostCriteria(payload, environment, hbsServicePort) - for (let item of items) { + for (let item of result.items) { hostsWithCriteria.push(item) } - currentPageNumber++; // result.page + 1 // NB: the first page starts at 0, not 1 - currentItems = currentPageNumber * itemsPerPage; // result.itemsPerPage - totalItems = totalItems; // result.totalItems + page = result.page + 1 // NB: pages are 0-indexed + currentItems = page * result.itemsPerPage + totalItems = result.totalItems } while (totalItems > currentItems); return hostsWithCriteria