RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/Lab/Site/FruitProfileController.js

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

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

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

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

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

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

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

export default FruitProfileController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} FruitProfileController.GetAllQueryParameters
 * @property {string} [name] The Fruit Profile Name
 * @memberof Controllers.Lab.Site
 */

/**
 * The Create Data for a Fruit Profile
 * 
 * @typedef {Object} FruitProfileController.CreateData
 * @property {string} name The Fruit Profile Name
 * @property {string} description The Fruit Profile Description
 * @property {string} image The Fruit Profile Image Source
 * @property {number} nominalWarmUpDuration The Typical Warm Up Duration (in seconds) for a Sample to reach the Minimum Target Temperature
 * @property {number} minimumWithinTargetDuration The Minimum Duration (in seconds) that a Sample should be within the Min and Max Target Temperatures to be Compliant
 * @property {number} minimumTotalDuration The Minimum Duration (in seconds) that a Sample must be Dehydrated for to be Compliant
 * @property {number} maximumTotalDuration The Maximum Duration (in seconds) that a Sample can be Dehydrated for before it is Considered Non-Compliant
 * @property {number} minimumTargetTemperature The Minimum Target Temperature for a Sample to be Compliant
 * @property {number} maximumTargetTemperature The Maximum Target Temperature for a Sample to be Compliant
 * @memberof Controllers.Lab.Site
 */

/**
 * The Update Data for a Fruit Profile
 * 
 * @typedef {Object} FruitProfileController.UpdateData
 * @property {string} [name] The Fruit Profile Name
 * @property {string} [description] The Fruit Profile Description
 * @property {string} [image] The Fruit Profile Image Source
 * @property {number} [nominalWarmUpDuration] The Typical Warm Up Duration (in seconds) for a Sample to reach the Minimum Target Temperature
 * @property {number} [minimumWithinTargetDuration] The Minimum Duration (in seconds) that a Sample should be within the Min and Max Target Temperatures to be Compliant
 * @property {number} [minimumTotalDuration] The Minimum Duration (in seconds) that a Sample must be Dehydrated for to be Compliant
 * @property {number} [maximumTotalDuration] The Maximum Duration (in seconds) that a Sample can be Dehydrated for before it is Considered Non-Compliant
 * @property {number} [minimumTargetTemperature] The Minimum Target Temperature for a Sample to be Compliant
 * @property {number} [maximumTargetTemperature] The Maximum Target Temperature for a Sample to be Compliant
 * @memberof Controllers.Lab.Site
 */