Implemented ListInfoBuilder a bit more. Not working.
This commit is contained in:
parent
375c25110a
commit
02c07d1add
25
src/main.js
25
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);
|
||||
});
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user