RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/Lab/Site/DehydratorController.js

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

import RequestHelper from '../../../RequestHelper';
import DehydratorModel from '../../../Models/Lab/Site/DehydratorModel';

/**
 * Controller Class for Dehydrators
 * 
 * @class
 */
class DehydratorController
{
    /**
     * Retrieve a Dehydrator [GET /lab/sites/{siteId}/dehydrators/{id}]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {string} id The Dehydrator ID
     * @return {Promise<DehydratorModel>}
     */
    static getOne(siteId, id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/lab/sites/${siteId}/dehydrators/${id}`)
            .then((result) => {
                let resolveValue = (function(){
                    return DehydratorModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

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

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

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

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

export default DehydratorController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} DehydratorController.GetAllQueryParameters
 * @property {?number} [rtuId] The RTU this Dehydrator belongs to
 * @property {string} [name] The Name of this Dehydrator
 * @property {string} [labId] The Lab that owns this Dehydrator
 * @memberof Controllers.Lab.Site
 */

/**
 * The Create Data for a Dehydrator
 * 
 * @typedef {Object} DehydratorController.CreateData
 * @property {?number} [rtuId] The RTU this Dehydrator belongs to
 * @property {string} name The Name of this Dehydrator
 * @property {{rackPositionId: number}} points The Points used by this Dehydrator
 * @property {string} labId The Lab that owns this Dehydrator
 * @memberof Controllers.Lab.Site
 */

/**
 * The Update Data for a Dehydrator
 * 
 * @typedef {Object} DehydratorController.UpdateData
 * @property {string} [name] The Name of this Dehydrator
 * @property {{rackPositionId: number}} [points] The Points used by this Dehydrator
 * @property {string} [labId] The Lab that owns this Dehydrator
 * @memberof Controllers.Lab.Site
 */