rerobe-js-orm 3.7.0 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,4 +45,5 @@ export default class Product extends Base {
45
45
  private convertMaterialCompJoinedStrToObj;
46
46
  private sanitizeMaterialComp;
47
47
  private sanitizeCommission;
48
+ private validateInventoryLocation;
48
49
  }
@@ -83,7 +83,7 @@ class Product extends Base_1.default {
83
83
  discountValue: (props === null || props === void 0 ? void 0 : props.discountValue) || '',
84
84
  selectedForClearance: (props === null || props === void 0 ? void 0 : props.selectedForClearance) || '',
85
85
  locationIds: (props === null || props === void 0 ? void 0 : props.locationIds) || [],
86
- inventoryLocations: (props === null || props === void 0 ? void 0 : props.inventoryLocations) || [],
86
+ inventoryLocations: this.validateInventoryLocation(props === null || props === void 0 ? void 0 : props.inventoryLocations) || [],
87
87
  majorDefects: (props === null || props === void 0 ? void 0 : props.majorDefects) || [],
88
88
  minorDefects: (props === null || props === void 0 ? void 0 : props.minorDefects) || [],
89
89
  };
@@ -276,6 +276,7 @@ class Product extends Base_1.default {
276
276
  };
277
277
  }
278
278
  toObjForTypesense() {
279
+ var _a, _b;
279
280
  const createdAtTimestamp = this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.createdAtTimestamp);
280
281
  const { createdAtHour, createdAtDay, createdAtMonth, createdAtYear } = this.utilities.formatTimestamp(createdAtTimestamp);
281
282
  const stagedObj = {
@@ -362,12 +363,15 @@ class Product extends Base_1.default {
362
363
  ? this.consignmentAttributes.inventoryLocations.map((c) => String(c.id))
363
364
  : [],
364
365
  };
365
- this.consignmentAttributes.inventoryLocations.forEach((l) => {
366
- if (l.id) {
367
- stagedObj[`inventoryLocations.${l.id}.availableAmount`] = l.availableAmount || 0;
368
- stagedObj[`inventoryLocations.${l.id}.incomingAmount`] = l.incomingAmount || 0;
369
- }
370
- });
366
+ if (((_a = this.consignmentAttributes) === null || _a === void 0 ? void 0 : _a.inventoryLocations) &&
367
+ Array.isArray((_b = this.consignmentAttributes) === null || _b === void 0 ? void 0 : _b.inventoryLocations)) {
368
+ this.consignmentAttributes.inventoryLocations.forEach((l) => {
369
+ if (l.id) {
370
+ stagedObj[`inventoryLocations.${l.id}.availableAmount`] = (l === null || l === void 0 ? void 0 : l.availableAmount) || 0;
371
+ stagedObj[`inventoryLocations.${l.id}.incomingAmount`] = (l === null || l === void 0 ? void 0 : l.incomingAmount) || 0;
372
+ }
373
+ });
374
+ }
371
375
  Object.values(this.sanitizeMaterialComp()).forEach((v, i) => {
372
376
  if (v) {
373
377
  stagedObj[`materialComposition.${Object.keys(this.sanitizeMaterialComp())[i]}.value`] = v;
@@ -929,10 +933,10 @@ class Product extends Base_1.default {
929
933
  const attributeKeys = Object.keys(this.attributes);
930
934
  const filterAttributeKeys = Object.keys(this.filterAttributes);
931
935
  const consignmentAttributeKeys = Object.keys(this.consignmentAttributes);
932
- // const timestampAttributeKeys = Object.keys(this.timestampAttributes);
933
- const allKeys = [...attributeKeys, ...filterAttributeKeys, ...consignmentAttributeKeys];
936
+ const timestampAttributeKeys = Object.keys(this.timestampAttributes);
937
+ const allKeys = [...attributeKeys, ...filterAttributeKeys, ...consignmentAttributeKeys, ...timestampAttributeKeys];
934
938
  const restrictedKeys = ['documentId', 'merchantId', 'merchants'];
935
- const systemManagedKeys = ['reservedBy', 'sellRequestId', 'rfidTag'];
939
+ const systemManagedKeys = ['reservedBy', 'sellRequestId'];
936
940
  const configurableAfterCreationKeys = ['editorAuthorizations', 'featuredCollections'];
937
941
  const obsoleteKeys = ['clothingSize', 'jeanSize', 'shoeSize'];
938
942
  const options = allKeys
@@ -1040,5 +1044,11 @@ class Product extends Base_1.default {
1040
1044
  }
1041
1045
  return parseFloat(String(com)) / 100;
1042
1046
  }
1047
+ validateInventoryLocation(locationLike) {
1048
+ if (locationLike && Array.isArray(locationLike) && locationLike.length > 0) {
1049
+ return locationLike.filter((v) => v && Object.keys(v).every((e) => ['id', 'name', 'availableAmount', 'incomingAmount'].includes(e)));
1050
+ }
1051
+ return [];
1052
+ }
1043
1053
  }
1044
1054
  exports.default = Product;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.7.0",
3
+ "version": "3.7.2",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",