@unchainedshop/core-orders 4.8.9 → 4.8.11

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.
@@ -6,6 +6,9 @@ export const OrderDeliveryStatus = {
6
6
  };
7
7
  export const OrderDeliveriesCollection = async (db) => {
8
8
  const OrderDeliveries = db.collection('order_deliveries');
9
- await buildDbIndexes(OrderDeliveries, [{ index: { orderId: 1 } }]);
9
+ await buildDbIndexes(OrderDeliveries, [
10
+ { index: { orderId: 1 } },
11
+ { index: { deliveryProviderId: 1 } },
12
+ ]);
10
13
  return OrderDeliveries;
11
14
  };
@@ -3,7 +3,7 @@ export const OrderDiscountsCollection = async (db) => {
3
3
  const OrderDiscounts = db.collection('order_discounts');
4
4
  await buildDbIndexes(OrderDiscounts, [
5
5
  { index: { orderId: 1 } },
6
- { index: { trigger: 1 } },
6
+ { index: { code: 1 }, options: { sparse: true } },
7
7
  ]);
8
8
  return OrderDiscounts;
9
9
  };
@@ -6,6 +6,10 @@ export const OrderPaymentStatus = {
6
6
  };
7
7
  export const OrderPaymentsCollection = async (db) => {
8
8
  const OrderPayments = db.collection('order_payments');
9
- await buildDbIndexes(OrderPayments, [{ index: { orderId: 1 } }]);
9
+ await buildDbIndexes(OrderPayments, [
10
+ { index: { orderId: 1 } },
11
+ { index: { paymentProviderId: 1 } },
12
+ { index: { transactionId: 1 }, options: { sparse: true } },
13
+ ]);
10
14
  return OrderPayments;
11
15
  };
@@ -2,8 +2,8 @@ import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
2
2
  export const OrderPositionsCollection = async (db) => {
3
3
  const OrderPositions = db.collection('order_positions');
4
4
  await buildDbIndexes(OrderPositions, [
5
+ { index: { orderId: 1, quantity: 1 } },
5
6
  { index: { productId: 1 } },
6
- { index: { orderId: 1 } },
7
7
  ]);
8
8
  return OrderPositions;
9
9
  };
