RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Controllers/Packhouse/Site/PackTypeController.js

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

import RequestHelper from '../../../RequestHelper';
import PackTypeModel from '../../../Models/Packhouse/Site/PackTypeModel';

/**
 * Controller Class for Pack Types
 * 
 * @class
 */
class PackTypeController
{
    /**
     * Retrieve a Pack Type [GET /packhouse/sites/{siteId}/pack-types/{id}]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {string} id The Pack Type ID
     * @return {Promise<PackTypeModel>}
     */
    static getOne(siteId, id)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.getRequest(`/packhouse/sites/${siteId}/pack-types/${id}`)
            .then((result) => {
                let resolveValue = (function(){
                    return PackTypeModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }

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

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

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

    /**
     * Create a Pack Type [POST /packhouse/sites/{siteId}/pack-types]
     * 
     * @static
     * @public
     * @param {number} siteId The Site ID
     * @param {PackTypeController.CreateData} createData The Pack Type Create Data
     * @return {Promise<PackTypeModel>}
     */
    static create(siteId, createData)
    {
        return new Promise((resolve, reject) => {
            RequestHelper.postRequest(`/packhouse/sites/${siteId}/pack-types`, createData)
            .then((result) => {
                let resolveValue = (function(){
                    return PackTypeModel.fromJSON(result, siteId);
                }());
                
                resolve(resolveValue);
            })
            .catch(error => reject(error));
        });
    }
}

export default PackTypeController;

/**
 * The Optional Query Parameters for the getAll Function
 * 
 * @typedef {Object} PackTypeController.GetAllQueryParameters
 * @property {string} [code] The Code for this Pack Type
 * @property {string} [form] The Physical Form of this Pack Type
 * @memberof Controllers.Packhouse.Site
 */

/**
 * The Create Data for a Pack Type
 * 
 * @typedef {Object} PackTypeController.CreateData
 * @property {string} [code] The Code for this Pack Type
 * @property {string} name The Name for this Pack Type
 * @property {string} [description] An Optional Description for this Pack Type
 * @property {string} form The Physical Form of this Pack Type
 * @property {Array<PackTypeController.PackTypeFruitSize>} [fruitSizes] An Array of Fruit Sizes Defined for this Pack Type
 * @memberof Controllers.Packhouse.Site
 */

/**
 * The Update Data for a Pack Type
 * 
 * @typedef {Object} PackTypeController.UpdateData
 * @property {string} [name] The Name for this Pack Type
 * @property {string} [description] An Optional Description for this Pack Type
 * @property {string} [form] The Physical Form of this Pack Type
 * @property {Array<PackTypeController.PackTypeFruitSize>} [fruitSizes] An Array of Fruit Sizes Defined for this Pack Type
 * @memberof Controllers.Packhouse.Site
 */

/**
 * A **PackTypeFruitSize** Type
 * 
 * @typedef {Object} PackTypeController.PackTypeFruitSize
 * @property {string} size The Fruit Size
 * @property {number} count The Count of Fruit in one Pack
 * @memberof Controllers.Packhouse.Site
 */