@unchainedshop/core 4.8.13 → 4.8.15

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.
@@ -0,0 +1,2 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function deleteCartService(this: Modules, orderId: string): Promise<number>;
@@ -0,0 +1,7 @@
1
+ export async function deleteCartService(orderId) {
2
+ await this.orders.positions.deleteOrderPositions(orderId);
3
+ await this.orders.payments.deleteOrderPayments(orderId);
4
+ await this.orders.deliveries.deleteOrderDeliveries(orderId);
5
+ await this.orders.discounts.deleteOrderDiscounts(orderId);
6
+ return this.orders.delete(orderId);
7
+ }
@@ -0,0 +1,2 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function deleteDeadCartsService(this: Modules): Promise<number>;
@@ -0,0 +1,17 @@
1
+ import { deleteCartService } from "./deleteCart.js";
2
+ export async function deleteDeadCartsService() {
3
+ const cartUserIds = (await this.orders.findCartUserIds()).filter(Boolean);
4
+ if (!cartUserIds.length)
5
+ return 0;
6
+ const existingUserIds = new Set(await this.users.findExistingUserIds({ userIds: cartUserIds }));
7
+ const deadUserIds = cartUserIds.filter((userId) => !existingUserIds.has(userId));
8
+ if (!deadUserIds.length)
9
+ return 0;
10
+ const deadCarts = await this.orders.findCarts({ userIds: deadUserIds }, { projection: { _id: 1 } });
11
+ let deletedCount = 0;
12
+ await Array.fromAsync(deadCarts, async (cart) => {
13
+ await deleteCartService.bind(this)(cart._id);
14
+ deletedCount += 1;
15
+ });
16
+ return deletedCount;
17
+ }
@@ -1,3 +1,4 @@
1
+ import { deleteCartService } from "./deleteCart.js";
1
2
  export async function deleteUserService({ userId }) {
2
3
  const user = await this.users.markDeleted(userId);
3
4
  if (!user)
@@ -11,11 +12,7 @@ export async function deleteUserService({ userId }) {
11
12
  }
12
13
  const carts = (await this.orders.findOrders({ userId, includeCarts: true })).filter((c) => c.status === null);
13
14
  await Array.fromAsync(carts, async (userCart) => {
14
- await this.orders.positions.deleteOrderPositions(userCart?._id);
15
- await this.orders.payments.deleteOrderPayments(userCart?._id);
16
- await this.orders.deliveries.deleteOrderDeliveries(userCart?._id);
17
- await this.orders.discounts.deleteOrderDiscounts(userCart?._id);
18
- await this.orders.delete(userCart?._id);
15
+ await deleteCartService.bind(this)(userCart._id);
19
16
  });
20
17
  const ordersCount = await this.orders.count({ userId, includeCarts: true });
21
18
  const quotationsCount = await this.quotations.count({ userId });
@@ -15,6 +15,7 @@ import { initCartProvidersService } from './initCartProviders.ts';
15
15
  import { updateCalculationService } from './updateCalculation.ts';
16
16
  import { supportedDeliveryProvidersService } from './supportedDeliveryProviders.ts';
17
17
  import { deleteUserService } from './deleteUser.ts';
18
+ import { deleteCartService } from './deleteCart.ts';
18
19
  import { supportedPaymentProvidersService } from './supportedPaymentProviders.ts';
19
20
  import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.ts';
20
21
  import { createEnrollmentFromCheckoutService } from './createEnrollmentFromCheckout.ts';
@@ -77,6 +78,7 @@ export default function initServices(modules: Modules, customServices?: CustomSe
77
78
  registerPaymentCredentials: Bound<typeof registerPaymentCredentialsService>;
78
79
  calculateDiscountTotal: Bound<typeof calculateDiscountTotalService>;
79
80
  migrateOrderCarts: Bound<typeof migrateOrderCartsService>;
81
+ deleteCart: Bound<typeof deleteCartService>;
80
82
  nextUserCart: Bound<typeof nextUserCartService>;
81
83
  findOrInitCart: Bound<typeof findOrInitCartService>;
82
84
  initCartProviders: Bound<typeof initCartProvidersService>;
@@ -14,6 +14,7 @@ import { initCartProvidersService } from "./initCartProviders.js";
14
14
  import { updateCalculationService } from "./updateCalculation.js";
15
15
  import { supportedDeliveryProvidersService } from "./supportedDeliveryProviders.js";
16
16
  import { deleteUserService } from "./deleteUser.js";
17
+ import { deleteCartService } from "./deleteCart.js";
17
18
  import { supportedPaymentProvidersService } from "./supportedPaymentProviders.js";
18
19
  import { supportedWarehousingProvidersService } from "./supportedWarehousingProviders.js";
19
20
  import { createEnrollmentFromCheckoutService } from "./createEnrollmentFromCheckout.js";
@@ -88,6 +89,7 @@ export default function initServices(modules, customServices = {}) {
88
89
  registerPaymentCredentials: registerPaymentCredentialsService,
89
90
  calculateDiscountTotal: calculateDiscountTotalService,
90
91
  migrateOrderCarts: migrateOrderCartsService,
92
+ deleteCart: deleteCartService,
91
93
  nextUserCart: nextUserCartService,
92
94
  findOrInitCart: findOrInitCartService,
93
95
  initCartProviders: initCartProvidersService,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core",
3
3
  "description": "Core orchestration package for the Unchained Engine with business services and directors",
4
- "version": "4.8.13",
4
+ "version": "4.8.15",
5
5
  "main": "lib/core-index.js",
6
6
  "types": "lib/core-index.d.ts",
7
7
  "type": "module",