RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/Lab/Site/SampleModel.js

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

import BaseModel from '../../../Models/BaseModel';

/**
 * Model Class for a Sample
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class SampleModel extends BaseModel
{
    /**
     * SampleModel Constructor
     * 
     * @protected
     * @param {number} siteId The Site ID associated with this Sample
     */
    constructor(siteId)
    {
        super();
        
        /**
         * The Sample ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Lab ID this Sample is associated with
         * 
         * @type {string}
         * @public
         */
        this.labId = "";
        
        /**
         * The Numeric Sample Number
         * 
         * @type {string}
         * @public
         */
        this.sampleNumber = "";
        
        /**
         * When this Sample was Created
         * 
         * @type {Date}
         * @public
         */
        this.createdTimestamp = new Date();
        
        /**
         * The Source that Created this Sample
         * 
         * @type {string}
         * @public
         */
        this.createdSource = "";
        
        /**
         * Name of the User who Created this Sample
         * 
         * @type {?string}
         * @public
         */
        this.createdUserName = null;
        
        /**
         * Optional Scheduled Timestamp when this Sample should Begin
         * 
         * @type {?Date}
         * @public
         */
        this.scheduledTimestamp = null;
        
        /**
         * When this Sample was Loaded into the Dehydrator
         * 
         * @type {?Date}
         * @public
         */
        this.loadedTimestamp = null;
        
        /**
         * When this Sample was Started
         * 
         * @type {?Date}
         * @public
         */
        this.startTimestamp = null;
        
        /**
         * When this Sample was Finished
         * 
         * @type {?Date}
         * @public
         */
        this.finishTimestamp = null;
        
        /**
         * When this Sample was Unloaded from the Dehydrator
         * 
         * @type {?Date}
         * @public
         */
        this.unloadedTimestamp = null;
        
        /**
         * When this Sample was Published
         * 
         * @type {?Date}
         * @public
         */
        this.publishTimestamp = null;
        
        /**
         * The Source that Published this Sample
         * 
         * @type {?string}
         * @public
         */
        this.publishSource = null;
        
        /**
         * Name of the User who Published this Sample
         * 
         * @type {?string}
         * @public
         */
        this.publishUserName = null;
        
        /**
         * The Fruit Profile for this Sample
         * 
         * @type {string}
         * @public
         */
        this.fruitProfileId = "";
        
        /**
         * The Rack Position used for this Sample
         * 
         * @type {string}
         * @public
         */
        this.rackPositionId = "";
        
        /**
         * The Dehydrator used for this Sample
         * 
         * @type {string}
         * @public
         */
        this.dehydratorId = "";
        
        /**
         * The Sample Result ID asociated with this Sample
         * 
         * @type {?string}
         * @public
         */
        this.resultId = null;
        
        /**
         * The Status of this Sample
         * 
         * @type {string}
         * @public
         */
        this.status = "";
        
        /**
         * Whether the Sample has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Sample was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
        
        /**
         * The Site ID associated with this Sample
         * 
         * @type {number}
         * @public
         */
        this.siteId = siteId;
    }

    /**
     * Create a new **SampleModel** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @param {number} siteId The Site ID associated with this Sample
     * @return {SampleModel}
     */
    static fromJSON(json, siteId)
    {
        let model = new SampleModel(siteId);
        
        /**
         * The JSON Object
         * 
         * @type {Object<string, any>}
         */
        let jsonObject = {};
        
        if(typeof json === 'string')
        {
            jsonObject = JSON.parse(json);
        }
        else if(typeof json === 'object')
        {
            jsonObject = json;
        }
        
        if('id' in jsonObject)
        {
            model.id = (function(){
                if(typeof jsonObject['id'] !== 'string')
                {
                    return String(jsonObject['id']);
                }
        
                return jsonObject['id'];
            }());
        }
        
        if('labId' in jsonObject)
        {
            model.labId = (function(){
                if(typeof jsonObject['labId'] !== 'string')
                {
                    return String(jsonObject['labId']);
                }
        
                return jsonObject['labId'];
            }());
        }
        
        if('sampleNumber' in jsonObject)
        {
            model.sampleNumber = (function(){
                if(typeof jsonObject['sampleNumber'] !== 'string')
                {
                    return String(jsonObject['sampleNumber']);
                }
        
                return jsonObject['sampleNumber'];
            }());
        }
        
        if('createdTimestamp' in jsonObject)
        {
            model.createdTimestamp = (function(){
                if(typeof jsonObject['createdTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['createdTimestamp']));
                }
        
                return new Date(jsonObject['createdTimestamp']);
            }());
        }
        
        if('createdSource' in jsonObject)
        {
            model.createdSource = (function(){
                if(typeof jsonObject['createdSource'] !== 'string')
                {
                    return String(jsonObject['createdSource']);
                }
        
                return jsonObject['createdSource'];
            }());
        }
        
        if('createdUserName' in jsonObject)
        {
            model.createdUserName = (function(){
                if(jsonObject['createdUserName'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['createdUserName'] !== 'string')
                {
                    return String(jsonObject['createdUserName']);
                }
        
                return jsonObject['createdUserName'];
            }());
        }
        
        if('scheduledTimestamp' in jsonObject)
        {
            model.scheduledTimestamp = (function(){
                if(jsonObject['scheduledTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['scheduledTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['scheduledTimestamp']));
                }
        
                return new Date(jsonObject['scheduledTimestamp']);
            }());
        }
        
        if('loadedTimestamp' in jsonObject)
        {
            model.loadedTimestamp = (function(){
                if(jsonObject['loadedTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['loadedTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['loadedTimestamp']));
                }
        
                return new Date(jsonObject['loadedTimestamp']);
            }());
        }
        
        if('startTimestamp' in jsonObject)
        {
            model.startTimestamp = (function(){
                if(jsonObject['startTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['startTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['startTimestamp']));
                }
        
                return new Date(jsonObject['startTimestamp']);
            }());
        }
        
        if('finishTimestamp' in jsonObject)
        {
            model.finishTimestamp = (function(){
                if(jsonObject['finishTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['finishTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['finishTimestamp']));
                }
        
                return new Date(jsonObject['finishTimestamp']);
            }());
        }
        
        if('unloadedTimestamp' in jsonObject)
        {
            model.unloadedTimestamp = (function(){
                if(jsonObject['unloadedTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['unloadedTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['unloadedTimestamp']));
                }
        
                return new Date(jsonObject['unloadedTimestamp']);
            }());
        }
        
        if('publishTimestamp' in jsonObject)
        {
            model.publishTimestamp = (function(){
                if(jsonObject['publishTimestamp'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['publishTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['publishTimestamp']));
                }
        
                return new Date(jsonObject['publishTimestamp']);
            }());
        }
        
        if('publishSource' in jsonObject)
        {
            model.publishSource = (function(){
                if(jsonObject['publishSource'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['publishSource'] !== 'string')
                {
                    return String(jsonObject['publishSource']);
                }
        
                return jsonObject['publishSource'];
            }());
        }
        
        if('publishUserName' in jsonObject)
        {
            model.publishUserName = (function(){
                if(jsonObject['publishUserName'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['publishUserName'] !== 'string')
                {
                    return String(jsonObject['publishUserName']);
                }
        
                return jsonObject['publishUserName'];
            }());
        }
        
        if('fruitProfileId' in jsonObject)
        {
            model.fruitProfileId = (function(){
                if(typeof jsonObject['fruitProfileId'] !== 'string')
                {
                    return String(jsonObject['fruitProfileId']);
                }
        
                return jsonObject['fruitProfileId'];
            }());
        }
        
        if('rackPositionId' in jsonObject)
        {
            model.rackPositionId = (function(){
                if(typeof jsonObject['rackPositionId'] !== 'string')
                {
                    return String(jsonObject['rackPositionId']);
                }
        
                return jsonObject['rackPositionId'];
            }());
        }
        
        if('dehydratorId' in jsonObject)
        {
            model.dehydratorId = (function(){
                if(typeof jsonObject['dehydratorId'] !== 'string')
                {
                    return String(jsonObject['dehydratorId']);
                }
        
                return jsonObject['dehydratorId'];
            }());
        }
        
        if('resultId' in jsonObject)
        {
            model.resultId = (function(){
                if(jsonObject['resultId'] === null)
                {
                    return null;
                }
        
                if(typeof jsonObject['resultId'] !== 'string')
                {
                    return String(jsonObject['resultId']);
                }
        
                return jsonObject['resultId'];
            }());
        }
        
        if('status' in jsonObject)
        {
            model.status = (function(){
                if(typeof jsonObject['status'] !== 'string')
                {
                    return String(jsonObject['status']);
                }
        
                return jsonObject['status'];
            }());
        }
        
        if('deleted' in jsonObject)
        {
            model.deleted = (function(){
                if(typeof jsonObject['deleted'] !== 'boolean')
                {
                    return Boolean(jsonObject['deleted']);
                }
        
                return jsonObject['deleted'];
            }());
        }
        
        if('updateTimestamp' in jsonObject)
        {
            model.updateTimestamp = (function(){
                if(typeof jsonObject['updateTimestamp'] !== 'string')
                {
                    return new Date(String(jsonObject['updateTimestamp']));
                }
        
                return new Date(jsonObject['updateTimestamp']);
            }());
        }
        
        return model;
    }
}

export default SampleModel;