Skip to content

Commit

Permalink
Clean up product model
Browse files Browse the repository at this point in the history
  • Loading branch information
janwerkhoven committed Sep 13, 2023
1 parent 5ad98fa commit c8f438f
Showing 1 changed file with 20 additions and 42 deletions.
62 changes: 20 additions & 42 deletions app/models/product.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
import Model, { attr, hasMany, belongsTo } from '@ember-data/model';

export default class ProductModel extends Model {
@attr('string') name;
@attr('string') label;
@attr('string') status;
@attr('string') pitch;
@attr('string') summary;
@attr('string') properties;
@attr('string') instructions;

@attr('number') rankAmongFamily;

@attr('boolean') compliesWithROHS;
@attr('boolean') compliesWithIEC;
@attr('boolean') compliesWithIPCJSTD004A;
@attr('boolean') compliesWithIPCJSTD004B;
@attr('boolean') compliesWithIPCJSTD005;
@attr('boolean') compliesWithISO;
@attr('string') testResults;
@attr('boolean') compliesWithROHS;
@attr('boolean') onFrontPage;
@attr('number') frontPageRank;

@belongsTo('image', { inverse: 'product' }) image;
@attr('number') frontPageRank;
@attr('number') rankAmongFamily;

// Avatar image properties are cached on the product record as to avoid N+1 when loading long lists of products
@attr('string') avatarPath;
@attr('string') avatarAlt;
@attr('string') avatarCaption;
@attr('string') avatarPath;
@attr('string') avatarVariations;
@attr('string') instructions;
@attr('string') label;
@attr('string') name;
@attr('string') pitch;
@attr('string') properties;
@attr('string') status;
@attr('string') summary;
@attr('string') testResults;

// @belongsTo('product-family') productFamily;
@belongsTo('image', { inverse: 'product' }) image;
@belongsTo('product-family') mainFamily;
@belongsTo('product-family') subFamily;
@belongsTo('product', { inverse: 'inferiorProducts' }) superiorProduct;

@hasMany('product-document') productDocuments;
@hasMany('product-image') productImages;
@hasMany('product-quality') productQualities;
@hasMany('product-use') productUses;
@hasMany('product', { inverse: 'superiorProduct' }) inferiorProducts;

get familyLabel() {
if (this.subFamily) {
Expand All @@ -47,24 +50,6 @@ export default class ProductModel extends Model {
return 'product';
}

// get family() {
// return this.productFamily;
// }

// get mainFamily() {
// return this.family.get('isMainFamily')
// ? this.family
// : this.family.get('productFamily');
// }

@belongsTo('product', { inverse: 'inferiorProducts' }) superiorProduct;
@hasMany('product', { inverse: 'superiorProduct' }) inferiorProducts;

@hasMany('product-use') productUses;
@hasMany('product-quality') productQualities;
@hasMany('product-document') productDocuments;
@hasMany('product-image') productImages;

get hasUses() {
return this.uses && this.uses.length > 0;
}
Expand Down Expand Up @@ -157,13 +142,6 @@ export default class ProductModel extends Model {
return JSON.parse(this.testResults);
}

// get familyLabel() {
// const family = this.family.get('nameSingle');
// const label = this.label;

// return label ? label : family;
// }

get compliesWithIPC() {
return (
this.compliesWithIPCJSTD004A ||
Expand Down

0 comments on commit c8f438f

Please sign in to comment.