RICADO Gen 4 API JS Client

RICADO Gen 4 API JS Client

source

Models/CompanyModel.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 Company
 * 
 * @class
 * @hideconstructor
 * @extends BaseModel
 */
class CompanyModel extends BaseModel
{
    /**
     * CompanyModel Constructor
     * 
     * @protected
     */
    constructor()
    {
        super();
        
        /**
         * The Company ID
         * 
         * @type {string}
         * @public
         */
        this.id = "";
        
        /**
         * The Company Display Name
         * 
         * @type {string}
         * @public
         */
        this.displayName = "";
        
        /**
         * The Company Legal Name
         * 
         * @type {string}
         * @public
         */
        this.legalName = "";
        
        /**
         * Whether the Company has been deleted
         * 
         * @type {boolean}
         * @public
         */
        this.deleted = false;
        
        /**
         * When the Company was last updated
         * 
         * @type {Date}
         * @public
         */
        this.updateTimestamp = new Date();
    }

    /**
     * Create a new **CompanyModel** from a JSON Object or JSON String
     * 
     * @static
     * @public
     * @param {Object<string, any>|string} json A JSON Object or JSON String
     * @return {CompanyModel}
     */
    static fromJSON(json)
    {
        let model = new CompanyModel();
        
        /**
         * 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('displayName' in jsonObject)
        {
            model.displayName = (function(){
                if(typeof jsonObject['displayName'] !== 'string')
                {
                    return String(jsonObject['displayName']);
                }
        
                return jsonObject['displayName'];
            }());
        }
        
        if('legalName' in jsonObject)
        {
            model.legalName = (function(){
                if(typeof jsonObject['legalName'] !== 'string')
                {
                    return String(jsonObject['legalName']);
                }
        
                return jsonObject['legalName'];
            }());
        }
        
        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 CompanyModel;