@@ -1,4 +1,4 @@
1
- import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
1
+ import { mongodb, buildDbIndexes, } from '@unchainedshop/mongodb';
2
2
  export const OrderStatus = {
3
3
  PENDING: 'PENDING',
4
4
  CONFIRMED: 'CONFIRMED',
@@ -7,36 +7,33 @@ export const OrderStatus = {
7
7
  };
8
8
  export const OrdersCollection = async (db) => {
9
9
  const Orders = db.collection('orders');
10
- if (!isDocumentDBCompatModeEnabled()) {
11
- await buildDbIndexes(Orders, [
12
- {
13
- index: {
14
- _id: 'text',
15
- userId: 'text',
16
- orderNumber: 'text',
17
- status: 'text',
18
- 'contact.emailAddress': 'text',
19
- 'contact.telNumber': 'text',
20
- },
21
- options: {
22
- weights: {
23
- _id: 8,
24
- userId: 3,
25
- orderNumber: 6,
26
- 'contact.telNumber': 5,
27
- 'contact.emailAddress': 4,
28
- status: 1,
29
- },
30
- name: 'order_fulltext_search',
10
+ await buildDbIndexes(Orders, [
11
+ {
12
+ index: {
13
+ _id: 'text',
14
+ userId: 'text',
15
+ orderNumber: 'text',
16
+ status: 'text',
17
+ 'contact.emailAddress': 'text',
18
+ 'contact.telNumber': 'text',
19
+ },
20
+ options: {
21
+ weights: {
22
+ _id: 8,
23
+ userId: 3,
24
+ orderNumber: 6,
25
+ 'contact.telNumber': 5,
26
+ 'contact.emailAddress': 4,
27
+ status: 1,
31
28
  },
29
+ name: 'order_fulltext_search',
32
30
  },
33
- ]);
34
- }
31
+ },
32
+ ]);
35
33
  await buildDbIndexes(Orders, [
36
- { index: { deleted: 1 } },
37
- { index: { userId: 1 } },
38
- { index: { status: 1 } },
39
- { index: { orderNumber: 1 } },
34
+ { index: { userId: 1, status: 1 } },
35
+ { index: { status: 1, updated: 1 } },
36
+ { index: { orderNumber: 1 }, options: { sparse: true } },
40
37
  ]);
41
38
  return Orders;
42
39
  };
@@ -1,4 +1,4 @@
1
- import { assertDocumentDBCompatMode, mongodb } from '@unchainedshop/mongodb';
1
+ import { mongodb } from '@unchainedshop/mongodb';
2
2
  export const buildFindSelector = ({ includeCarts, status, userId, queryString, paymentIds, deliveryIds, dateRange, orderIds, }) => {
3
3
  const selector = {};
4
4
  if (userId) {
@@ -30,7 +30,6 @@ export const buildFindSelector = ({ includeCarts, status, userId, queryString, p
30
30
  selector.status = { $ne: null };
31
31
  }
32
32
  if (queryString) {
33
- assertDocumentDBCompatMode();
34
33
  selector.$text = { $search: queryString };
35
34
  }
36
35
  return selector;
@@ -8,6 +8,9 @@ export declare const configureOrderDeliveriesModule: ({ OrderDeliveries, }: {
8
8
  findDelivery: ({ orderDeliveryId }: {
9
9
  orderDeliveryId: string;
10
10
  }, options?: mongodb.FindOptions) => Promise<OrderDelivery | null>;
11
+ findDeliveries: ({ orderDeliveryIds }: {
12
+ orderDeliveryIds: string[];
13
+ }, options?: mongodb.FindOptions) => Promise<OrderDelivery[]>;
11
14
  findDeliveryByProvidersId: ({ deliveryProviderIds }: {
12
15
  deliveryProviderIds: string[];
13
16
  }, options?: mongodb.FindOptions) => Promise<OrderDelivery[]>;
@@ -32,6 +32,11 @@ export const configureOrderDeliveriesModule = ({ OrderDeliveries, }) => {
32
32
  findDelivery: async ({ orderDeliveryId }, options) => {
33
33
  return OrderDeliveries.findOne(buildFindByIdSelector(orderDeliveryId), options);
34
34
  },
35
+ findDeliveries: async ({ orderDeliveryIds }, options) => {
36
+ if (!orderDeliveryIds?.length)
37
+ return [];
38
+ return OrderDeliveries.find({ _id: { $in: orderDeliveryIds } }, options).toArray();
39
+ },
35
40
  findDeliveryByProvidersId: async ({ deliveryProviderIds }, options) => {
36
41
  if (!deliveryProviderIds?.length)
37
42
  return [];
@@ -7,8 +7,10 @@ export declare const configureOrderDiscountsModule: ({ OrderDiscounts, }: {
7
7
  findOrderDiscount: ({ discountId }: {
8
8
  discountId: string;
9
9
  }, options?: mongodb.FindOptions) => Promise<OrderDiscount | null>;
10
- findOrderDiscounts: ({ orderId }: {
10
+ findOrderDiscounts: (query: {
11
11
  orderId: string;
12
+ } | {
13
+ orderIds: string[];
12
14
  }) => Promise<OrderDiscount[]>;
13
15
  create: (doc: Omit<OrderDiscount, "_id" | "created" | "trigger"> & Pick<Partial<OrderDiscount>, "_id" | "created" | "trigger">) => Promise<OrderDiscount>;
14
16
  delete: (orderDiscountId: string) => Promise<mongodb.WithId<OrderDiscount> | null>;
@@ -13,9 +13,13 @@ export const configureOrderDiscountsModule = ({ OrderDiscounts, }) => {
13
13
  findOrderDiscount: async ({ discountId }, options) => {
14
14
  return OrderDiscounts.findOne(buildFindOrderDiscountByIdSelector(discountId), options);
15
15
  },
16
- findOrderDiscounts: async ({ orderId }) => {
17
- const discounts = OrderDiscounts.find({ orderId });
18
- return discounts.toArray();
16
+ findOrderDiscounts: async (query) => {
17
+ if ('orderIds' in query) {
18
+ if (!query.orderIds?.length)
19
+ return [];
20
+ return OrderDiscounts.find({ orderId: { $in: query.orderIds } }).toArray();
21
+ }
22
+ return OrderDiscounts.find({ orderId: query.orderId }).toArray();
19
23
  },
20
24
  create: async (doc) => {
21
25
  const normalizedTrigger = doc.trigger || OrderDiscountTrigger.USER;
@@ -8,6 +8,9 @@ export declare const configureOrderPaymentsModule: ({ OrderPayments, }: {
8
8
  findOrderPayment: ({ orderPaymentId, }: {
9
9
  orderPaymentId: string;
10
10
  }, options?: mongodb.FindOptions) => Promise<OrderPayment | null>;
11
+ findOrderPayments: ({ orderPaymentIds }: {
12
+ orderPaymentIds: string[];
13
+ }, options?: mongodb.FindOptions) => Promise<OrderPayment[]>;
11
14
  findOrderPaymentsByProviderIds: ({ paymentProviderIds, }: {
12
15
  paymentProviderIds: string[];
13
16
  }, options?: mongodb.FindOptions) => Promise<OrderPayment[]>;
@@ -35,6 +35,11 @@ export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
35
35
  findOrderPayment: async ({ orderPaymentId, }, options) => {
36
36
  return OrderPayments.findOne(buildFindOrderPaymentByIdSelector(orderPaymentId), options);
37
37
  },
38
+ findOrderPayments: async ({ orderPaymentIds }, options) => {
39
+ if (!orderPaymentIds?.length)
40
+ return [];
41
+ return OrderPayments.find({ _id: { $in: orderPaymentIds } }, options).toArray();
42
+ },
38
43
  findOrderPaymentsByProviderIds: async ({ paymentProviderIds, }, options) => {
39
44
  if (!paymentProviderIds?.length)
40
45
  return [];
@@ -23,8 +23,10 @@ export declare const configureOrderPositionsModule: ({ OrderPositions, }: {
23
23
  findOrderPosition: ({ itemId }: {
24
24
  itemId: string;
25
25
  }, options?: mongodb.FindOptions) => Promise<OrderPosition | null>;
26
- findOrderPositions: ({ orderId }: {
26
+ findOrderPositions: (query: {
27
27
  orderId: string;
28
+ } | {
29
+ orderIds: string[];
28
30
  }) => Promise<OrderPosition[]>;
29
31
  delete: (orderPositionId: string) => Promise<mongodb.WithId<OrderPosition> | null>;
30
32
  removePositions: ({ orderId }: {
@@ -13,9 +13,16 @@ export const configureOrderPositionsModule = ({ OrderPositions, }) => {
13
13
  findOrderPosition: async ({ itemId }, options) => {
14
14
  return OrderPositions.findOne(buildFindOrderPositionByIdSelector(itemId), options);
15
15
  },
16
- findOrderPositions: async ({ orderId }) => {
17
- const positions = OrderPositions.find({ orderId, quantity: { $gt: 0 } });
18
- return positions.toArray();
16
+ findOrderPositions: async (query) => {
17
+ if ('orderIds' in query) {
18
+ if (!query.orderIds?.length)
19
+ return [];
20
+ return OrderPositions.find({
21
+ orderId: { $in: query.orderIds },
22
+ quantity: { $gt: 0 },
23
+ }).toArray();
24
+ }
25
+ return OrderPositions.find({ orderId: query.orderId, quantity: { $gt: 0 } }).toArray();
19
26
  },
20
27
  delete: async (orderPositionId) => {
21
28
  const selector = buildFindOrderPositionByIdSelector(orderPositionId);
@@ -6,6 +6,9 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
6
6
  findDelivery: ({ orderDeliveryId }: {
7
7
  orderDeliveryId: string;
8
8
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderDeliveriesCollection.ts").OrderDelivery | null>;
9
+ findDeliveries: ({ orderDeliveryIds }: {
10
+ orderDeliveryIds: string[];
11
+ }, options?: mongodb.FindOptions) => Promise<import("../db/OrderDeliveriesCollection.ts").OrderDelivery[]>;
9
12
  findDeliveryByProvidersId: ({ deliveryProviderIds }: {
10
13
  deliveryProviderIds: string[];
11
14
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderDeliveriesCollection.ts").OrderDelivery[]>;
@@ -25,8 +28,10 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
25
28
  findOrderDiscount: ({ discountId }: {
26
29
  discountId: string;
27
30
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderDiscountsCollection.ts").OrderDiscount | null>;
28
- findOrderDiscounts: ({ orderId }: {
31
+ findOrderDiscounts: (query: {
29
32
  orderId: string;
33
+ } | {
34
+ orderIds: string[];
30
35
  }) => Promise<import("../db/OrderDiscountsCollection.ts").OrderDiscount[]>;
31
36
  create: (doc: Omit<import("../db/OrderDiscountsCollection.ts").OrderDiscount, "_id" | "created" | "trigger"> & Pick<Partial<import("../db/OrderDiscountsCollection.ts").OrderDiscount>, "_id" | "created" | "trigger">) => Promise<import("../db/OrderDiscountsCollection.ts").OrderDiscount>;
32
37
  delete: (orderDiscountId: string) => Promise<mongodb.WithId<import("../db/OrderDiscountsCollection.ts").OrderDiscount> | null>;
@@ -44,8 +49,10 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
44
49
  findOrderPosition: ({ itemId }: {
45
50
  itemId: string;
46
51
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderPositionsCollection.ts").OrderPosition | null>;
47
- findOrderPositions: ({ orderId }: {
52
+ findOrderPositions: (query: {
48
53
  orderId: string;
54
+ } | {
55
+ orderIds: string[];
49
56
  }) => Promise<import("../db/OrderPositionsCollection.ts").OrderPosition[]>;
50
57
  delete: (orderPositionId: string) => Promise<mongodb.WithId<import("../db/OrderPositionsCollection.ts").OrderPosition> | null>;
51
58
  removePositions: ({ orderId }: {
@@ -84,6 +91,9 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
84
91
  findOrderPayment: ({ orderPaymentId, }: {
85
92
  orderPaymentId: string;
86
93
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment | null>;
94
+ findOrderPayments: ({ orderPaymentIds }: {
95
+ orderPaymentIds: string[];
96
+ }, options?: mongodb.FindOptions) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment[]>;
87
97
  findOrderPaymentsByProviderIds: ({ paymentProviderIds, }: {
88
98
  paymentProviderIds: string[];
89
99
  }, options?: mongodb.FindOptions) => Promise<import("../db/OrderPaymentsCollection.ts").OrderPayment[]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-orders",
3
3
  "description": "Order management module for the Unchained Engine",
4
- "version": "4.8.9",
4
+ "version": "4.8.11",
5
5
  "main": "lib/orders-index.js",
6
6
  "types": "lib/orders-index.d.ts",
7
7
  "type": "module",