RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/Site/TemporaryObjectController.js

/**
 * File Auto-Generated by the RICADO Gen 4 PHP API Project
 * 
 * Do Not Edit this File Manually!
 */

import RequestHelper from '../../RequestHelper';
import TemporaryObjectModel from '../../Models/Site/TemporaryObjectModel';

/**
 * Controller Class for Temporary Objects
 * 
 * @class
 */
class TemporaryObjectController
{
    /**
     * Retrieve a Temporary Object [GET /sites/{siteId}/temporary-objects/{id}]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {string} id The Temporary Object ID
     * @return {Promise<TemporaryObjectModel>}
     */
    static getOne(siteId, id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/sites/${siteId}/temporary-objects/${id}`)
            .then((result) => {
                let resolveValue = (function(){
                    return TemporaryObjectModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Update a Temporary Object [PATCH /sites/{siteId}/temporary-objects/{id}]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {string} id The Temporary Object ID
     * @param {TemporaryObjectController.UpdateData} updateData The Temporary Object Update Data
     * @return {Promise<TemporaryObjectModel>}
     */
    static update(siteId, id, updateData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.patchRequest(`/sites/${siteId}/temporary-objects/${id}`, updateData)
            .then((result) => {
                let resolveValue = (function(){
                    return TemporaryObjectModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Delete a Temporary Object [DELETE /sites/{siteId}/temporary-objects/{id}]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {string} id The Temporary Object ID
     * @return {Promise<boolean>}
     */
    static delete(siteId, id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.deleteRequest(`/sites/${siteId}/temporary-objects/${id}`)
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * List all Temporary Objects [GET /sites/{siteId}/temporary-objects]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {TemporaryObjectController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
     * @return {Promise<TemporaryObjectModel[]>}
     */
    static getAll(siteId, queryParameters = {})
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/sites/${siteId}/temporary-objects`, queryParameters)
            .then((result) => {
                let resolveValue = (function(){
                    if(Array.isArray(result) !== true)
                    {
                        return [];
                    }
                
                    return result.map((resultItem) => {
                        return (function(){
                            return TemporaryObjectModel.fromJSON(resultItem, siteId);
                        }());
                    });
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Create a Temporary Object [POST /sites/{siteId}/temporary-objects]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {TemporaryObjectController.CreateData} createData The Temporary Object Create Data
     * @return {Promise<TemporaryObjectModel>}
     */
    static create(siteId, createData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/sites/${siteId}/temporary-objects`, createData)
            .then((result) => {
                let resolveValue = (function(){
                    return TemporaryObjectModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }
}

export default TemporaryObjectController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} TemporaryObjectController.GetAllQueryParameters
 * @property {string} [keyIndex] The Temporary Object Key Index
 * @property {string} [type] The Temporary Object Type
 * @memberof Controllers.Site
 */

/**
 * The Create Data for a Temporary Object
 * 
 * @typedef {Object} TemporaryObjectController.CreateData
 * @property {string} [keyIndex] The Temporary Object Key Index
 * @property {string} type The Temporary Object Type
 * @property {Object} [definition] The Temporary Object Definition
 * @memberof Controllers.Site
 */

/**
 * The Update Data for a Temporary Object
 * 
 * @typedef {Object} TemporaryObjectController.UpdateData
 * @property {string} [type] The Temporary Object Type
 * @property {Object} [definition] The Temporary Object Definition
 * @memberof Controllers.Site
 */