rerobe-js-orm 3.7.1 → 3.7.3

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;
@@ -1040,5 +1044,20 @@ 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
1050
+ .filter((v) => v && v.id && v.name)
1051
+ .map((v) => {
1052
+ return {
1053
+ id: v.id,
1054
+ name: v.name,
1055
+ availableAmount: (v === null || v === void 0 ? void 0 : v.availableAmount) || 0,
1056
+ incomingAmount: (v === null || v === void 0 ? void 0 : v.incomingAmount) || 0,
1057
+ };
1058
+ });
1059
+ }
1060
+ return [];
1061
+ }
1043
1062
  }
1044
1063
  exports.default = Product;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "3.7.1",
3
+ "version": "3.7.3",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",