/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import RequestHelper from '../../../RequestHelper';
import VarietyModel from '../../../Models/Packhouse/Site/VarietyModel';
/**
* Controller Class for Varieties
*
* @class
*/
class VarietyController
{
/**
* Retrieve a Variety [GET /packhouse/sites/{siteId}/varieties/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Variety ID
* @return {Promise<VarietyModel>}
*/
static getOne(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/varieties/${id}`)
.then((result) => {
let resolveValue = (function(){
return VarietyModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a Variety [PATCH /packhouse/sites/{siteId}/varieties/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Variety ID
* @param {VarietyController.UpdateData} updateData The Variety Update Data
* @return {Promise<VarietyModel>}
*/
static update(siteId, id, updateData)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/packhouse/sites/${siteId}/varieties/${id}`, updateData)
.then((result) => {
let resolveValue = (function(){
return VarietyModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a Variety [DELETE /packhouse/sites/{siteId}/varieties/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The Variety ID
* @return {Promise<boolean>}
*/
static delete(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/packhouse/sites/${siteId}/varieties/${id}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* List all Varieties [GET /packhouse/sites/{siteId}/varieties]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {VarietyController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<VarietyModel[]>}
*/
static getAll(siteId, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/varieties`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
return VarietyModel.fromJSON(resultItem, siteId);
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a Variety [POST /packhouse/sites/{siteId}/varieties]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {VarietyController.CreateData} createData The Variety Create Data
* @return {Promise<VarietyModel>}
*/
static create(siteId, createData)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/packhouse/sites/${siteId}/varieties`, createData)
.then((result) => {
let resolveValue = (function(){
return VarietyModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
}
export default VarietyController;
/**
* The Optional Query Parameters for the getAll Function
*
* @typedef {Object} VarietyController.GetAllQueryParameters
* @property {string} [code] The Variety Code
* @property {string} [name] The Variety Name
* @memberof Controllers.Packhouse.Site
*/
/**
* The Create Data for a Variety
*
* @typedef {Object} VarietyController.CreateData
* @property {string} [code] The Variety Code
* @property {string} name The Variety Name
* @property {string} description The Variety Description
* @property {string} image The Variety Image Source
* @property {Array<VarietyController.VarietyFruitSize>} fruitSizes An Array of Fruit Sizes Defined for this Variety
* @memberof Controllers.Packhouse.Site
*/
/**
* The Update Data for a Variety
*
* @typedef {Object} VarietyController.UpdateData
* @property {string} [name] The Variety Name
* @property {string} [description] The Variety Description
* @property {string} [image] The Variety Image Source
* @property {Array<VarietyController.VarietyFruitSize>} [fruitSizes] An Array of Fruit Sizes Defined for this Variety
* @memberof Controllers.Packhouse.Site
*/
/**
* A **VarietyFruitSize** Type
*
* @typedef {Object} VarietyController.VarietyFruitSize
* @property {string} size The Fruit Size
* @memberof Controllers.Packhouse.Site
*/
source