From 375c25110a51e6efe24a9f1afa91155d224f0bad Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Tue, 6 Jan 2026 15:56:02 -0500 Subject: [PATCH] Working on adding in other classes. Not working or tested. --- src/modules/sdp-api.js | 86 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 5 deletions(-) diff --git a/src/modules/sdp-api.js b/src/modules/sdp-api.js index 69f94c6..e24d12e 100644 --- a/src/modules/sdp-api.js +++ b/src/modules/sdp-api.js @@ -3,10 +3,9 @@ * * Developed for MCCS ITS by Skylar Grant */ - const axios = require('axios'); -// Config Stuff +// Template strings for requests const strings = { tokenPrefix: 'Authorization: Zoho-oauthtoken ', initiation: { @@ -25,8 +24,7 @@ const strings = { } } -/** - * SDP API Client +/** SDP API Client * Handles OAuth device authorization flow for Zoho's SDP Cloud API. * @class Client * @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} 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} 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 = { - Client + Client, + SearchCriteriaBuilder, + ListInfoBuilder } \ No newline at end of file