/**
* PersonCertificationsProfessionalcertificationPeople Resource
* Generated: 2025-04-01T19:44:53.334Z
*/
export class PersonCertificationsProfessionalcertificationPeopleResource {
/**
* Create a new PersonCertificationsProfessionalcertificationPeople resource
* @param {ApiClient} client - API client instance
*/
constructor(client) {
this.client = client;
this.resourcePath = 'person_certifications__professionalcertification_people'; // Preserve the exact path name
// Make QueryChain methods available at the resource level
this.then = (resolve, reject) => this.find().execute().then(resolve, reject);
}
/**
* Starts a new query chain with the given criteria
* @param {Object} criteria - Filter criteria
* @returns {QueryChain} - Query chain for further operations
*/
find(criteria = {}) {
return new QueryChain(this.client, this.resourcePath, criteria);
}
/**
* Find a single record by id
* @param {string|number} id - Record id
* @param {string|string[]} [populate] - Fields to populate
* @returns {QueryChain|Promise<Object>} - Query chain for further operations or found record with data and headers
*/
findOne(id, populate) {
const query = this.find({ id });
if (populate) {
query.populate(populate);
}
// Add a custom executeOne method that will be called when awaited
const originalThen = query.then;
query.then = (resolve, reject) => {
return query.executeOne().then(resolve, reject);
};
return query;
}
/**
* Create a new record
* @param {Object} data - Record data
* @returns {Promise<Object>} - Created record with data and headers
*/
async create(data) {
return await this.client.request({
method: 'post',
url: `/${this.resourcePath}`,
data
});
}
/**
* Update a record by id
* @param {string|number} id - Record id
* @param {Object} data - Update data
* @returns {Promise<Object>} - Updated record with data and headers
*/
async update(id, data) {
return await this.client.request({
method: 'patch',
url: `/${this.resourcePath}/${id}`,
data
});
}
/**
* Delete a record by id
* @param {string|number} id - Record id
* @returns {Promise<Object>} - Deletion result with data and headers
*/
async destroy(id) {
return await this.client.request({
method: 'delete',
url: `/${this.resourcePath}/${id}`
});
}
/**
* /person_certifications__professionalcertification_people
*
* @returns {Promise<void>} - Response with data and headers
*/
async getPersonCertificationsProfessionalcertificationPeople() {
let url = '/person_certifications__professionalcertification_people'
;
return await this.client.request({
method: 'get',
url,
});
}
/**
* /person_certifications__professionalcertification_people
*
* @returns {Promise<void>} - Response with data and headers
*/
async postPersonCertificationsProfessionalcertificationPeople() {
let url = '/person_certifications__professionalcertification_people'
;
return await this.client.request({
method: 'post',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{id}
*
* @param {string} id - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async getPersonCertificationsProfessionalcertificationPeopleId(id, ) {
let url = '/person_certifications__professionalcertification_people/{id}'
.replace('id', encodeURIComponent(id))
;
return await this.client.request({
method: 'get',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{id}
*
* @param {string} id - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async patchPersonCertificationsProfessionalcertificationPeopleId(id, ) {
let url = '/person_certifications__professionalcertification_people/{id}'
.replace('id', encodeURIComponent(id))
;
return await this.client.request({
method: 'patch',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{id}
*
* @param {string} id - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async deletePersonCertificationsProfessionalcertificationPeopleId(id, ) {
let url = '/person_certifications__professionalcertification_people/{id}'
.replace('id', encodeURIComponent(id))
;
return await this.client.request({
method: 'delete',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{id}
*
* @param {string} id - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async putPersonCertificationsProfessionalcertificationPeopleId(id, ) {
let url = '/person_certifications__professionalcertification_people/{id}'
.replace('id', encodeURIComponent(id))
;
return await this.client.request({
method: 'put',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{parentid}/person_certifications
*
* @param {string} parentid - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async getPersonCertificationsProfessionalcertificationPeopleParentidPersonCertifications(parentid, ) {
let url = '/person_certifications__professionalcertification_people/{parentid}/person_certifications'
.replace('parentid', encodeURIComponent(parentid))
;
return await this.client.request({
method: 'get',
url,
});
}
/**
* /person_certifications__professionalcertification_people/{parentid}/professionalcertification_people
*
* @param {string} parentid - Path parameter
* @returns {Promise<void>} - Response with data and headers
*/
async getPersonCertificationsProfessionalcertificationPeopleParentidProfessionalcertificationPeople(parentid, ) {
let url = '/person_certifications__professionalcertification_people/{parentid}/professionalcertification_people'
.replace('parentid', encodeURIComponent(parentid))
;
return await this.client.request({
method: 'get',
url,
});
}
}
/**
* Query chain for waterline-like syntax
*/
class QueryChain {
constructor(client, resourceName, criteria = {}) {
this.client = client;
this.resourceName = resourceName;
this.criteria = { ...criteria };
this.limitValue = null;
this.skipValue = 0;
this.sortValue = null;
this.selectFields = null;
this.populateFields = null;
// Make the QueryChain thenable
this.then = (resolve, reject) => this.execute().then(resolve, reject);
}
/**
* Set the maximum number of records to return
* @param {number} limit - Maximum number of records
* @returns {QueryChain} - This query chain
*/
limit(limit) {
this.limitValue = limit;
return this;
}
/**
* Set the number of records to skip
* @param {number} skip - Number of records to skip
* @returns {QueryChain} - This query chain
*/
skip(skip) {
this.skipValue = skip;
return this;
}
/**
* Set the fields to select
* @param {string[]} fields - Fields to select
* @returns {QueryChain} - This query chain
*/
select(fields) {
this.selectFields = Array.isArray(fields) ? fields : [fields];
return this;
}
/**
* Set the sort order
* @param {Object|string} sort - Sort criteria
* @returns {QueryChain} - This query chain
*/
sort(sort) {
this.sortValue = sort;
return this;
}
/**
* Specify fields to populate
* @param {string[]} fields - Fields to populate
* @returns {QueryChain} - This query chain
*/
populate(fields) {
this.populateFields = Array.isArray(fields) ? fields : [fields];
return this;
}
/**
* Execute the query
* @returns {Promise<Object>} - Found records with data and headers
*/
async execute() {
const queryParams = { ...this.criteria };
if (this.limitValue !== null) {
queryParams.limit = this.limitValue;
}
if (this.skipValue > 0) {
queryParams.skip = this.skipValue;
}
if (this.sortValue) {
queryParams.sort = this.sortValue;
}
if (this.selectFields) {
queryParams.select = this.selectFields.join(',');
}
if (this.populateFields) {
queryParams.populate = this.populateFields.join(',');
}
return await this.client.request({
method: 'get',
url: `/${this.resourceName}`,
params: queryParams
});
}
/**
* Execute the query and return a single record
* @returns {Promise<Object>} - Found record with data and headers
*/
async executeOne() {
const response = await this.limit(1).execute();
if (response.data && Array.isArray(response.data)) {
return {
data: response.data.length > 0 ? response.data[0] : null,
headers: response.headers
};
}
return response;
}
/**
* Count records matching the criteria
* @returns {Promise<Object>} - Count of matching records with data and headers
*/
async count() {
const response = await this.client.request({
method: 'get',
url: `/${this.resourceName}/count`,
params: this.criteria
});
if (response.data) {
return {
data: { count: response.data.count || 0 },
headers: response.headers
};
}
return response;
}
}
export default PersonCertificationsProfessionalcertificationPeopleResource