/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import RequestHelper from '../../RequestHelper';
import DefinitionModel from '../../Models/Site/DefinitionModel';
/**
* Controller Class for Definitions
*
* @class
*/
class DefinitionController
{
/**
* Retrieve a Definition [GET /sites/{siteId}/definitions/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Definition ID
* @return {Promise<DefinitionModel>}
*/
static getOne(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/definitions/${id}`)
.then((result) => {
let resolveValue = (function(){
return DefinitionModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a Definition [PATCH /sites/{siteId}/definitions/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Definition ID
* @param {DefinitionController.UpdateData} updateData The Definition Update Data
* @return {Promise<DefinitionModel>}
*/
static update(siteId, id, updateData)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/sites/${siteId}/definitions/${id}`, updateData)
.then((result) => {
let resolveValue = (function(){
return DefinitionModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a Definition [DELETE /sites/{siteId}/definitions/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Definition ID
* @return {Promise<boolean>}
*/
static delete(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/sites/${siteId}/definitions/${id}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* List all Definitions [GET /sites/{siteId}/definitions]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {DefinitionController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<DefinitionModel[]>}
*/
static getAll(siteId, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/sites/${siteId}/definitions`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
return DefinitionModel.fromJSON(resultItem, siteId);
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a Definition [POST /sites/{siteId}/definitions]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {DefinitionController.CreateData} createData The Definition Create Data
* @return {Promise<DefinitionModel>}
*/
static create(siteId, createData)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/sites/${siteId}/definitions`, createData)
.then((result) => {
let resolveValue = (function(){
return DefinitionModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
}
export default DefinitionController;
/**
* The Optional Query Parameters for the getAll Function
*
* @typedef {Object} DefinitionController.GetAllQueryParameters
* @property {string} [keyIndex] The Definition Key Index
* @property {string} [type] The Definition Type
* @memberof Controllers.Site
*/
/**
* The Create Data for a Definition
*
* @typedef {Object} DefinitionController.CreateData
* @property {string} [keyIndex] The Definition Key Index
* @property {string} type The Definition Type
* @property {Object} [data] The Definition Data
* @memberof Controllers.Site
*/
/**
* The Update Data for a Definition
*
* @typedef {Object} DefinitionController.UpdateData
* @property {string} [type] The Definition Type
* @property {Object} [data] The Definition Data
* @memberof Controllers.Site
*/
source