RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/Site/PermanentObjectController.js

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

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

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

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

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

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

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

export default PermanentObjectController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} PermanentObjectController.GetAllQueryParameters
 * @property {?number} [rtuId] The RTU this Permanent Object belongs to
 * @property {string} [keyIndex] The Permanent Object Key Index
 * @property {string} [type] The Permanent Object Type
 * @memberof Controllers.Site
 */

/**
 * The Create Data for a Permanent Object
 * 
 * @typedef {Object} PermanentObjectController.CreateData
 * @property {?number} [rtuId] The RTU this Permanent Object belongs to
 * @property {string} [keyIndex] The Permanent Object Key Index
 * @property {string} type The Permanent Object Type
 * @property {Object} [definition] The Permanent Object Definition
 * @memberof Controllers.Site
 */

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