diff options
Diffstat (limited to 'iridescence/src/models')
-rw-r--r-- | iridescence/src/models/product.js | 62 | ||||
-rw-r--r-- | iridescence/src/models/product_diff.js | 43 |
2 files changed, 55 insertions, 50 deletions
diff --git a/iridescence/src/models/product.js b/iridescence/src/models/product.js index fb7fd68..c408b79 100644 --- a/iridescence/src/models/product.js +++ b/iridescence/src/models/product.js @@ -1,54 +1,16 @@ export default class Product { - id = 0; - name = ""; - description = ""; - cents = 0; - quantity = 0; - featured = false; - photo_base = ""; - photo_fullsize = ""; - photo_thumbnail = ""; - category = ""; - - constructor(from) { - if (from) { - this.id = from.id; - this.name = from.name; - this.description = from.description; - this.cents = from.cents; - this.quantity = from.quantity; - this.featured = from.featured; - this.photo_base = from.photo_base; - this.photo_fullsize = from.photo_fullsize; - this.photo_thumbnail = from.photo_thumbnail; - this.category = from.category; + constructor(json) { + if (json) { + this.id = json.id ? json.id : null; + this.name = json.name ? json.name : null; + this.description = json.description ? json.description : null; + this.cents = json.cents ? json.cents : null; + this.quantity = json.quantity ? json.quantity : null; + this.featured = json.featured ? json.featured : false; + this.category = json.category ? json.category : null; + this.photo_base = json.photo_base ? json.photo_base : null; + this.photo_thumbnail = json.photo_thumbnail ? json.photo_thumbnail : null; + this.photo_fullsize = json.photo_fullsize ? json.photo_fullsize : null; } } - - isDifferent(product) { - return ( - this.id != product.id || - this.name != product.name || - this.quantity != product.quantity || - this.cents != product.cents || - this.photo_base != product.photo_base || - this.photo_thumbnail != product.photo_thumbnail || - this.photo_fullsize != product.photo_fullsize || - this.description != product.description || - this.featured != product.featured || - this.category != product.category - ); - } - - isValid() { - return ( - this.cents > 0 && - this.name != "" && - this.photo_thumbnail != "" && - this.photo_base != "" && - this.photo_fullsize != "" && - this.category != "" && - this.description != "" - ); - } } 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)) + ); + } +} |