Skip to content

Commit

Permalink
Merge pull request #109 from Holo-Host/refactor/remove-hbs-host-crite…
Browse files Browse the repository at this point in the history
…ria-call

Refactor/remove-host-jurisdiction-call
  • Loading branch information
JettTech authored Aug 27, 2024
2 parents 77b3910 + 521eef5 commit a2a8cb5
Showing 1 changed file with 0 additions and 70 deletions.
70 changes: 0 additions & 70 deletions src/services/hbs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async function authCall(args, environment, hbsServicePort) {
...args
})
}

export async function authenticateAgent(payload, signature, environment, hbsServicePort) {
try {
const result = await authCall({
Expand Down Expand Up @@ -42,75 +41,6 @@ export async function fetchAgentKycLevel(payload, signature, environment, hbsSer
return (authResult && authResult.kyc) ? (authResult.kyc === kycLevel2) ? 2 : 1 : null
}


async function registrationCall(args, environment, hbsServicePort) {
return httpCall({
serviceUrl: registrationServiceUrl(environment),
version: registrationServiceVersion(hbsServicePort),
method: 'post',
...args
})
}

async function registrationFetchHostCriteria(payload, environment, hbsServicePort) {
try {
const result = await registrationCall({
params: payload,
endpoint: 'fetch-host-criteria',
},
environment,
hbsServicePort
)

return result.data
} catch (e) {
if (axios.isAxiosError(e)) {
return e.message
} else {
return 'unknown error'
}
}
}

// 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 hostsWithCriteria = [];
let currentItems = 0
// 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 ${page} from uptime records...`)
const payload = {
"page": page,
"itemsPerPage": itemsPerPage,
"ids": hostIds
}

const result = await registrationFetchHostCriteria(payload, environment, hbsServicePort)

for (let item of result.items) {
hostsWithCriteria.push(item)
}

page = result.page + 1 // NB: pages are 0-indexed
currentItems = page * result.itemsPerPage
totalItems = result.totalItems
} while (totalItems > currentItems);

return hostsWithCriteria
}

export async function registrationFetchJurisdictions(environment, hbsServicePort) {
const result = httpCall({
serviceUrl: registrationServiceUrl(environment),
Expand Down

0 comments on commit a2a8cb5

Please sign in to comment.