@unchainedshop/core-orders 4.8.12 → 4.8.13

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.
@@ -2,7 +2,7 @@ import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
2
2
  export const OrderDiscountsCollection = async (db) => {
3
3
  const OrderDiscounts = db.collection('order_discounts');
4
4
  await buildDbIndexes(OrderDiscounts, [
5
- { index: { orderId: 1 } },
5
+ { index: { orderId: 1, created: 1 } },
6
6
  { index: { code: 1 }, options: { sparse: true } },
7
7
  ]);
8
8
  return OrderDiscounts;
@@ -2,7 +2,7 @@ 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
+ { index: { orderId: 1, created: 1 } },
6
6
  { index: { productId: 1 } },
7
7
  ]);
8
8
  return OrderPositions;
@@ -17,9 +17,9 @@ export const configureOrderDiscountsModule = ({ OrderDiscounts, }) => {
17
17
  if ('orderIds' in query) {
18
18
  if (!query.orderIds?.length)
19
19
  return [];
20
- return OrderDiscounts.find({ orderId: { $in: query.orderIds } }).toArray();
20
+ return OrderDiscounts.find({ orderId: { $in: query.orderIds } }, { sort: { created: 1 } }).toArray();
21
21
  }
22
- return OrderDiscounts.find({ orderId: query.orderId }).toArray();
22
+ return OrderDiscounts.find({ orderId: query.orderId }, { sort: { created: 1 } }).toArray();
23
23
  },
24
24
  create: async (doc) => {
25
25
  const normalizedTrigger = doc.trigger || OrderDiscountTrigger.USER;
@@ -20,9 +20,9 @@ export const configureOrderPositionsModule = ({ OrderPositions, }) => {
20
20
  return OrderPositions.find({
21
21
  orderId: { $in: query.orderIds },
22
22
  quantity: { $gt: 0 },
23
- }).toArray();
23
+ }, { sort: { created: 1 } }).toArray();
24
24
  }
25
- return OrderPositions.find({ orderId: query.orderId, quantity: { $gt: 0 } }).toArray();
25
+ return OrderPositions.find({ orderId: query.orderId, quantity: { $gt: 0 } }, { sort: { created: 1 } }).toArray();
26
26
  },
27
27
  delete: async (orderPositionId) => {
28
28
  const selector = buildFindOrderPositionByIdSelector(orderPositionId);
@@ -48,6 +48,9 @@ export declare const configureOrdersModuleQueries: ({ Orders }: {
48
48
  orderNumber?: string;
49
49
  userId: string;
50
50
  }) => Promise<mongodb.WithId<Order> | null>;
51
+ findCarts: ({ userIds }: {
52
+ userIds: string[];
53
+ }, options?: mongodb.FindOptions) => Promise<Order[]>;
51
54
  count: (query: OrderQuery) => Promise<number>;
52
55
  findOrder: ({ orderId, orderNumber, }: {
53
56
  orderId?: string;
@@ -33,6 +33,9 @@ export const configureOrdersModuleQueries = ({ Orders }) => {
33
33
  };
34
34
  return Orders.findOne(selector, options);
35
35
  },
36
+ findCarts: async ({ userIds }, options) => {
37
+ return Orders.find({ status: { $eq: null }, userId: { $in: userIds } }, { sort: { updated: -1 }, ...options }).toArray();
38
+ },
36
39
  count: async (query) => {
37
40
  const orderCount = await Orders.countDocuments(buildFindSelector(query));
38
41
  return orderCount;
@@ -152,6 +152,9 @@ export declare const configureOrdersModule: ({ db, migrationRepository, options:
152
152
  orderNumber?: string;
153
153
  userId: string;
154
154
  }) => Promise<mongodb.WithId<Order> | null>;
155
+ findCarts: ({ userIds }: {
156
+ userIds: string[];
157
+ }, options?: mongodb.FindOptions) => Promise<Order[]>;
155
158
  count: (query: import("../db/OrdersCollection.ts").OrderQuery) => Promise<number>;
156
159
  findOrder: ({ orderId, orderNumber, }: {
157
160
  orderId?: string;
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.12",
4
+ "version": "4.8.13",
5
5
  "main": "lib/orders-index.js",
6
6
  "types": "lib/orders-index.d.ts",
7
7
  "type": "module",