/**
* File Auto-Generated by the RICADO Gen 4 PHP API Project
*
* Do Not Edit this File Manually!
*/
import RequestHelper from '../../../RequestHelper';
import FreshPackPackrunSummaryModel from '../../../Models/Packhouse/Site/FreshPackPackrunSummaryModel';
/**
* Controller Class for FreshPack Packrun Summaries
*
* @class
*/
class FreshPackPackrunSummaryController
{
/**
* Retrieve a FreshPack Packrun Summary [GET /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @return {Promise<FreshPackPackrunSummaryModel>}
*/
static getOne(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}`)
.then((result) => {
let resolveValue = (function(){
return FreshPackPackrunSummaryModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a FreshPack Packrun Summary [PATCH /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @param {FreshPackPackrunSummaryController.UpdateData} updateData The FreshPack Packrun Summary Update Data
* @return {Promise<FreshPackPackrunSummaryModel>}
*/
static update(siteId, id, updateData)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}`, updateData)
.then((result) => {
let resolveValue = (function(){
return FreshPackPackrunSummaryModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a FreshPack Packrun Summary [DELETE /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @return {Promise<boolean>}
*/
static delete(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* Retrieve Comments [GET /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}/comments]
*
* Retrieves Comments for a FreshPack Packrun Summary
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @return {Promise<Array<FreshPackPackrunSummaryController.CommentItem>>}
*/
static getComments(siteId, id)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}/comments`)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
let resultItemObject = {};
if(typeof resultItem === 'object' && 'id' in resultItem)
{
resultItemObject.id = (function(){
if(typeof resultItem.id !== 'string')
{
return String(resultItem.id);
}
return resultItem.id;
}());
}
else
{
resultItemObject.id = "";
}
if(typeof resultItem === 'object' && 'userAccount' in resultItem)
{
resultItemObject.userAccount = (function(){
let userAccountObject = {};
if(typeof resultItem.userAccount === 'object' && 'id' in resultItem.userAccount)
{
userAccountObject.id = (function(){
if(resultItem.userAccount.id === null)
{
return null;
}
if(typeof resultItem.userAccount.id !== 'string')
{
return String(resultItem.userAccount.id);
}
return resultItem.userAccount.id;
}());
}
else
{
userAccountObject.id = null;
}
if(typeof resultItem.userAccount === 'object' && 'firstName' in resultItem.userAccount)
{
userAccountObject.firstName = (function(){
if(resultItem.userAccount.firstName === null)
{
return null;
}
if(typeof resultItem.userAccount.firstName !== 'string')
{
return String(resultItem.userAccount.firstName);
}
return resultItem.userAccount.firstName;
}());
}
else
{
userAccountObject.firstName = null;
}
if(typeof resultItem.userAccount === 'object' && 'lastName' in resultItem.userAccount)
{
userAccountObject.lastName = (function(){
if(resultItem.userAccount.lastName === null)
{
return null;
}
if(typeof resultItem.userAccount.lastName !== 'string')
{
return String(resultItem.userAccount.lastName);
}
return resultItem.userAccount.lastName;
}());
}
else
{
userAccountObject.lastName = null;
}
return userAccountObject;
}());
}
else
{
resultItemObject.userAccount = (function(){
let userAccountDefaultValue = {};
userAccountDefaultValue.id = null;
userAccountDefaultValue.firstName = null;
userAccountDefaultValue.lastName = null;
return userAccountDefaultValue;
}());
}
if(typeof resultItem === 'object' && 'content' in resultItem)
{
resultItemObject.content = (function(){
if(resultItem.content === null)
{
return null;
}
if(typeof resultItem.content !== 'string')
{
return String(resultItem.content);
}
return resultItem.content;
}());
}
else
{
resultItemObject.content = null;
}
if(typeof resultItem === 'object' && 'createdTimestamp' in resultItem)
{
resultItemObject.createdTimestamp = (function(){
if(resultItem.createdTimestamp === null)
{
return null;
}
if(typeof resultItem.createdTimestamp !== 'string')
{
return new Date(String(resultItem.createdTimestamp));
}
return new Date(resultItem.createdTimestamp);
}());
}
else
{
resultItemObject.createdTimestamp = null;
}
if(typeof resultItem === 'object' && 'updatedTimestamp' in resultItem)
{
resultItemObject.updatedTimestamp = (function(){
if(resultItem.updatedTimestamp === null)
{
return null;
}
if(typeof resultItem.updatedTimestamp !== 'string')
{
return new Date(String(resultItem.updatedTimestamp));
}
return new Date(resultItem.updatedTimestamp);
}());
}
else
{
resultItemObject.updatedTimestamp = null;
}
return resultItemObject;
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a Comment [POST /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}/comments]
*
* Create a Comment for a FreshPack Packrun Summary
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @param {string} content The Content of the New Comment
* @return {Promise<FreshPackPackrunSummaryController.CommentItem>}
*/
static createComment(siteId, id, content)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}/comments`, {content})
.then((result) => {
let resolveValue = (function(){
let resultObject = {};
if(typeof result === 'object' && 'id' in result)
{
resultObject.id = (function(){
if(typeof result.id !== 'string')
{
return String(result.id);
}
return result.id;
}());
}
else
{
resultObject.id = "";
}
if(typeof result === 'object' && 'userAccount' in result)
{
resultObject.userAccount = (function(){
let userAccountObject = {};
if(typeof result.userAccount === 'object' && 'id' in result.userAccount)
{
userAccountObject.id = (function(){
if(result.userAccount.id === null)
{
return null;
}
if(typeof result.userAccount.id !== 'string')
{
return String(result.userAccount.id);
}
return result.userAccount.id;
}());
}
else
{
userAccountObject.id = null;
}
if(typeof result.userAccount === 'object' && 'firstName' in result.userAccount)
{
userAccountObject.firstName = (function(){
if(result.userAccount.firstName === null)
{
return null;
}
if(typeof result.userAccount.firstName !== 'string')
{
return String(result.userAccount.firstName);
}
return result.userAccount.firstName;
}());
}
else
{
userAccountObject.firstName = null;
}
if(typeof result.userAccount === 'object' && 'lastName' in result.userAccount)
{
userAccountObject.lastName = (function(){
if(result.userAccount.lastName === null)
{
return null;
}
if(typeof result.userAccount.lastName !== 'string')
{
return String(result.userAccount.lastName);
}
return result.userAccount.lastName;
}());
}
else
{
userAccountObject.lastName = null;
}
return userAccountObject;
}());
}
else
{
resultObject.userAccount = (function(){
let userAccountDefaultValue = {};
userAccountDefaultValue.id = null;
userAccountDefaultValue.firstName = null;
userAccountDefaultValue.lastName = null;
return userAccountDefaultValue;
}());
}
if(typeof result === 'object' && 'content' in result)
{
resultObject.content = (function(){
if(result.content === null)
{
return null;
}
if(typeof result.content !== 'string')
{
return String(result.content);
}
return result.content;
}());
}
else
{
resultObject.content = null;
}
if(typeof result === 'object' && 'createdTimestamp' in result)
{
resultObject.createdTimestamp = (function(){
if(result.createdTimestamp === null)
{
return null;
}
if(typeof result.createdTimestamp !== 'string')
{
return new Date(String(result.createdTimestamp));
}
return new Date(result.createdTimestamp);
}());
}
else
{
resultObject.createdTimestamp = null;
}
if(typeof result === 'object' && 'updatedTimestamp' in result)
{
resultObject.updatedTimestamp = (function(){
if(result.updatedTimestamp === null)
{
return null;
}
if(typeof result.updatedTimestamp !== 'string')
{
return new Date(String(result.updatedTimestamp));
}
return new Date(result.updatedTimestamp);
}());
}
else
{
resultObject.updatedTimestamp = null;
}
return resultObject;
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Retrieve a Comment [GET /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}/comments/{commentId}]
*
* Retrieves Comments for a FreshPack Packrun Summary
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @param {string} commentId The Comment ID
* @return {Promise<FreshPackPackrunSummaryController.CommentItem>}
*/
static getOneComment(siteId, id, commentId)
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}/comments/${commentId}`)
.then((result) => {
let resolveValue = (function(){
let resultObject = {};
if(typeof result === 'object' && 'id' in result)
{
resultObject.id = (function(){
if(typeof result.id !== 'string')
{
return String(result.id);
}
return result.id;
}());
}
else
{
resultObject.id = "";
}
if(typeof result === 'object' && 'userAccount' in result)
{
resultObject.userAccount = (function(){
let userAccountObject = {};
if(typeof result.userAccount === 'object' && 'id' in result.userAccount)
{
userAccountObject.id = (function(){
if(result.userAccount.id === null)
{
return null;
}
if(typeof result.userAccount.id !== 'string')
{
return String(result.userAccount.id);
}
return result.userAccount.id;
}());
}
else
{
userAccountObject.id = null;
}
if(typeof result.userAccount === 'object' && 'firstName' in result.userAccount)
{
userAccountObject.firstName = (function(){
if(result.userAccount.firstName === null)
{
return null;
}
if(typeof result.userAccount.firstName !== 'string')
{
return String(result.userAccount.firstName);
}
return result.userAccount.firstName;
}());
}
else
{
userAccountObject.firstName = null;
}
if(typeof result.userAccount === 'object' && 'lastName' in result.userAccount)
{
userAccountObject.lastName = (function(){
if(result.userAccount.lastName === null)
{
return null;
}
if(typeof result.userAccount.lastName !== 'string')
{
return String(result.userAccount.lastName);
}
return result.userAccount.lastName;
}());
}
else
{
userAccountObject.lastName = null;
}
return userAccountObject;
}());
}
else
{
resultObject.userAccount = (function(){
let userAccountDefaultValue = {};
userAccountDefaultValue.id = null;
userAccountDefaultValue.firstName = null;
userAccountDefaultValue.lastName = null;
return userAccountDefaultValue;
}());
}
if(typeof result === 'object' && 'content' in result)
{
resultObject.content = (function(){
if(result.content === null)
{
return null;
}
if(typeof result.content !== 'string')
{
return String(result.content);
}
return result.content;
}());
}
else
{
resultObject.content = null;
}
if(typeof result === 'object' && 'createdTimestamp' in result)
{
resultObject.createdTimestamp = (function(){
if(result.createdTimestamp === null)
{
return null;
}
if(typeof result.createdTimestamp !== 'string')
{
return new Date(String(result.createdTimestamp));
}
return new Date(result.createdTimestamp);
}());
}
else
{
resultObject.createdTimestamp = null;
}
if(typeof result === 'object' && 'updatedTimestamp' in result)
{
resultObject.updatedTimestamp = (function(){
if(result.updatedTimestamp === null)
{
return null;
}
if(typeof result.updatedTimestamp !== 'string')
{
return new Date(String(result.updatedTimestamp));
}
return new Date(result.updatedTimestamp);
}());
}
else
{
resultObject.updatedTimestamp = null;
}
return resultObject;
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Update a Comment [PATCH /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}/comments/{commentId}]
*
* Update a Comment for a FreshPack Packrun Summary
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @param {string} commentId The Comment ID
* @param {string} content The Updated Content for the Comment
* @return {Promise<FreshPackPackrunSummaryController.CommentItem>}
*/
static updateOneComment(siteId, id, commentId, content)
{
return new Promise((resolve, reject) => {
RequestHelper.patchRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}/comments/${commentId}`, {content})
.then((result) => {
let resolveValue = (function(){
let resultObject = {};
if(typeof result === 'object' && 'id' in result)
{
resultObject.id = (function(){
if(typeof result.id !== 'string')
{
return String(result.id);
}
return result.id;
}());
}
else
{
resultObject.id = "";
}
if(typeof result === 'object' && 'userAccount' in result)
{
resultObject.userAccount = (function(){
let userAccountObject = {};
if(typeof result.userAccount === 'object' && 'id' in result.userAccount)
{
userAccountObject.id = (function(){
if(result.userAccount.id === null)
{
return null;
}
if(typeof result.userAccount.id !== 'string')
{
return String(result.userAccount.id);
}
return result.userAccount.id;
}());
}
else
{
userAccountObject.id = null;
}
if(typeof result.userAccount === 'object' && 'firstName' in result.userAccount)
{
userAccountObject.firstName = (function(){
if(result.userAccount.firstName === null)
{
return null;
}
if(typeof result.userAccount.firstName !== 'string')
{
return String(result.userAccount.firstName);
}
return result.userAccount.firstName;
}());
}
else
{
userAccountObject.firstName = null;
}
if(typeof result.userAccount === 'object' && 'lastName' in result.userAccount)
{
userAccountObject.lastName = (function(){
if(result.userAccount.lastName === null)
{
return null;
}
if(typeof result.userAccount.lastName !== 'string')
{
return String(result.userAccount.lastName);
}
return result.userAccount.lastName;
}());
}
else
{
userAccountObject.lastName = null;
}
return userAccountObject;
}());
}
else
{
resultObject.userAccount = (function(){
let userAccountDefaultValue = {};
userAccountDefaultValue.id = null;
userAccountDefaultValue.firstName = null;
userAccountDefaultValue.lastName = null;
return userAccountDefaultValue;
}());
}
if(typeof result === 'object' && 'content' in result)
{
resultObject.content = (function(){
if(result.content === null)
{
return null;
}
if(typeof result.content !== 'string')
{
return String(result.content);
}
return result.content;
}());
}
else
{
resultObject.content = null;
}
if(typeof result === 'object' && 'createdTimestamp' in result)
{
resultObject.createdTimestamp = (function(){
if(result.createdTimestamp === null)
{
return null;
}
if(typeof result.createdTimestamp !== 'string')
{
return new Date(String(result.createdTimestamp));
}
return new Date(result.createdTimestamp);
}());
}
else
{
resultObject.createdTimestamp = null;
}
if(typeof result === 'object' && 'updatedTimestamp' in result)
{
resultObject.updatedTimestamp = (function(){
if(result.updatedTimestamp === null)
{
return null;
}
if(typeof result.updatedTimestamp !== 'string')
{
return new Date(String(result.updatedTimestamp));
}
return new Date(result.updatedTimestamp);
}());
}
else
{
resultObject.updatedTimestamp = null;
}
return resultObject;
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Delete a Comment [DELETE /packhouse/sites/{siteId}/freshpack-packrun-summaries/{id}/comments/{commentId}]
*
* Delete a Comment for a FreshPack Packrun Summary
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {string} id The FreshPack Packrun Summary ID
* @param {string} commentId The Comment ID
* @return {Promise<boolean>}
*/
static deleteOneComment(siteId, id, commentId)
{
return new Promise((resolve, reject) => {
RequestHelper.deleteRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries/${id}/comments/${commentId}`)
.then((result) => {
resolve(result ?? true);
})
.catch(error => reject(error));
});
}
/**
* List all FreshPack Packrun Summaries [GET /packhouse/sites/{siteId}/freshpack-packrun-summaries]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {FreshPackPackrunSummaryController.GetAllQueryParameters} [queryParameters] The Optional Query Parameters
* @return {Promise<FreshPackPackrunSummaryModel[]>}
*/
static getAll(siteId, queryParameters = {})
{
return new Promise((resolve, reject) => {
RequestHelper.getRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries`, queryParameters)
.then((result) => {
let resolveValue = (function(){
if(Array.isArray(result) !== true)
{
return [];
}
return result.map((resultItem) => {
return (function(){
return FreshPackPackrunSummaryModel.fromJSON(resultItem, siteId);
}());
});
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
/**
* Create a FreshPack Packrun Summary [POST /packhouse/sites/{siteId}/freshpack-packrun-summaries]
*
* @static
* @public
* @param {number} siteId The Site ID
* @param {FreshPackPackrunSummaryController.CreateData} createData The FreshPack Packrun Summary Create Data
* @return {Promise<FreshPackPackrunSummaryModel>}
*/
static create(siteId, createData)
{
return new Promise((resolve, reject) => {
RequestHelper.postRequest(`/packhouse/sites/${siteId}/freshpack-packrun-summaries`, createData)
.then((result) => {
let resolveValue = (function(){
return FreshPackPackrunSummaryModel.fromJSON(result, siteId);
}());
resolve(resolveValue);
})
.catch(error => reject(error));
});
}
}
export default FreshPackPackrunSummaryController;
/**
* The Optional Query Parameters for the getAll Function
*
* @typedef {Object} FreshPackPackrunSummaryController.GetAllQueryParameters
* @property {string} [packingLineId] The Packing Line ID this Summary is associated with
* @property {string} [packrunId] The Packrun ID this Summary is associated with
* @property {?string} [timeBatchId] The Time Batch this Summary is associated with
* @property {Date} [createdTimestampBegin] Filter by the Timestamp when this FreshPack Packrun Summary was Created. Results Greater than or Equal to Timestamp
* @property {Date} [createdTimestampEnd] Filter by the Timestamp when this FreshPack Packrun Summary was Created. Results Less than or Equal to Timestamp
* @memberof Controllers.Packhouse.Site
*/
/**
* The Create Data for a FreshPack Packrun Summary
*
* @typedef {Object} FreshPackPackrunSummaryController.CreateData
* @property {string} packingLineId The Packing Line ID this Summary is associated with
* @property {string} [packrunId] The Packrun ID this Summary is associated with
* @property {Date} [createdTimestamp] When this Summary was Created
* @property {?string} [timeBatchId] The Time Batch this Summary is associated with
* @property {Array<FreshPackPackrunSummaryController.TraySummary>} [traySummaries] An Array of Tray Summary Data Objects for all Sizes and Class Types
* @property {Array<FreshPackPackrunSummaryController.ClearanceSummary>} [clearanceSummaries] An Array of Clearance Summary Data Objects for all Sizes
* @memberof Controllers.Packhouse.Site
*/
/**
* The Update Data for a FreshPack Packrun Summary
*
* @typedef {Object} FreshPackPackrunSummaryController.UpdateData
* @property {string} [packingLineId] The Packing Line ID this Summary is associated with
* @property {Date} [createdTimestamp] When this Summary was Created
* @property {?string} [timeBatchId] The Time Batch this Summary is associated with
* @property {Array<FreshPackPackrunSummaryController.TraySummary>} [traySummaries] An Array of Tray Summary Data Objects for all Sizes and Class Types
* @property {Array<FreshPackPackrunSummaryController.ClearanceSummary>} [clearanceSummaries] An Array of Clearance Summary Data Objects for all Sizes
* @memberof Controllers.Packhouse.Site
*/
/**
* A **UserAccount** Type
*
* @typedef {Object} FreshPackPackrunSummaryController.UserAccount
* @property {?string} id The User Account ID
* @property {?string} firstName The User's First Name
* @property {?string} lastName The User's Last Name
* @memberof Controllers.Packhouse.Site
*/
/**
* A **CommentItem** Type
*
* @typedef {Object} FreshPackPackrunSummaryController.CommentItem
* @property {string} id The Comment ID
* @property {FreshPackPackrunSummaryController.UserAccount} userAccount
* @property {?string} content The Content of the Comment
* @property {?Date} createdTimestamp When the Comment was Created
* @property {?Date} updatedTimestamp When the Comment was last Updated
* @memberof Controllers.Packhouse.Site
*/
/**
* A **TraySummary** Type
*
* @typedef {Object} FreshPackPackrunSummaryController.TraySummary
* @property {string} classType The Class Type of this Tray Summary
* @property {?string} fruitSize The Fruit Size of this Tray Summary
* @property {number} trayCount Total Number of Tray Equivalents
* @property {number} averageTrayWeight Average Tray Weight in Kilograms
* @property {number} weight The Total Fruit Weight in Kilograms for this Tray Summary
* @memberof Controllers.Packhouse.Site
*/
/**
* A **ClearanceSummary** Type
*
* @typedef {Object} FreshPackPackrunSummaryController.ClearanceSummary
* @property {?string} fruitSize The Fruit Size of this Clearance Summary
* @property {?string} tasteBand Taste Band (e.g. Y, T, M, R, L)
* @property {?string} maturityProtocol The Maturity Protocol (since Harvesting) of this Fruit Size (e.g. A, B, C, N)
* @property {?string} harvestProtocol The Protocol (at Harvest) of this Fruit Size
* @property {?Date} clearanceDate When this Fruit Size met the Clearance Criteria. Will be `null` if this Fruit Size has not Cleared
* @property {?Date} kiwiStartDate The Kiwi-Start Date for this Fruit Size
* @property {?number} trayEstimate The Estimated Number of Tray Equivalents for this Fruit Size
* @property {?Date} protocolADate Estimated or Actual Date when this Fruit Size will reach Protocol A Maturity
* @property {?Date} protocolBDate Estimated or Actual Date when this Fruit Size will reach Protocol B Maturity
* @property {?Date} protocolCDate Estimated or Actual Date when this Fruit Size will reach Protocol C Maturity
* @property {?Date} protocolNDate Estimated or Actual Date when this Fruit Size will reach Protocol N Maturity
* @property {?boolean} useNIRPacking Whether NIR Packing should be utilized for this Fruit Size
* @memberof Controllers.Packhouse.Site
*/
source