rerobe-js-orm 2.5.3 → 2.5.6

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.
@@ -89,6 +89,12 @@ class OrderFromFormState extends OrderFactory_1.default {
89
89
  merchantId: ((_s = fs.props) === null || _s === void 0 ? void 0 : _s.merchantId) || '',
90
90
  tags: fs.fields.tags.selectedValues || [],
91
91
  refunds: ((_t = fs.props) === null || _t === void 0 ? void 0 : _t.refunds) || [],
92
+ subtotalPricePresentment: fs.props.subtotalPricePresentment,
93
+ totalDiscountPresentment: fs.props.totalDiscountPresentment,
94
+ totalPricePresentment: fs.props.totalPricePresentment,
95
+ totalRefundedPresentment: fs.props.totalRefundedPresentment,
96
+ totalShippingPricePresentment: fs.props.totalShippingPricePresentment,
97
+ totalTaxPresentment: fs.props.totalTaxPresentment,
92
98
  };
93
99
  return new Order_1.default(Object.assign({}, orderAttributes));
94
100
  }
@@ -4,7 +4,7 @@ const ProductFactory_1 = require("./ProductFactory");
4
4
  const Product_1 = require("../../models/Product");
5
5
  class ProductFromFormState extends ProductFactory_1.default {
6
6
  createProduct(props) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
8
8
  const productAttributes = {
9
9
  availableForSale: props.fields.availableForSale.selectedValue,
10
10
  description: props.fields.description.inputValue,
@@ -102,6 +102,7 @@ class ProductFromFormState extends ProductFactory_1.default {
102
102
  liquidationRequestedTimestamp: (_12 = props.props) === null || _12 === void 0 ? void 0 : _12.liquidationRequestedTimestamp,
103
103
  sellerLiquidatedTimestamp: (_13 = props.props) === null || _13 === void 0 ? void 0 : _13.sellerLiquidatedTimestamp,
104
104
  archivedTimestamp: (_14 = props.props) === null || _14 === void 0 ? void 0 : _14.archivedTimestamp,
105
+ liquidationReadyTimestamp: (_15 = props.props) === null || _15 === void 0 ? void 0 : _15.liquidationReadyTimestamp,
105
106
  };
106
107
  return new Product_1.default(Object.assign(Object.assign(Object.assign(Object.assign({}, productAttributes), productFilterAttributes), consignmentAttributes), timestampAttributes));
107
108
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.conditionTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
3
+ exports.productOptions = exports.productIsOnSaleOptions = exports.discountTypeOptions = exports.salesChannelOptions = exports.unisexJewelry = exports.mensJewelry = exports.jewelry = exports.unisexAccessories = exports.mensAccessories = exports.accessories = exports.unisexBags = exports.mensBags = exports.bags = exports.unisexShoes = exports.mensShoes = exports.shoes = exports.unisexClothing = exports.mensClothing = exports.clothing = exports.productCategories = exports.clothingMaterials = exports.shoeSizes = exports.jeanSizes = exports.gender = exports.conditions = exports.colors = exports.brands = exports.sizeCommentOptions = exports.clothingSizeOptions = exports.statusOptions = exports.publishTypeOptions = exports.availableForSaleOptions = void 0;
4
4
  const ProductStateManager_1 = require("../../models/ProductStateManager");
5
5
  const lodash_1 = require("lodash");
6
6
  const availableForSaleOptions = [
@@ -9,4 +9,8 @@ export default class OrderHelpers {
9
9
  getOrderInfoWithRefundsAndFulfillments(order: CompleteOrder): OrderWithRefundsAndFulfillmentsInfoObj;
10
10
  getUpdatedOrderObjWithRefunds(orderObj: CompleteOrder, refundObj: OrderRefund): CompleteOrder;
11
11
  getUpdatedOrderObjWithFulfillment(orderObj: CompleteOrder, fulfillmentObj: FulfillmentAdmin, totalUnfulfilledItems: number): CompleteOrder;
12
+ getSubtotalPrice(lineItems: ReRobeOrderLineItem[] | any[], userAvailableCredit?: number | string): number;
13
+ getCreditDiscount(lineItems: ReRobeOrderLineItem[] | undefined, userAvailableCredit: number | string): number;
14
+ getSaleDiscount(lineItems?: ReRobeOrderLineItem[]): number;
15
+ getDiscountAmount(lineItems?: ReRobeOrderLineItem[], userAvailableCredit?: number | string): number;
12
16
  }
@@ -84,6 +84,9 @@ class OrderHelpers {
84
84
  },
85
85
  shopifyProductId: product.shopifyId || null,
86
86
  productId: product.documentId,
87
+ status: product.status || '',
88
+ isOnSale: product.isOnSale || '',
89
+ salePrice: product.salePrice || '',
87
90
  };
88
91
  }
89
92
  toFixedPointPrice(price) {
@@ -193,5 +196,49 @@ class OrderHelpers {
193
196
  totalUnfulfilledItems - fulfilledItemsQuantity > 0 ? 'PARTIALLY_FULFILLED' : 'FULFILLED';
194
197
  return updatedOrder;
195
198
  }
199
+ getSubtotalPrice(lineItems, userAvailableCredit = 0) {
200
+ // Get subtotal without saleDiscount (products on sale) and creditDiscount (userAvailableCredit)
201
+ if (!lineItems || !lineItems.length) {
202
+ return 0;
203
+ }
204
+ const subtotalWithoutSaleDiscount = lineItems.reduce((acc, lineItem) => {
205
+ var _a;
206
+ const isSaleItem = lineItem.isOnSale === 'yes' && (lineItem.status === 'CLEARANCE' || lineItem.status === 'RESERVED');
207
+ const itemPrice = isSaleItem ? lineItem.salePrice : (_a = lineItem.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount;
208
+ return acc + Number(itemPrice);
209
+ }, 0);
210
+ let subtotal = subtotalWithoutSaleDiscount;
211
+ if (userAvailableCredit && Number(userAvailableCredit) > 0) {
212
+ subtotal = subtotalWithoutSaleDiscount - Number(userAvailableCredit);
213
+ }
214
+ if (subtotal < 0) {
215
+ subtotal = 0;
216
+ }
217
+ return Number(Number(subtotal).toFixed(2));
218
+ }
219
+ getCreditDiscount(lineItems = [], userAvailableCredit) {
220
+ if (!userAvailableCredit || Number(userAvailableCredit) <= 0) {
221
+ return 0;
222
+ }
223
+ const subtotal = this.getSubtotalPrice(lineItems);
224
+ return subtotal > userAvailableCredit ? Number(userAvailableCredit) : subtotal;
225
+ }
226
+ getSaleDiscount(lineItems = []) {
227
+ return lineItems.reduce((acc, cur) => {
228
+ var _a;
229
+ const isSaleItem = cur.isOnSale === 'yes' && (cur.status === 'CLEARANCE' || cur.status === 'RESERVED');
230
+ let prodDiscount = 0;
231
+ if (isSaleItem) {
232
+ prodDiscount = Number((Number((_a = cur.originalTotalPrice) === null || _a === void 0 ? void 0 : _a.amount) - Number(cur.salePrice)).toFixed(2));
233
+ }
234
+ return acc + prodDiscount;
235
+ }, 0);
236
+ }
237
+ getDiscountAmount(lineItems = [], userAvailableCredit = 0) {
238
+ const creditDiscount = this.getCreditDiscount(lineItems, userAvailableCredit);
239
+ const saleDiscount = this.getSaleDiscount(lineItems);
240
+ const discount = Number(Number(creditDiscount + saleDiscount).toFixed(2));
241
+ return discount;
242
+ }
196
243
  }
197
244
  exports.default = OrderHelpers;
@@ -6,19 +6,19 @@ const options_1 = require("../form-states/Product/options");
6
6
  const ProductStateManager_1 = require("../models/ProductStateManager");
7
7
  class ReRobeProductHelpers {
8
8
  static calculateProductionFee(commission) {
9
- if (commission >= 0.5 || commission === 0.2 || commission === 0.15 || commission === 0) {
10
- return 0;
11
- }
12
9
  if (commission === 0.16) {
13
10
  return 19;
14
11
  }
15
- return 40;
12
+ if (commission === 0.35) {
13
+ return 40;
14
+ }
15
+ return 0;
16
16
  }
17
17
  static calculateFulfillmentFee(commission) {
18
- if (commission >= 0.5 || commission === 0.2 || commission === 0.15 || commission === 0 || commission === 0.16) {
19
- return 0;
18
+ if (commission === 0.35) {
19
+ return 24;
20
20
  }
21
- return 24;
21
+ return 0;
22
22
  }
23
23
  static buildReRobeEarnings(arrayLike) {
24
24
  const products = Array.isArray(arrayLike) ? arrayLike : [arrayLike];
@@ -226,7 +226,7 @@ class ReRobeProductHelpers {
226
226
  static createTimestampsForStates(productObj) {
227
227
  const docFieldsToUpdate = {};
228
228
  if (productObj) {
229
- const { status, sellRequestReviewDraftTimestamp, sellRequestReviewTimestamp, rejectedTimestamp, holdTimestamp, acceptedTimestamp, sellerToDropOffTimestamp, sellerToShipTimestamp, sellerToGetPickUpTimestamp, qualityControlTimestamp, pendingPublicationTimestamp, listedTimestamp, clearanceTimestamp, reservedTimestamp, soldTimestamp, soldSellerToBePaidTimestamp, soldSellerPaidTimestamp, returnedTimestamp, sellerSelfRejectTimestamp, liquidationRequestedTimestamp, sellerLiquidatedTimestamp, archivedTimestamp, } = productObj;
229
+ const { status, sellRequestReviewDraftTimestamp, sellRequestReviewTimestamp, rejectedTimestamp, holdTimestamp, acceptedTimestamp, sellerToDropOffTimestamp, sellerToShipTimestamp, sellerToGetPickUpTimestamp, qualityControlTimestamp, pendingPublicationTimestamp, listedTimestamp, clearanceTimestamp, reservedTimestamp, soldTimestamp, soldSellerToBePaidTimestamp, soldSellerPaidTimestamp, returnedTimestamp, sellerSelfRejectTimestamp, liquidationRequestedTimestamp, sellerLiquidatedTimestamp, archivedTimestamp, liquidationReadyTimestamp, } = productObj;
230
230
  if (status === ProductStateManager_1.default.PRODUCT_STATES.sellRequestReviewDraft && !sellRequestReviewDraftTimestamp) {
231
231
  docFieldsToUpdate.sellRequestReviewDraftTimestamp = new Date().getTime();
232
232
  }
@@ -301,6 +301,9 @@ class ReRobeProductHelpers {
301
301
  if (status === ProductStateManager_1.default.PRODUCT_STATES.archived && !archivedTimestamp) {
302
302
  docFieldsToUpdate.archivedTimestamp = new Date().getTime();
303
303
  }
304
+ if (status === ProductStateManager_1.default.PRODUCT_STATES.liquidationReady && !liquidationReadyTimestamp) {
305
+ docFieldsToUpdate.liquidationReadyTimestamp = new Date().getTime();
306
+ }
304
307
  }
305
308
  return docFieldsToUpdate;
306
309
  }
@@ -82,6 +82,12 @@ export default class Order extends Base {
82
82
  customerName: string;
83
83
  merchantId: string;
84
84
  refunds: OrderRefund[];
85
+ subtotalPricePresentment: Money;
86
+ totalDiscountPresentment: Money;
87
+ totalPricePresentment: Money;
88
+ totalRefundedPresentment: Money;
89
+ totalShippingPricePresentment: Money;
90
+ totalTaxPresentment: Money;
85
91
  constructor(props?: any);
86
92
  toObj(): ReRobeOrderObj;
87
93
  }
@@ -105,6 +105,24 @@ class Order extends Base_1.default {
105
105
  this.customerName = (props === null || props === void 0 ? void 0 : props.customerName) || '';
106
106
  this.merchantId = (props === null || props === void 0 ? void 0 : props.merchantId) || '';
107
107
  this.refunds = (props === null || props === void 0 ? void 0 : props.refunds) || [];
108
+ this.subtotalPricePresentment = (props === null || props === void 0 ? void 0 : props.subtotalPricePresentment) || {
109
+ amount: 0,
110
+ };
111
+ this.totalDiscountPresentment = (props === null || props === void 0 ? void 0 : props.totalDiscountPresentment) || {
112
+ amount: 0,
113
+ };
114
+ this.totalPricePresentment = (props === null || props === void 0 ? void 0 : props.totalPricePresentment) || {
115
+ amount: 0,
116
+ };
117
+ this.totalRefundedPresentment = (props === null || props === void 0 ? void 0 : props.totalRefundedPresentment) || {
118
+ amount: 0,
119
+ };
120
+ this.totalShippingPricePresentment = (props === null || props === void 0 ? void 0 : props.totalShippingPricePresentment) || {
121
+ amount: 0,
122
+ };
123
+ this.totalTaxPresentment = (props === null || props === void 0 ? void 0 : props.totalTaxPresentment) || {
124
+ amount: 0,
125
+ };
108
126
  }
109
127
  toObj() {
110
128
  const orderObj = {
@@ -150,6 +168,12 @@ class Order extends Base_1.default {
150
168
  customerName: this.customerName,
151
169
  merchantId: this.merchantId,
152
170
  refunds: this.refunds,
171
+ subtotalPricePresentment: this.subtotalPricePresentment,
172
+ totalDiscountPresentment: this.totalDiscountPresentment,
173
+ totalPricePresentment: this.totalPricePresentment,
174
+ totalRefundedPresentment: this.totalRefundedPresentment,
175
+ totalShippingPricePresentment: this.totalShippingPricePresentment,
176
+ totalTaxPresentment: this.totalTaxPresentment,
153
177
  };
154
178
  if (this.paymentType) {
155
179
  orderObj.paymentType = this.paymentType;
@@ -114,6 +114,7 @@ class Product extends Base_1.default {
114
114
  : null,
115
115
  sellerLiquidatedTimestamp: (props === null || props === void 0 ? void 0 : props.sellerLiquidatedTimestamp) ? Number(props === null || props === void 0 ? void 0 : props.sellerLiquidatedTimestamp) : null,
116
116
  archivedTimestamp: (props === null || props === void 0 ? void 0 : props.archivedTimestamp) ? Number(props === null || props === void 0 ? void 0 : props.archivedTimestamp) : null,
117
+ liquidationReadyTimestamp: (props === null || props === void 0 ? void 0 : props.liquidationReadyTimestamp) ? Number(props === null || props === void 0 ? void 0 : props.liquidationReadyTimestamp) : null,
117
118
  };
118
119
  }
119
120
  toPartialObj() {
@@ -279,6 +280,7 @@ class Product extends Base_1.default {
279
280
  liquidationRequestedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.liquidationRequestedTimestamp),
280
281
  sellerLiquidatedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.sellerLiquidatedTimestamp),
281
282
  archivedTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.archivedTimestamp),
283
+ liquidationReadyTimestamp: this.utilities.sanitizeMillisTimeStamp(this.timestampAttributes.liquidationReadyTimestamp),
282
284
  selectedForClearance: this.utilities.sanitizeString(this.consignmentAttributes.selectedForClearance),
283
285
  availableForSale: !!this.attributes.availableForSale,
284
286
  color: this.utilities.sanitizeString(this.filterAttributes.color),
@@ -22,6 +22,7 @@ export default class ProductStateManager extends Base {
22
22
  soldSellerPaid: string;
23
23
  sellerSelfReject: string;
24
24
  liquidationRequested: string;
25
+ liquidationReady: string;
25
26
  sellerLiquidated: string;
26
27
  loading: string;
27
28
  shoppingBag: string;
@@ -371,6 +371,7 @@ ProductStateManager.PRODUCT_STATES = {
371
371
  soldSellerPaid: 'SOLD_SELLER_PAID',
372
372
  sellerSelfReject: 'SELLER_SELF_REJECT',
373
373
  liquidationRequested: 'LIQUIDATION_REQUESTED',
374
+ liquidationReady: 'LIQUIDATION_READY',
374
375
  sellerLiquidated: 'SELLER_LIQUIDATED',
375
376
  loading: 'LOADING',
376
377
  shoppingBag: 'IN_SHOPPING_BAG',
@@ -63,6 +63,12 @@ declare type ReRobeOrderObj = {
63
63
  refunds?: OrderRefund[];
64
64
  createdAt?: string;
65
65
  updatedAt?: string;
66
+ subtotalPricePresentment?: Money;
67
+ totalDiscountPresentment?: Money;
68
+ totalPricePresentment?: Money;
69
+ totalRefundedPresentment?: Money;
70
+ totalShippingPricePresentment?: Money;
71
+ totalTaxPresentment?: Money;
66
72
  };
67
73
  declare type OrderWithRefundsAndFulfillmentsInfoObj = {
68
74
  documentId?: string;
@@ -213,6 +219,9 @@ interface ReRobeOrderLineItem extends OrderLineItem {
213
219
  canceledQuantity?: number | string;
214
220
  fulfilledQuantity?: number | string;
215
221
  unfulfilledQuantity?: number | string;
222
+ status?: ProductSellStatusKeys | string;
223
+ isOnSale?: string;
224
+ salePrice?: string;
216
225
  }
217
226
  declare type OrderLineItemConnection = {
218
227
  edges: OrderLineItemEdge[];
@@ -95,6 +95,7 @@ declare type ProductTimestampAttributes = {
95
95
  liquidationRequestedTimestamp: number | null;
96
96
  sellerLiquidatedTimestamp: number | null;
97
97
  archivedTimestamp: number | null;
98
+ liquidationReadyTimestamp: number | null;
98
99
  };
99
100
  declare type TranslatableAttributes = {
100
101
  description: string;
@@ -281,6 +282,7 @@ declare type TypesenseProductObj = {
281
282
  liquidationRequestedTimestamp: number;
282
283
  sellerLiquidatedTimestamp: number;
283
284
  archivedTimestamp: number;
285
+ liquidationReadyTimestamp: number;
284
286
  availableForSale: boolean;
285
287
  color: string;
286
288
  description: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.5.3",
3
+ "version": "2.5.6",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",