summaryrefslogtreecommitdiff
path: root/iridescence/src/models/product_diff.js
blob: a68310268624e7982dfd9c21ed1f36bab5b169f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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))
    );
  }
}