RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/SiteController.js

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

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

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

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

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

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

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

export default SiteController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} SiteController.GetAllQueryParameters
 * @property {string} [name] The Site Name
 * @property {string} [companyId] The Company this Site belongs to
 * @property {boolean} [enabled] Whether the Site is Enabled
 * @memberof Controllers
 */

/**
 * The Create Data for a Site
 * 
 * @typedef {Object} SiteController.CreateData
 * @property {string} name The Site Name
 * @property {string} companyId The Company this Site belongs to
 * @property {boolean} [enabled] Whether the Site is Enabled
 * @memberof Controllers
 */

/**
 * The Update Data for a Site
 * 
 * @typedef {Object} SiteController.UpdateData
 * @property {string} [name] The Site Name
 * @property {string} [companyId] The Company this Site belongs to
 * @property {boolean} [enabled] Whether the Site is Enabled
 * @memberof Controllers
 */