@couleetech/n8n-nodes-enlightenedmsp
Version:
n8n node for EnlightenedMSP ticketing and workflow automation
62 lines (61 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchCoreCompaniesGraphql = exports.DEFAULT_FIELDS = void 0;
const GraphqlBase_1 = require("./GraphqlBase");
exports.DEFAULT_FIELDS = 'id\nname\ndefaultTicketLevel\ndefaultHourlyRate\nbillingConfigured\nactive\nisOwnCompany\nautotaskCompanyId';
class SearchCoreCompaniesGraphql extends GraphqlBase_1.GraphqlBase {
constructor(endpoint, apiKey, userId) {
super(endpoint, apiKey, userId);
}
async searchCompanies({ name, defaultTicketLevel, defaultHourlyRate, billingConfigured, active, isOwnCompany, autotaskCompanyId, order, page = 1, limit = 10, fields = exports.DEFAULT_FIELDS, }) {
const cleanVariables = {
page,
limit,
};
if (fields) {
cleanVariables.fields = fields;
}
const queryParams = ['$page: Int!', '$limit: Int!'];
const queryArgs = ['page: $page', 'limit: $limit'];
const filterParams = {
name: 'StringProp',
defaultTicketLevel: 'StringProp',
defaultHourlyRate: 'NumberProp',
billingConfigured: 'BooleanProp',
active: 'BooleanProp',
isOwnCompany: 'BooleanProp',
autotaskCompanyId: 'NumberProp',
order: 'SortCoreCompaniesArgs',
};
Object.entries({
name,
defaultTicketLevel,
defaultHourlyRate,
billingConfigured,
active,
isOwnCompany,
autotaskCompanyId,
order,
}).forEach(([key, value]) => {
if (value !== undefined) {
queryParams.push(`$${key}: ${filterParams[key]}`);
queryArgs.push(`${key}: $${key}`);
cleanVariables[key] = value;
}
});
const query = `
query SearchCoreCompanies(${queryParams.join(', ')}) {
findCoreCompaniesPaginated(${queryArgs.join(', ')}) {
data {
${fields}
}
totalCount
page
limit
}
}
`;
return this.executeGraphql(query, cleanVariables);
}
}
exports.SearchCoreCompaniesGraphql = SearchCoreCompaniesGraphql;