From 7381a7033231e6454a37fd64b1f3de4e8d59355f Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Wed, 11 Nov 2020 20:07:12 -0500 Subject: Kind of flailing with the UI; lots of API bugfixes though. --- iridescence/src/models/product_diff.js | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 iridescence/src/models/product_diff.js (limited to 'iridescence/src/models/product_diff.js') diff --git a/iridescence/src/models/product_diff.js b/iridescence/src/models/product_diff.js new file mode 100644 index 0000000..a683102 --- /dev/null +++ b/iridescence/src/models/product_diff.js @@ -0,0 +1,43 @@ +export default class ProductDiff { + constructor(product) { + if (product) { + this.id = product.id ? product.id : 0; + this.name = product.name ? product.name : null; + this.description = product.description ? product.description : null; + this.cents = product.cents ? product.cents : null; + this.quantity = product.quantity ? product.quantity : null; + this.featured = + typeof product.featured === "boolean" ? product.featured : null; + this.category_path = product.category ? product.category : null; + this.photo_set = null; + } + } + + isValidPost() { + return ( + !this.id && + this.name && + this.description && + this.cents && + !this.quantity.isNaN && + this.photo_set && + this.category_path && + this.description && + typeof this.featured === "boolean" + ); + } + + isValidPatch(product) { + return ( + this.id && + (this.photo_set || + (this.name && this.name != product.name) || + (this.cents && this.cents != product.cents) || + (this.category_path && this.category_path != product.category) || + (this.quantity && this.quantity != product.quantity) || + (this.description && this.description != product.description) || + (typeof this.featured === "boolean" && + this.featured != product.featured)) + ); + } +} -- cgit v1.2.3