From 02c07d1add056ee6225f4ed25eb373398ada1cc5 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 7 Jan 2026 15:12:26 -0500 Subject: [PATCH] Implemented ListInfoBuilder a bit more. Not working. --- src/main.js | 25 +++++++++++++++--- src/modules/sdp-api.js | 59 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index d907b98..62492a8 100644 --- a/src/main.js +++ b/src/main.js @@ -8,10 +8,12 @@ const dotenv = require('dotenv'); dotenv.config({ quiet: true }); const { CLIENT_ID, CLIENT_SECRET } = process.env; -const { Client } = require('./modules/sdp-api'); +const { Client, ListInfoBuilder, SearchCriteriaBuilder } = require('./modules/sdp-api'); const client = new Client(CLIENT_ID, CLIENT_SECRET); +const technicianNamesArray = process.env.TECHNICIAN_NAMES.split(','); +const statusNamesArray = process.env.STATUS_NAMES.split(','); -async function main() { +async function authInitLoop() { await client.init(); console.log(`Please visit ${client.verificationUrl} and enter the code: ${client.userCode}`); @@ -33,6 +35,21 @@ async function main() { }, client.pollInterval + 500); } -main().catch(err => { - console.error('Error in main execution:', err.message); +async function pullRequests() { + try { + const listInfo = new ListInfoBuilder() + .setRowCount(10); + + const searchCriteria = new SearchCriteriaBuilder() + .addTechnicians(technicianNamesArray, "is") + .addStatuses(statusNamesArray, "is", "and"); + + listInfo.data.search_criteria = searchCriteria.data; + } catch (error) { + console.error('Error pulling requests:', error.message); + } +} + +authInitLoop().catch(err => { + console.error('Error in authInitLoop execution:', err.message); }); \ No newline at end of file diff --git a/src/modules/sdp-api.js b/src/modules/sdp-api.js index e24d12e..13d2582 100644 --- a/src/modules/sdp-api.js +++ b/src/modules/sdp-api.js @@ -105,7 +105,7 @@ class Client { */ class SearchCriteriaBuilder { constructor() { - this.criteria = new Array(); + this.data = new Array(); return this; } @@ -131,7 +131,7 @@ class SearchCriteriaBuilder { newCriterion.logical_operator = operator; } - this.criteria.push(newCriterion); + this.data.push(newCriterion); return this; } @@ -155,7 +155,7 @@ class SearchCriteriaBuilder { if (operator) { newCriterion.logical_operator = operator; } - this.criteria.push(newCriterion); + this.data.push(newCriterion); return this; } } @@ -168,7 +168,58 @@ class SearchCriteriaBuilder { */ class ListInfoBuilder { constructor() { - this.listInfo = {}; + this.data = { + row_count: 100, + start_index: 0, + sort_field: 'last_updated_time', + sort_order: 'desc', + get_total_count: true + }; + return this; + } + + setRowCount(count) { + if (typeof count !== 'number' || count <= 0) { + throw new Error('Row count must be a positive number.'); + } + this.data.row_count = count; + return this; + } + + setStartIndex(index) { + if (typeof index !== 'number' || index < 0) { + throw new Error('Start index must be a non-negative number.'); + } + this.data.start_index = index; + return this; + } + + setSortField(field) { + if (typeof field !== 'string' || field.trim() === '') { + throw new Error('Sort field must be a non-empty string.'); + } + this.data.sort_field = field; + return this; + } + + setSortOrder(order) { + if (order !== 'asc' && order !== 'desc') { + throw new Error('Sort order must be either "asc" or "desc".'); + } + this.data.sort_order = order; + return this; + } + + enableTotalCount(enable) { + this.data.get_total_count = Boolean(enable); + return this; + } + + setSearchCriteria(criteriaArray) { + if (!Array.isArray(criteriaArray)) { + throw new Error('Search criteria must be an array.'); + } + this.data.search_criteria = criteriaArray; return this; } }