import { Configuration } from './../config/configuration'; export class Product { // Notice: OldApifromJson should be dropped soon // we got different json situations for products // 1) when in cartItem (where productId, title, price are present) // 2) when retrieved from the new productProvider where ( id, name, price thumb is passed) public static fromJson (obj: any) { // TODO check if fields exist to get the error return new Product( obj.id, obj.name, obj.brand ? obj.brand : 'HARD_CODED_BRAND', obj.description ? obj.description : 'HARD_CODED_DESCRIPTION', obj.price, obj.thumb ? obj.thumb : 'HARD_CODED_IMG_URL', obj.category ? obj.category : 'HARD_CODED_CATEGORY', obj.tenantId ? obj.tenantId : 'HARD_CODED_TENANT', obj.sku ? obj.sku : 'HARD_CODED_SKU', obj.__v ? obj.__v : '', obj.printer ? obj.printer : 'HARD_CODED_PRINTER' ); } public static inCartFromJson(obj: any) { return new Product( obj.productId, obj.title, obj.brand ? obj.brand : 'HARD_CODED_BRAND', obj.description ? obj.description : 'HARD_CODED_DESCRIPTION', obj.price, obj.img_url ? obj.img_url : 'HARD_CODED_IMG_URL', obj.category ? obj.category : 'HARD_CODED_CATEGORY', obj.tenantId ? obj.tenantId : 'HARD_CODED_TENANT', obj.sku ? obj.sku : undefined, obj.__v ? obj.__v : '', obj.printer ? obj.printer : undefined ); } // public static OldApifromJson (obj: any) { // // TODO check if fields exist to get the error // return new Product( // obj.id, // obj.name, // obj.brand, // 'HARD_CODED_DESCRIPTION', // obj.price, // obj.img_url, // 'HARD_CODED_CATEGORY', // 'HARD_CODED_TENANT_ID' // ); // } public toJson() { let productJson: any = { productId : this.getId(), title: this.getName(), finalPrice: this.getPrice(), img_url: this.getImgUrl(), __v: this.__v, printer: this.getPrinter(), sku: this.sku }; return productJson; } constructor( public id: string , public name: string , public brand: string , public description: string , public price: number , public img_url: string , public category: string // TODO should become enum at some point , public tenantId: string , public sku: string , public __v? : string , public printer? : object // TODO Make this into CLASS? ) {} getId() { return this.id; } getName() { return this.name; } getBrand() { return this.brand; } getDescription() { return this.description; } getPrice() { return this.price; } getImgUrl() { return this.img_url; } getCategory() { return this.category; } getTenantId() { return this.tenantId; } getPrinter() { return this.printer; } getSKU() { return this.sku; } // setPrinter(pr: any) { this.printer = pr } }