Working on adding in other classes. Not working or tested.
This commit is contained in:
parent
9da88bddf4
commit
375c25110a
@ -3,10 +3,9 @@
|
|||||||
*
|
*
|
||||||
* Developed for MCCS ITS by Skylar Grant
|
* Developed for MCCS ITS by Skylar Grant
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
// Config Stuff
|
// Template strings for requests
|
||||||
const strings = {
|
const strings = {
|
||||||
tokenPrefix: 'Authorization: Zoho-oauthtoken ',
|
tokenPrefix: 'Authorization: Zoho-oauthtoken ',
|
||||||
initiation: {
|
initiation: {
|
||||||
@ -25,8 +24,7 @@ const strings = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** SDP API Client
|
||||||
* SDP API Client
|
|
||||||
* Handles OAuth device authorization flow for Zoho's SDP Cloud API.
|
* Handles OAuth device authorization flow for Zoho's SDP Cloud API.
|
||||||
* @class Client
|
* @class Client
|
||||||
* @constructor
|
* @constructor
|
||||||
@ -99,6 +97,84 @@ class Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Search Criteria Builder
|
||||||
|
* Class to help build search criteria for SDP API requests.
|
||||||
|
* @class SearchCriteriaBuilder
|
||||||
|
* @constructor
|
||||||
|
* @returns {SearchCriteriaBuilder} An instance of the Search Criteria Builder.
|
||||||
|
*/
|
||||||
|
class SearchCriteriaBuilder {
|
||||||
|
constructor() {
|
||||||
|
this.criteria = new Array();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add technician names to the search criteria.
|
||||||
|
* @param {Array<String>} technicianNamesArray Array of technician names
|
||||||
|
* @param {String} condition Condition to use for filtering, "is" or "is not" (Default: "is")
|
||||||
|
* @param {String} operator Operator to use for filtering, "and" or "or" (Optional if first/only criterion)
|
||||||
|
* @returns {SearchCriteriaBuilder}
|
||||||
|
*/
|
||||||
|
addTechnicians(technicianNamesArray, condition, operator) {
|
||||||
|
if (!Array.isArray(technicianNamesArray) || technicianNamesArray.length === 0) {
|
||||||
|
throw new Error('Technician names must be a non-empty array.');
|
||||||
|
}
|
||||||
|
condition = condition || 'is';
|
||||||
|
|
||||||
|
const newCriterion = {
|
||||||
|
field: 'technician.name',
|
||||||
|
condition: condition,
|
||||||
|
values: technicianNamesArray
|
||||||
|
};
|
||||||
|
|
||||||
|
if (operator) {
|
||||||
|
newCriterion.logical_operator = operator;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.criteria.push(newCriterion);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add status names to the search criteria.
|
||||||
|
* @param {Array<String>} statusesArray Array of status names
|
||||||
|
* @param {String} condition Condition to use for filtering, "is" or "is not" (Default: "is not")
|
||||||
|
* @param {String} operator Operator to use for filtering, "and" or "or" (Optional if first/only criterion)
|
||||||
|
* @returns {SearchCriteriaBuilder}
|
||||||
|
*/
|
||||||
|
addStatuses(statusesArray, condition, operator) {
|
||||||
|
if (!Array.isArray(statusesArray) || statusesArray.length === 0) {
|
||||||
|
throw new Error('Statuses must be a non-empty array.');
|
||||||
|
}
|
||||||
|
condition = condition || 'is not';
|
||||||
|
|
||||||
|
const newCriterion = {
|
||||||
|
field: 'status.internal_name',
|
||||||
|
condition: condition,
|
||||||
|
values: statusesArray
|
||||||
|
};
|
||||||
|
if (operator) {
|
||||||
|
newCriterion.logical_operator = operator;
|
||||||
|
}
|
||||||
|
this.criteria.push(newCriterion);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** List Info Builder
|
||||||
|
* Class to help build list info for SDP API requests.
|
||||||
|
* @class ListInfoBuilder
|
||||||
|
* @constructor
|
||||||
|
* @returns {ListInfoBuilder} An instance of the List Info Builder.
|
||||||
|
*/
|
||||||
|
class ListInfoBuilder {
|
||||||
|
constructor() {
|
||||||
|
this.listInfo = {};
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
Client
|
Client,
|
||||||
|
SearchCriteriaBuilder,
|
||||||
|
ListInfoBuilder
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user