cce-unified-config
Advanced tools
Comparing version 0.7.0 to 0.7.1
43
index.js
@@ -88,19 +88,36 @@ const axios = require('axios') | ||
async list(type, q) { | ||
// pass params from input | ||
const params = {q} | ||
// pass params from input, and set max results | ||
const params = { | ||
q, | ||
resultsPerPage: 100, | ||
startIndex: 0 | ||
} | ||
try { | ||
const response = await axios.get(this.url + type.toLowerCase(), {auth: this.auth, params}) | ||
let response = await axios.get(this.url + type.toLowerCase(), {auth: this.auth, params}) | ||
let totalResults = response.data.pageInfo.totalResults | ||
// good response? | ||
if (response.data[`${type}s`] && response.data[`${type}s`][0] && response.data[`${type}s`][0][`${type}`]) { | ||
const data = response.data[`${type}s`][0][`${type}`] | ||
// is response object an array or object? | ||
if (Array.isArray(data)) { | ||
// return array as-is | ||
if (totalResults === 0) { | ||
// no results | ||
return [] | ||
} else { | ||
// 1 or more results | ||
let data = response.data[`${type}s`][0][`${type}`] | ||
if (totalResults === 1) { | ||
// return single result object as an array | ||
return [data] | ||
} else { | ||
// more than 1 result | ||
// check if there are more results to fetch | ||
while (totalResults > params.startIndex + 100) { | ||
// go get more results | ||
// increase cursor | ||
params.startIndex += 100 | ||
// fetch next data set | ||
response = await axios.get(this.url + type.toLowerCase(), {auth: this.auth, params}) | ||
// append data | ||
data = data.concat(response.data[`${type}s`][0][`${type}`]) | ||
} | ||
// all done, return data array | ||
return data | ||
} else { | ||
// return single result as array | ||
return [data] | ||
} | ||
} else { | ||
return [] | ||
} | ||
@@ -107,0 +124,0 @@ } catch (e) { |
{ | ||
"name": "cce-unified-config", | ||
"version": "0.7.0", | ||
"version": "0.7.1", | ||
"description": "JavaScript library for Cisco Contact Center Enterprise APIs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
7502
206