RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/RTUPluginController.js

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

import RequestHelper from '../RequestHelper';
import RTUPluginModel from '../Models/RTUPluginModel';

/**
 * Controller Class for RTU Plugins
 * 
 * @class
 */
class RTUPluginController
{
    /**
     * Retrieve a RTU Plugin [GET /rtu-plugins/{id}]
     * 
     * @static
     * @public
     * @param {number} id The RTU Plugin ID
     * @return {Promise<RTUPluginModel>}
     */
    static getOne(id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/rtu-plugins/${id}`)
            .then((result) => {
                let resolveValue = (function(){
                    return RTUPluginModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Update a RTU Plugin [PATCH /rtu-plugins/{id}]
     * 
     * @static
     * @public
     * @param {number} id The RTU Plugin ID
     * @param {RTUPluginController.UpdateData} updateData The RTU Plugin Update Data
     * @return {Promise<RTUPluginModel>}
     */
    static update(id, updateData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.patchRequest(`/rtu-plugins/${id}`, updateData)
            .then((result) => {
                let resolveValue = (function(){
                    return RTUPluginModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Delete a RTU Plugin [DELETE /rtu-plugins/{id}]
     * 
     * @static
     * @public
     * @param {number} id The RTU Plugin ID
     * @return {Promise<boolean>}
     */
    static delete(id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.deleteRequest(`/rtu-plugins/${id}`)
            .then((result) => {
                resolve(result ?? true);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * List all RTU Plugins [GET /rtu-plugins]
     * 
     * @static
     * @public
     * @param {RTUPluginController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
     * @return {Promise<RTUPluginModel[]>}
     */
    static getAll(queryParameters = {})
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/rtu-plugins`, queryParameters)
            .then((result) => {
                let resolveValue = (function(){
                    if(Array.isArray(result) !== true)
                    {
                        return [];
                    }
                
                    return result.map((resultItem) => {
                        return (function(){
                            return RTUPluginModel.fromJSON(resultItem);
                        }());
                    });
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

    /**
     * Create a RTU Plugin [POST /rtu-plugins]
     * 
     * @static
     * @public
     * @param {RTUPluginController.CreateData} createData The RTU Plugin Create Data
     * @return {Promise<RTUPluginModel>}
     */
    static create(createData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/rtu-plugins`, createData)
            .then((result) => {
                let resolveValue = (function(){
                    return RTUPluginModel.fromJSON(result);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }
}

export default RTUPluginController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} RTUPluginController.GetAllQueryParameters
 * @property {string} [name] The Plugin Name
 * @property {string} [companyId] The Company this RTU Plugin belongs to
 * @memberof Controllers
 */

/**
 * The Create Data for a RTU Plugin
 * 
 * @typedef {Object} RTUPluginController.CreateData
 * @property {string} name The Plugin Name
 * @property {string} companyId The Company this RTU Plugin belongs to
 * @memberof Controllers
 */

/**
 * The Update Data for a RTU Plugin
 * 
 * @typedef {Object} RTUPluginController.UpdateData
 * @property {string} [name] The Plugin Name
 * @property {string} [companyId] The Company this RTU Plugin belongs to
 * @memberof Controllers
 */