/**
* People Resource
* Generated: 2025-04-01T19:44:53.328Z
*/
export class PeopleResource {
/**
* Create a new People resource
* @param {ApiClient} client - API client instance
*/
constructor(client) {
this.client = client;
this.resourcePath = '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}`
});
}
/**
* Sum field values
* Calculate the sum of a specified numeric field across filtered records.
* @param {Object} [query] - Query parameters
* @returns {Promise<any>} - Response with data and headers
*/
async getPeopleSum(query = {}) {
let url = '/people/sum'
;
return await this.client.request({
method: 'get',
url,
params: query,
});
}
/**
* Count records
* Count the number of records that match the specified criteria.
* @param {Object} [query] - Query parameters
* @returns {Promise<any>} - Response with data and headers
*/
async getPeopleCount(query = {}) {
let url = '/people/count'
;
return await this.client.request({
method: 'get',
url,
params: query,
});
}
/**
* List Person (find where)
* Find a list of **Person** records that match the specified criteria.
* @param {Object} [query] - Query parameters
* @returns {Promise<person[]>} - Response with data and headers
*/
async getPeople(query = {}) {
let url = '/people'
;
return await this.client.request({
method: 'get',
url,
params: query,
});
}
/**
* Create Person
* Create a new **Person** record.
* @param {Object} data - Request body
* @returns {Promise<person>} - Response with data and headers
*/
async postPeople(data) {
let url = '/people'
;
return await this.client.request({
method: 'post',
url,
data,
});
}
/**
* Get Person (find one)
* Look up the **Person** record with the specified ID.
* @param {Object} [query] - Query parameters
* @returns {Promise<person>} - Response with data and headers
*/
async getPeopleId(query = {}) {
let url = '/people/{_id}'
;
return await this.client.request({
method: 'get',
url,
params: query,
});
}
/**
* Update Person
* Update an existing **Person** record.
* @param {Object} data - Request body
* @returns {Promise<person>} - Response with data and headers
*/
async patchPeopleId(data) {
let url = '/people/{_id}'
;
return await this.client.request({
method: 'patch',
url,
data,
});
}
/**
* Delete Person (destroy)
* Delete the **Person** record with the specified ID.
* @returns {Promise<person>} - Response with data and headers
*/
async deletePeopleId() {
let url = '/people/{_id}'
;
return await this.client.request({
method: 'delete',
url,
});
}
/**
* Add to for Person
* Add a foreign record to one of this **Person** record's collections.
* @param {string} association - Path parameter
* @param {string} childid - Path parameter
* @returns {Promise<person>} - Response with data and headers
*/
async putPeopleIdAssociationChildid(association, childid, ) {
let url = '/people/{_id}/{association}/{childid}'
.replace('association', encodeURIComponent(association))
.replace('childid', encodeURIComponent(childid))
;
return await this.client.request({
method: 'put',
url,
});
}
/**
* Remove from for Person
* Remove a foreign record from one of this **Person** record's collections.
* @param {string} association - Path parameter
* @param {string} childid - Path parameter
* @returns {Promise<person>} - Response with data and headers
*/
async deletePeopleIdAssociationChildid(association, childid, ) {
let url = '/people/{_id}/{association}/{childid}'
.replace('association', encodeURIComponent(association))
.replace('childid', encodeURIComponent(childid))
;
return await this.client.request({
method: 'delete',
url,
});
}
/**
* Replace for Person
* Replace all of the child records in one of this **Person** record's associations.
* @param {string} association - Path parameter
* @param {Object} data - Request body
* @returns {Promise<person>} - Response with data and headers
*/
async putPeopleIdAssociation(association, data) {
let url = '/people/{_id}/{association}'
.replace('association', encodeURIComponent(association))
;
return await this.client.request({
method: 'put',
url,
data,
});
}
/**
* Populate association for Person
* Populate and return foreign record(s) for the given association of this **Person** record.
* @param {string} association - Path parameter
* @param {Object} [query] - Query parameters
* @returns {Promise<any[]>} - Response with data and headers
*/
async getPeopleIdAssociation(association, query = {}) {
let url = '/people/{_id}/{association}'
.replace('association', encodeURIComponent(association))
;
return await this.client.request({
method: 'get',
url,
params: query,
});
}
}
/**
* 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 PeopleResource