@unchainedshop/core-orders 2.13.0 → 3.0.0-alpha2

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.
Files changed (38) hide show
  1. package/lib/module/configureOrderDeliveriesModule.d.ts +1 -3
  2. package/lib/module/configureOrderDeliveriesModule.d.ts.map +1 -1
  3. package/lib/module/configureOrderDeliveriesModule.js +2 -9
  4. package/lib/module/configureOrderDeliveriesModule.js.map +1 -1
  5. package/lib/module/configureOrderDiscountsModule.d.ts +1 -3
  6. package/lib/module/configureOrderDiscountsModule.d.ts.map +1 -1
  7. package/lib/module/configureOrderDiscountsModule.js +2 -15
  8. package/lib/module/configureOrderDiscountsModule.js.map +1 -1
  9. package/lib/module/configureOrderPaymentsModule.d.ts +1 -3
  10. package/lib/module/configureOrderPaymentsModule.d.ts.map +1 -1
  11. package/lib/module/configureOrderPaymentsModule.js +2 -11
  12. package/lib/module/configureOrderPaymentsModule.js.map +1 -1
  13. package/lib/module/configureOrderPositionsModule.d.ts +1 -3
  14. package/lib/module/configureOrderPositionsModule.d.ts.map +1 -1
  15. package/lib/module/configureOrderPositionsModule.js +11 -51
  16. package/lib/module/configureOrderPositionsModule.js.map +1 -1
  17. package/lib/module/configureOrdersModule-mutations.d.ts +2 -4
  18. package/lib/module/configureOrdersModule-mutations.d.ts.map +1 -1
  19. package/lib/module/configureOrdersModule-mutations.js +16 -42
  20. package/lib/module/configureOrdersModule-mutations.js.map +1 -1
  21. package/lib/module/configureOrdersModule-processing.d.ts.map +1 -1
  22. package/lib/module/configureOrdersModule-processing.js +15 -19
  23. package/lib/module/configureOrdersModule-processing.js.map +1 -1
  24. package/lib/module/configureOrdersModule.d.ts.map +1 -1
  25. package/lib/module/configureOrdersModule.js +15 -7
  26. package/lib/module/configureOrdersModule.js.map +1 -1
  27. package/lib/service/migrateOrderCartService.d.ts.map +1 -1
  28. package/lib/service/migrateOrderCartService.js +2 -2
  29. package/lib/service/migrateOrderCartService.js.map +1 -1
  30. package/package.json +5 -5
  31. package/src/module/configureOrderDeliveriesModule.ts +1 -15
  32. package/src/module/configureOrderDiscountsModule.ts +1 -25
  33. package/src/module/configureOrderPaymentsModule.ts +1 -15
  34. package/src/module/configureOrderPositionsModule.ts +10 -93
  35. package/src/module/configureOrdersModule-mutations.ts +42 -69
  36. package/src/module/configureOrdersModule-processing.ts +15 -27
  37. package/src/module/configureOrdersModule.ts +22 -7
  38. package/src/service/migrateOrderCartService.ts +2 -6
@@ -95,7 +95,7 @@ export const configureOrdersModule = async ({
95
95
  await Promise.all(
96
96
  systemDiscounts
97
97
  .filter((key) => currentDiscountKeys.indexOf(key) === -1)
98
- .map((discountKey) =>
98
+ .map(async (discountKey) =>
99
99
  modules.orders.discounts.create({
100
100
  orderId: order._id,
101
101
  discountKey,
@@ -256,6 +256,23 @@ export const configureOrdersModule = async ({
256
256
  );
257
257
  };
258
258
 
259
+ const invalidateProviders = async (unchainedAPI, maxAgeDays = 30) => {
260
+ const ONE_DAY_IN_MILLISECONDS = 86400000;
261
+
262
+ const minValidDate = new Date(new Date().getTime() - maxAgeDays * ONE_DAY_IN_MILLISECONDS);
263
+
264
+ const orders = await Orders.find({
265
+ status: { $eq: null },
266
+ updated: { $gte: minValidDate },
267
+ }).toArray();
268
+
269
+ await Promise.allSettled(
270
+ orders.map(async (order) => {
271
+ await updateCalculation(order._id, unchainedAPI);
272
+ }),
273
+ );
274
+ };
275
+
259
276
  const orderQueries = configureOrdersModuleQueries({ Orders });
260
277
  const orderTransformations = configureOrderModuleTransformations({
261
278
  Orders,
@@ -272,28 +289,22 @@ export const configureOrdersModule = async ({
272
289
  OrderDeliveries,
273
290
  OrderPayments,
274
291
  OrderPositions,
275
- initProviders,
276
- updateCalculation,
277
292
  });
278
293
 
279
294
  const orderDiscountsModule = configureOrderDiscountsModule({
280
295
  OrderDiscounts,
281
- updateCalculation,
282
296
  });
283
297
 
284
298
  const orderPositionsModule = configureOrderPositionsModule({
285
299
  OrderPositions,
286
- updateCalculation,
287
300
  });
288
301
 
289
302
  const orderPaymentsModule = configureOrderPaymentsModule({
290
303
  OrderPayments,
291
- updateCalculation,
292
304
  });
293
305
 
294
306
  const orderDeliveriesModule = configureOrderDeliveriesModule({
295
307
  OrderDeliveries,
296
- updateCalculation,
297
308
  });
298
309
 
299
310
  return {
@@ -302,6 +313,10 @@ export const configureOrdersModule = async ({
302
313
  ...orderProcessing,
303
314
  ...orderMutations,
304
315
 
316
+ initProviders,
317
+ updateCalculation,
318
+ invalidateProviders,
319
+
305
320
  // Subentities
306
321
  deliveries: orderDeliveriesModule,
307
322
  discounts: orderDiscountsModule,
@@ -29,16 +29,12 @@ export const migrateOrderCartsService: MigrateOrderCartsService = async (
29
29
 
30
30
  // Move billing address if target order has none
31
31
  if (fromCart.billingAddress && !toCart.billingAddress) {
32
- await unchainedAPI.modules.orders.updateBillingAddress(
33
- toCart._id,
34
- fromCart.billingAddress,
35
- unchainedAPI,
36
- );
32
+ await unchainedAPI.modules.orders.updateBillingAddress(toCart._id, fromCart.billingAddress);
37
33
  }
38
34
 
39
35
  // Move contact data if target order has none
40
36
  if (fromCart.contact && !toCart.contact) {
41
- await unchainedAPI.modules.orders.updateContact(toCart._id, fromCart.contact, unchainedAPI);
37
+ await unchainedAPI.modules.orders.updateContact(toCart._id, fromCart.contact);
42
38
  }
43
39
 
44
40
  await unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI);