@unchainedshop/core-orders 4.3.4 → 4.5.0
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.
- package/README.md +137 -3
- package/lib/db/OrderDeliveriesCollection.d.ts +8 -8
- package/lib/db/OrderDeliveriesCollection.js +6 -9
- package/lib/db/OrderDiscountsCollection.d.ts +7 -7
- package/lib/db/OrderDiscountsCollection.js +5 -8
- package/lib/db/OrderPaymentsCollection.d.ts +8 -8
- package/lib/db/OrderPaymentsCollection.js +6 -9
- package/lib/db/OrderPositionsCollection.d.ts +2 -3
- package/lib/db/OrderPositionsCollection.js +1 -3
- package/lib/db/OrdersCollection.d.ts +13 -10
- package/lib/db/OrdersCollection.js +7 -10
- package/lib/migrations/20250502111800-currency-code.d.ts +1 -2
- package/lib/migrations/20250502111800-currency-code.js +1 -2
- package/lib/module/buildFindSelector.d.ts +2 -3
- package/lib/module/buildFindSelector.js +6 -4
- package/lib/module/configureOrderDeliveriesModule.d.ts +2 -3
- package/lib/module/configureOrderDeliveriesModule.js +2 -7
- package/lib/module/configureOrderDiscountsModule.d.ts +1 -2
- package/lib/module/configureOrderDiscountsModule.js +2 -4
- package/lib/module/configureOrderPaymentsModule.d.ts +2 -3
- package/lib/module/configureOrderPaymentsModule.js +2 -9
- package/lib/module/configureOrderPositionsModule.d.ts +10 -3
- package/lib/module/configureOrderPositionsModule.js +48 -4
- package/lib/module/configureOrdersModule-mutations.d.ts +8 -4
- package/lib/module/configureOrdersModule-mutations.js +23 -3
- package/lib/module/configureOrdersModule-queries.d.ts +28 -4
- package/lib/module/configureOrdersModule-queries.js +127 -3
- package/lib/module/configureOrdersModule.d.ts +58 -40
- package/lib/module/configureOrdersModule.js +17 -23
- package/lib/orders-index.d.ts +13 -14
- package/lib/orders-index.js +13 -14
- package/lib/orders-settings.d.ts +1 -2
- package/lib/orders-settings.js +0 -1
- package/package.json +12 -10
- package/lib/db/OrderDeliveriesCollection.d.ts.map +0 -1
- package/lib/db/OrderDeliveriesCollection.js.map +0 -1
- package/lib/db/OrderDiscountsCollection.d.ts.map +0 -1
- package/lib/db/OrderDiscountsCollection.js.map +0 -1
- package/lib/db/OrderPaymentsCollection.d.ts.map +0 -1
- package/lib/db/OrderPaymentsCollection.js.map +0 -1
- package/lib/db/OrderPositionsCollection.d.ts.map +0 -1
- package/lib/db/OrderPositionsCollection.js.map +0 -1
- package/lib/db/OrdersCollection.d.ts.map +0 -1
- package/lib/db/OrdersCollection.js.map +0 -1
- package/lib/migrations/20250502111800-currency-code.d.ts.map +0 -1
- package/lib/migrations/20250502111800-currency-code.js.map +0 -1
- package/lib/module/buildFindSelector.d.ts.map +0 -1
- package/lib/module/buildFindSelector.js.map +0 -1
- package/lib/module/configureOrderDeliveriesModule.d.ts.map +0 -1
- package/lib/module/configureOrderDeliveriesModule.js.map +0 -1
- package/lib/module/configureOrderDiscountsModule.d.ts.map +0 -1
- package/lib/module/configureOrderDiscountsModule.js.map +0 -1
- package/lib/module/configureOrderPaymentsModule.d.ts.map +0 -1
- package/lib/module/configureOrderPaymentsModule.js.map +0 -1
- package/lib/module/configureOrderPositionsModule.d.ts.map +0 -1
- package/lib/module/configureOrderPositionsModule.js.map +0 -1
- package/lib/module/configureOrdersModule-mutations.d.ts.map +0 -1
- package/lib/module/configureOrdersModule-mutations.js.map +0 -1
- package/lib/module/configureOrdersModule-queries.d.ts.map +0 -1
- package/lib/module/configureOrdersModule-queries.js.map +0 -1
- package/lib/module/configureOrdersModule.d.ts.map +0 -1
- package/lib/module/configureOrdersModule.js.map +0 -1
- package/lib/orders-index.d.ts.map +0 -1
- package/lib/orders-index.js.map +0 -1
- package/lib/orders-settings.d.ts.map +0 -1
- package/lib/orders-settings.js.map +0 -1
- package/src/db/OrderDeliveriesCollection.ts +0 -34
- package/src/db/OrderDiscountsCollection.ts +0 -30
- package/src/db/OrderPaymentsCollection.ts +0 -35
- package/src/db/OrderPositionsCollection.ts +0 -32
- package/src/db/OrdersCollection.ts +0 -87
- package/src/migrations/20250502111800-currency-code.ts +0 -18
- package/src/module/buildFindSelector.test.ts +0 -121
- package/src/module/buildFindSelector.ts +0 -49
- package/src/module/configureOrderDeliveriesModule.ts +0 -157
- package/src/module/configureOrderDiscountsModule.ts +0 -95
- package/src/module/configureOrderPaymentsModule.ts +0 -224
- package/src/module/configureOrderPositionsModule.ts +0 -244
- package/src/module/configureOrdersModule-mutations.ts +0 -178
- package/src/module/configureOrdersModule-queries.ts +0 -159
- package/src/module/configureOrdersModule.ts +0 -257
- package/src/orders-index.ts +0 -13
- package/src/orders-settings.ts +0 -45
- package/tsconfig.json +0 -9
package/README.md
CHANGED
|
@@ -1,5 +1,139 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://npmjs.com/package/@unchainedshop/core-orders)
|
|
2
|
+
[](https://opensource.org/licenses/EUPL-1.2)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# @unchainedshop/core-orders
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
Order management module for the Unchained Engine. Handles the complete order lifecycle including positions, payments, deliveries, and discounts.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @unchainedshop/core-orders
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { configureOrdersModule, OrderStatus } from '@unchainedshop/core-orders';
|
|
18
|
+
|
|
19
|
+
const ordersModule = await configureOrdersModule({ db });
|
|
20
|
+
|
|
21
|
+
// Create an order
|
|
22
|
+
const orderId = await ordersModule.create({
|
|
23
|
+
userId: 'user-123',
|
|
24
|
+
currency: 'CHF',
|
|
25
|
+
countryCode: 'CH',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// Add position to order
|
|
29
|
+
await ordersModule.positions.create({
|
|
30
|
+
orderId,
|
|
31
|
+
productId: 'product-456',
|
|
32
|
+
quantity: 2,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Checkout order
|
|
36
|
+
await ordersModule.checkout(orderId, { paymentContext: {} });
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## API Overview
|
|
40
|
+
|
|
41
|
+
### Module Configuration
|
|
42
|
+
|
|
43
|
+
| Export | Description |
|
|
44
|
+
|--------|-------------|
|
|
45
|
+
| `configureOrdersModule` | Configure and return the orders module |
|
|
46
|
+
|
|
47
|
+
### Queries
|
|
48
|
+
|
|
49
|
+
| Method | Description |
|
|
50
|
+
|--------|-------------|
|
|
51
|
+
| `findOrder` | Find order by ID or number |
|
|
52
|
+
| `findOrders` | Find orders with filtering and pagination |
|
|
53
|
+
| `count` | Count orders matching query |
|
|
54
|
+
| `orderExists` | Check if order exists |
|
|
55
|
+
|
|
56
|
+
### Mutations
|
|
57
|
+
|
|
58
|
+
| Method | Description |
|
|
59
|
+
|--------|-------------|
|
|
60
|
+
| `create` | Create a new order |
|
|
61
|
+
| `update` | Update order data |
|
|
62
|
+
| `delete` | Delete an order |
|
|
63
|
+
| `checkout` | Process order checkout |
|
|
64
|
+
| `confirm` | Confirm an order |
|
|
65
|
+
| `reject` | Reject an order |
|
|
66
|
+
| `setPaymentProvider` | Set payment provider |
|
|
67
|
+
| `setDeliveryProvider` | Set delivery provider |
|
|
68
|
+
|
|
69
|
+
### Submodules
|
|
70
|
+
|
|
71
|
+
#### Positions (`orders.positions`)
|
|
72
|
+
| Method | Description |
|
|
73
|
+
|--------|-------------|
|
|
74
|
+
| `findPositions` | Find order positions |
|
|
75
|
+
| `create` | Add position to order |
|
|
76
|
+
| `update` | Update position |
|
|
77
|
+
| `delete` | Remove position |
|
|
78
|
+
|
|
79
|
+
#### Payments (`orders.payments`)
|
|
80
|
+
| Method | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `findPayment` | Find order payment |
|
|
83
|
+
| `create` | Create payment for order |
|
|
84
|
+
| `markPaid` | Mark payment as paid |
|
|
85
|
+
| `charge` | Charge the payment |
|
|
86
|
+
|
|
87
|
+
#### Deliveries (`orders.deliveries`)
|
|
88
|
+
| Method | Description |
|
|
89
|
+
|--------|-------------|
|
|
90
|
+
| `findDelivery` | Find order delivery |
|
|
91
|
+
| `create` | Create delivery for order |
|
|
92
|
+
| `markDelivered` | Mark as delivered |
|
|
93
|
+
| `send` | Trigger delivery |
|
|
94
|
+
|
|
95
|
+
#### Discounts (`orders.discounts`)
|
|
96
|
+
| Method | Description |
|
|
97
|
+
|--------|-------------|
|
|
98
|
+
| `findDiscounts` | Find order discounts |
|
|
99
|
+
| `create` | Add discount to order |
|
|
100
|
+
| `delete` | Remove discount |
|
|
101
|
+
|
|
102
|
+
### Constants
|
|
103
|
+
|
|
104
|
+
| Export | Description |
|
|
105
|
+
|--------|-------------|
|
|
106
|
+
| `OrderStatus` | Order status values (OPEN, PENDING, CONFIRMED, FULLFILLED, REJECTED) |
|
|
107
|
+
|
|
108
|
+
### Settings
|
|
109
|
+
|
|
110
|
+
| Export | Description |
|
|
111
|
+
|--------|-------------|
|
|
112
|
+
| `ordersSettings` | Access order module settings |
|
|
113
|
+
|
|
114
|
+
### Types
|
|
115
|
+
|
|
116
|
+
| Export | Description |
|
|
117
|
+
|--------|-------------|
|
|
118
|
+
| `Order` | Order document type |
|
|
119
|
+
| `OrderPosition` | Position document type |
|
|
120
|
+
| `OrderPayment` | Payment document type |
|
|
121
|
+
| `OrderDelivery` | Delivery document type |
|
|
122
|
+
| `OrderDiscount` | Discount document type |
|
|
123
|
+
| `OrdersModule` | Module interface type |
|
|
124
|
+
|
|
125
|
+
## Events
|
|
126
|
+
|
|
127
|
+
| Event | Description |
|
|
128
|
+
|-------|-------------|
|
|
129
|
+
| `ORDER_CREATE` | Order created |
|
|
130
|
+
| `ORDER_UPDATE` | Order updated |
|
|
131
|
+
| `ORDER_REMOVE` | Order deleted |
|
|
132
|
+
| `ORDER_CHECKOUT` | Order checked out |
|
|
133
|
+
| `ORDER_CONFIRMED` | Order confirmed |
|
|
134
|
+
| `ORDER_REJECTED` | Order rejected |
|
|
135
|
+
| `ORDER_FULLFILLED` | Order fulfilled |
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
EUPL-1.2
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { mongodb, LogFields, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
export declare
|
|
4
|
-
OPEN
|
|
5
|
-
DELIVERED
|
|
6
|
-
RETURNED
|
|
7
|
-
}
|
|
1
|
+
import { mongodb, type LogFields, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { Price } from '@unchainedshop/utils';
|
|
3
|
+
export declare const OrderDeliveryStatus: {
|
|
4
|
+
readonly OPEN: "OPEN";
|
|
5
|
+
readonly DELIVERED: "DELIVERED";
|
|
6
|
+
readonly RETURNED: "RETURNED";
|
|
7
|
+
};
|
|
8
|
+
export type OrderDeliveryStatus = (typeof OrderDeliveryStatus)[keyof typeof OrderDeliveryStatus];
|
|
8
9
|
export type OrderDelivery = {
|
|
9
10
|
_id: string;
|
|
10
11
|
orderId: string;
|
|
@@ -20,4 +21,3 @@ export type OrderDeliveryDiscount = Omit<Price, '_id'> & {
|
|
|
20
21
|
item: OrderDelivery;
|
|
21
22
|
};
|
|
22
23
|
export declare const OrderDeliveriesCollection: (db: mongodb.Db) => Promise<mongodb.Collection<OrderDelivery>>;
|
|
23
|
-
//# sourceMappingURL=OrderDeliveriesCollection.d.ts.map
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(OrderDeliveryStatus || (OrderDeliveryStatus = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
+
export const OrderDeliveryStatus = {
|
|
3
|
+
OPEN: 'OPEN',
|
|
4
|
+
DELIVERED: 'DELIVERED',
|
|
5
|
+
RETURNED: 'RETURNED',
|
|
6
|
+
};
|
|
8
7
|
export const OrderDeliveriesCollection = async (db) => {
|
|
9
8
|
const OrderDeliveries = db.collection('order_deliveries');
|
|
10
|
-
// Order Indexes
|
|
11
9
|
await buildDbIndexes(OrderDeliveries, [{ index: { orderId: 1 } }]);
|
|
12
10
|
return OrderDeliveries;
|
|
13
11
|
};
|
|
14
|
-
//# sourceMappingURL=OrderDeliveriesCollection.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { Price } from '@unchainedshop/utils';
|
|
3
3
|
export type OrderDiscount = {
|
|
4
4
|
_id: string;
|
|
5
5
|
orderId: string;
|
|
@@ -11,8 +11,8 @@ export type OrderDiscount = {
|
|
|
11
11
|
context?: any;
|
|
12
12
|
} & TimestampFields;
|
|
13
13
|
export declare const OrderDiscountsCollection: (db: mongodb.Db) => Promise<mongodb.Collection<OrderDiscount>>;
|
|
14
|
-
export declare
|
|
15
|
-
USER
|
|
16
|
-
SYSTEM
|
|
17
|
-
}
|
|
18
|
-
|
|
14
|
+
export declare const OrderDiscountTrigger: {
|
|
15
|
+
readonly USER: "USER";
|
|
16
|
+
readonly SYSTEM: "SYSTEM";
|
|
17
|
+
};
|
|
18
|
+
export type OrderDiscountTrigger = (typeof OrderDiscountTrigger)[keyof typeof OrderDiscountTrigger];
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
2
|
export const OrderDiscountsCollection = async (db) => {
|
|
3
3
|
const OrderDiscounts = db.collection('order_discounts');
|
|
4
|
-
// Order Indexes
|
|
5
4
|
await buildDbIndexes(OrderDiscounts, [
|
|
6
5
|
{ index: { orderId: 1 } },
|
|
7
6
|
{ index: { trigger: 1 } },
|
|
8
7
|
]);
|
|
9
8
|
return OrderDiscounts;
|
|
10
9
|
};
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})(OrderDiscountTrigger || (OrderDiscountTrigger = {}));
|
|
16
|
-
//# sourceMappingURL=OrderDiscountsCollection.js.map
|
|
10
|
+
export const OrderDiscountTrigger = {
|
|
11
|
+
USER: 'USER',
|
|
12
|
+
SYSTEM: 'SYSTEM',
|
|
13
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { mongodb, LogFields, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
export declare
|
|
4
|
-
OPEN
|
|
5
|
-
PAID
|
|
6
|
-
REFUNDED
|
|
7
|
-
}
|
|
1
|
+
import { mongodb, type LogFields, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { Price } from '@unchainedshop/utils';
|
|
3
|
+
export declare const OrderPaymentStatus: {
|
|
4
|
+
readonly OPEN: "OPEN";
|
|
5
|
+
readonly PAID: "PAID";
|
|
6
|
+
readonly REFUNDED: "REFUNDED";
|
|
7
|
+
};
|
|
8
|
+
export type OrderPaymentStatus = (typeof OrderPaymentStatus)[keyof typeof OrderPaymentStatus];
|
|
8
9
|
export type OrderPayment = {
|
|
9
10
|
_id: string;
|
|
10
11
|
orderId: string;
|
|
@@ -21,4 +22,3 @@ export type OrderPaymentDiscount = Omit<Price, '_id'> & {
|
|
|
21
22
|
item: OrderPayment;
|
|
22
23
|
};
|
|
23
24
|
export declare const OrderPaymentsCollection: (db: mongodb.Db) => Promise<mongodb.Collection<OrderPayment>>;
|
|
24
|
-
//# sourceMappingURL=OrderPaymentsCollection.d.ts.map
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})(OrderPaymentStatus || (OrderPaymentStatus = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
+
export const OrderPaymentStatus = {
|
|
3
|
+
OPEN: 'OPEN',
|
|
4
|
+
PAID: 'PAID',
|
|
5
|
+
REFUNDED: 'REFUNDED',
|
|
6
|
+
};
|
|
8
7
|
export const OrderPaymentsCollection = async (db) => {
|
|
9
8
|
const OrderPayments = db.collection('order_payments');
|
|
10
|
-
// Order Indexes
|
|
11
9
|
await buildDbIndexes(OrderPayments, [{ index: { orderId: 1 } }]);
|
|
12
10
|
return OrderPayments;
|
|
13
11
|
};
|
|
14
|
-
//# sourceMappingURL=OrderPaymentsCollection.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { Price } from '@unchainedshop/utils';
|
|
3
3
|
export type OrderPosition = {
|
|
4
4
|
_id: string;
|
|
5
5
|
calculation: any[];
|
|
@@ -20,4 +20,3 @@ export type OrderPositionDiscount = Omit<Price, '_id'> & {
|
|
|
20
20
|
item: OrderPosition;
|
|
21
21
|
};
|
|
22
22
|
export declare const OrderPositionsCollection: (db: mongodb.Db) => Promise<mongodb.Collection<OrderPosition>>;
|
|
23
|
-
//# sourceMappingURL=OrderPositionsCollection.d.ts.map
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { buildDbIndexes } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
2
|
export const OrderPositionsCollection = async (db) => {
|
|
3
3
|
const OrderPositions = db.collection('order_positions');
|
|
4
|
-
// Order Indexes
|
|
5
4
|
await buildDbIndexes(OrderPositions, [
|
|
6
5
|
{ index: { productId: 1 } },
|
|
7
6
|
{ index: { orderId: 1 } },
|
|
8
7
|
]);
|
|
9
8
|
return OrderPositions;
|
|
10
9
|
};
|
|
11
|
-
//# sourceMappingURL=OrderPositionsCollection.js.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { mongodb, Address, Contact, LogFields, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { DateFilterInput } from '@unchainedshop/utils';
|
|
3
|
-
export declare
|
|
4
|
-
PENDING
|
|
5
|
-
CONFIRMED
|
|
6
|
-
FULLFILLED
|
|
7
|
-
REJECTED
|
|
8
|
-
}
|
|
1
|
+
import { mongodb, type Address, type Contact, type LogFields, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
import type { DateFilterInput } from '@unchainedshop/utils';
|
|
3
|
+
export declare const OrderStatus: {
|
|
4
|
+
readonly PENDING: "PENDING";
|
|
5
|
+
readonly CONFIRMED: "CONFIRMED";
|
|
6
|
+
readonly FULLFILLED: "FULLFILLED";
|
|
7
|
+
readonly REJECTED: "REJECTED";
|
|
8
|
+
};
|
|
9
|
+
export type OrderStatus = (typeof OrderStatus)[keyof typeof OrderStatus];
|
|
9
10
|
export type Order = {
|
|
10
11
|
_id: string;
|
|
11
12
|
billingAddress?: Address;
|
|
@@ -25,7 +26,7 @@ export type Order = {
|
|
|
25
26
|
status: OrderStatus | null;
|
|
26
27
|
userId: string;
|
|
27
28
|
} & LogFields & TimestampFields;
|
|
28
|
-
export interface OrderQuery
|
|
29
|
+
export interface OrderQuery {
|
|
29
30
|
includeCarts?: boolean;
|
|
30
31
|
queryString?: string;
|
|
31
32
|
status?: OrderStatus[];
|
|
@@ -33,6 +34,8 @@ export interface OrderQuery extends mongodb.Filter<Order> {
|
|
|
33
34
|
deliveryIds?: string[];
|
|
34
35
|
paymentIds?: string[];
|
|
35
36
|
dateRange?: DateFilterInput;
|
|
37
|
+
orderIds?: string[];
|
|
38
|
+
paymentProviderIds?: string[];
|
|
39
|
+
deliveryProviderIds?: string[];
|
|
36
40
|
}
|
|
37
41
|
export declare const OrdersCollection: (db: mongodb.Db) => Promise<mongodb.Collection<Order>>;
|
|
38
|
-
//# sourceMappingURL=OrdersCollection.d.ts.map
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(OrderStatus || (OrderStatus = {}));
|
|
1
|
+
import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
|
+
export const OrderStatus = {
|
|
3
|
+
PENDING: 'PENDING',
|
|
4
|
+
CONFIRMED: 'CONFIRMED',
|
|
5
|
+
FULLFILLED: 'FULLFILLED',
|
|
6
|
+
REJECTED: 'REJECTED',
|
|
7
|
+
};
|
|
9
8
|
export const OrdersCollection = async (db) => {
|
|
10
9
|
const Orders = db.collection('orders');
|
|
11
10
|
if (!isDocumentDBCompatModeEnabled()) {
|
|
@@ -33,7 +32,6 @@ export const OrdersCollection = async (db) => {
|
|
|
33
32
|
},
|
|
34
33
|
]);
|
|
35
34
|
}
|
|
36
|
-
// Order Indexes
|
|
37
35
|
await buildDbIndexes(Orders, [
|
|
38
36
|
{ index: { userId: 1 } },
|
|
39
37
|
{ index: { status: 1 } },
|
|
@@ -41,4 +39,3 @@ export const OrdersCollection = async (db) => {
|
|
|
41
39
|
]);
|
|
42
40
|
return Orders;
|
|
43
41
|
};
|
|
44
|
-
//# sourceMappingURL=OrdersCollection.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { MigrationRepository } from '@unchainedshop/mongodb';
|
|
1
|
+
import type { MigrationRepository } from '@unchainedshop/mongodb';
|
|
2
2
|
export default function renameCurrencyCode(repository: MigrationRepository): void;
|
|
3
|
-
//# sourceMappingURL=20250502111800-currency-code.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OrdersCollection } from
|
|
1
|
+
import { OrdersCollection } from "../orders-index.js";
|
|
2
2
|
export default function renameCurrencyCode(repository) {
|
|
3
3
|
repository?.register({
|
|
4
4
|
id: 20250502111800,
|
|
@@ -11,4 +11,3 @@ export default function renameCurrencyCode(repository) {
|
|
|
11
11
|
},
|
|
12
12
|
});
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=20250502111800-currency-code.js.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { OrderQuery, Order } from '../db/OrdersCollection.
|
|
1
|
+
import type { OrderQuery, Order } from '../db/OrdersCollection.ts';
|
|
2
2
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
3
|
-
export declare const buildFindSelector: ({ includeCarts, status, userId, queryString, paymentIds, deliveryIds, dateRange,
|
|
3
|
+
export declare const buildFindSelector: ({ includeCarts, status, userId, queryString, paymentIds, deliveryIds, dateRange, orderIds, }: OrderQuery) => mongodb.Filter<Order>;
|
|
4
4
|
export default buildFindSelector;
|
|
5
|
-
//# sourceMappingURL=buildFindSelector.d.ts.map
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { assertDocumentDBCompatMode } from '@unchainedshop/mongodb';
|
|
2
|
-
export const buildFindSelector = ({ includeCarts, status, userId, queryString, paymentIds, deliveryIds, dateRange,
|
|
3
|
-
const selector = {
|
|
1
|
+
import { assertDocumentDBCompatMode, mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
export const buildFindSelector = ({ includeCarts, status, userId, queryString, paymentIds, deliveryIds, dateRange, orderIds, }) => {
|
|
3
|
+
const selector = {};
|
|
4
4
|
if (userId) {
|
|
5
5
|
selector.userId = userId;
|
|
6
6
|
}
|
|
7
|
+
if (orderIds) {
|
|
8
|
+
selector._id = { $in: orderIds };
|
|
9
|
+
}
|
|
7
10
|
if (dateRange) {
|
|
8
11
|
const dateFilter = {};
|
|
9
12
|
if (dateRange.start)
|
|
@@ -33,4 +36,3 @@ export const buildFindSelector = ({ includeCarts, status, userId, queryString, p
|
|
|
33
36
|
return selector;
|
|
34
37
|
};
|
|
35
38
|
export default buildFindSelector;
|
|
36
|
-
//# sourceMappingURL=buildFindSelector.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
-
import { OrderDelivery, OrderDeliveryStatus } from '../db/OrderDeliveriesCollection.
|
|
2
|
+
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
+
import { type OrderDelivery, OrderDeliveryStatus } from '../db/OrderDeliveriesCollection.ts';
|
|
4
4
|
export declare const buildFindByIdSelector: (orderDeliveryId: string) => mongodb.Filter<OrderDelivery>;
|
|
5
5
|
export declare const configureOrderDeliveriesModule: ({ OrderDeliveries, }: {
|
|
6
6
|
OrderDeliveries: mongodb.Collection<OrderDelivery>;
|
|
@@ -24,4 +24,3 @@ export declare const configureOrderDeliveriesModule: ({ OrderDeliveries, }: {
|
|
|
24
24
|
deleteOrderDeliveries: (orderId: string) => Promise<number>;
|
|
25
25
|
};
|
|
26
26
|
export type OrderDeliveriesModule = ReturnType<typeof configureOrderDeliveriesModule>;
|
|
27
|
-
//# sourceMappingURL=configureOrderDeliveriesModule.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
2
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
|
-
import { OrderDeliveryStatus } from
|
|
3
|
+
import { OrderDeliveryStatus } from "../db/OrderDeliveriesCollection.js";
|
|
4
4
|
const ORDER_DELIVERY_EVENTS = ['ORDER_DELIVER', 'ORDER_UPDATE_DELIVERY'];
|
|
5
5
|
export const buildFindByIdSelector = (orderDeliveryId) => generateDbFilterById(orderDeliveryId);
|
|
6
6
|
export const configureOrderDeliveriesModule = ({ OrderDeliveries, }) => {
|
|
@@ -23,15 +23,12 @@ export const configureOrderDeliveriesModule = ({ OrderDeliveries, }) => {
|
|
|
23
23
|
},
|
|
24
24
|
};
|
|
25
25
|
if (status === OrderDeliveryStatus.DELIVERED) {
|
|
26
|
-
// eslint-disable-next-line
|
|
27
|
-
// @ts-ignore
|
|
28
26
|
modifier.$set.delivered = date;
|
|
29
27
|
}
|
|
30
28
|
const selector = buildFindByIdSelector(orderDeliveryId);
|
|
31
29
|
return OrderDeliveries.findOneAndUpdate(selector, modifier, { returnDocument: 'after' });
|
|
32
30
|
};
|
|
33
31
|
return {
|
|
34
|
-
// Queries
|
|
35
32
|
findDelivery: async ({ orderDeliveryId }, options) => {
|
|
36
33
|
return OrderDeliveries.findOne(buildFindByIdSelector(orderDeliveryId), options);
|
|
37
34
|
},
|
|
@@ -41,7 +38,6 @@ export const configureOrderDeliveriesModule = ({ OrderDeliveries, }) => {
|
|
|
41
38
|
return OrderDeliveries.find({ deliveryProviderId: { $in: deliveryProviderIds } }, options).toArray();
|
|
42
39
|
},
|
|
43
40
|
normalizedStatus,
|
|
44
|
-
// Mutations
|
|
45
41
|
create: async (doc) => {
|
|
46
42
|
const { insertedId: orderDeliveryId } = await OrderDeliveries.insertOne({
|
|
47
43
|
_id: generateDbObjectId(),
|
|
@@ -102,4 +98,3 @@ export const configureOrderDeliveriesModule = ({ OrderDeliveries, }) => {
|
|
|
102
98
|
},
|
|
103
99
|
};
|
|
104
100
|
};
|
|
105
|
-
//# sourceMappingURL=configureOrderDeliveriesModule.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrderDiscount } from '../db/OrderDiscountsCollection.
|
|
2
|
+
import { type OrderDiscount } from '../db/OrderDiscountsCollection.ts';
|
|
3
3
|
export declare const buildFindOrderDiscountByIdSelector: (orderDiscountId: string) => mongodb.Filter<OrderDiscount>;
|
|
4
4
|
export declare const configureOrderDiscountsModule: ({ OrderDiscounts, }: {
|
|
5
5
|
OrderDiscounts: mongodb.Collection<OrderDiscount>;
|
|
@@ -23,4 +23,3 @@ export declare const configureOrderDiscountsModule: ({ OrderDiscounts, }: {
|
|
|
23
23
|
deleteOrderDiscounts: (orderId: string) => Promise<number>;
|
|
24
24
|
};
|
|
25
25
|
export type OrderDiscountsModule = ReturnType<typeof configureOrderDiscountsModule>;
|
|
26
|
-
//# sourceMappingURL=configureOrderDiscountsModule.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import { generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
3
|
-
import { OrderDiscountTrigger } from
|
|
2
|
+
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
|
|
3
|
+
import { OrderDiscountTrigger } from "../db/OrderDiscountsCollection.js";
|
|
4
4
|
const ORDER_DISCOUNT_EVENTS = [
|
|
5
5
|
'ORDER_CREATE_DISCOUNT',
|
|
6
6
|
'ORDER_UPDATE_DISCOUNT',
|
|
@@ -10,7 +10,6 @@ export const buildFindOrderDiscountByIdSelector = (orderDiscountId) => generateD
|
|
|
10
10
|
export const configureOrderDiscountsModule = ({ OrderDiscounts, }) => {
|
|
11
11
|
registerEvents(ORDER_DISCOUNT_EVENTS);
|
|
12
12
|
return {
|
|
13
|
-
// Queries
|
|
14
13
|
findOrderDiscount: async ({ discountId }, options) => {
|
|
15
14
|
return OrderDiscounts.findOne(buildFindOrderDiscountByIdSelector(discountId), options);
|
|
16
15
|
},
|
|
@@ -66,4 +65,3 @@ export const configureOrderDiscountsModule = ({ OrderDiscounts, }) => {
|
|
|
66
65
|
},
|
|
67
66
|
};
|
|
68
67
|
};
|
|
69
|
-
//# sourceMappingURL=configureOrderDiscountsModule.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
-
import { OrderPayment, OrderPaymentStatus } from '../db/OrderPaymentsCollection.
|
|
2
|
+
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
+
import { type OrderPayment, OrderPaymentStatus } from '../db/OrderPaymentsCollection.ts';
|
|
4
4
|
export declare const buildFindOrderPaymentByIdSelector: (orderPaymentId: string) => mongodb.Filter<OrderPayment>;
|
|
5
5
|
export declare const buildFindByContextDataSelector: (context: any) => mongodb.Filter<OrderPayment> | null;
|
|
6
6
|
export declare const configureOrderPaymentsModule: ({ OrderPayments, }: {
|
|
@@ -32,4 +32,3 @@ export declare const configureOrderPaymentsModule: ({ OrderPayments, }: {
|
|
|
32
32
|
deleteOrderPayments: (orderId: string) => Promise<number>;
|
|
33
33
|
};
|
|
34
34
|
export type OrderPaymentsModule = ReturnType<typeof configureOrderPaymentsModule>;
|
|
35
|
-
//# sourceMappingURL=configureOrderPaymentsModule.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import { generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
3
|
-
import { OrderPaymentStatus } from
|
|
2
|
+
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
|
|
3
|
+
import { OrderPaymentStatus } from "../db/OrderPaymentsCollection.js";
|
|
4
4
|
const ORDER_PAYMENT_EVENTS = ['ORDER_UPDATE_PAYMENT', 'ORDER_SIGN_PAYMENT', 'ORDER_PAY'];
|
|
5
5
|
export const buildFindOrderPaymentByIdSelector = (orderPaymentId) => generateDbFilterById(orderPaymentId);
|
|
6
6
|
export const buildFindByContextDataSelector = (context) => {
|
|
@@ -35,20 +35,15 @@ export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
|
|
|
35
35
|
},
|
|
36
36
|
};
|
|
37
37
|
if (transactionId) {
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
// @ts-ignore
|
|
40
38
|
modifier.$set.transactionId = transactionId;
|
|
41
39
|
}
|
|
42
40
|
if (status === OrderPaymentStatus.PAID) {
|
|
43
|
-
// eslint-disable-next-line
|
|
44
|
-
// @ts-ignore
|
|
45
41
|
modifier.$set.paid = date;
|
|
46
42
|
}
|
|
47
43
|
const selector = buildFindOrderPaymentByIdSelector(orderPaymentId);
|
|
48
44
|
return OrderPayments.findOneAndUpdate(selector, modifier, { returnDocument: 'after' });
|
|
49
45
|
};
|
|
50
46
|
return {
|
|
51
|
-
// Queries
|
|
52
47
|
findOrderPayment: async ({ orderPaymentId, }, options) => {
|
|
53
48
|
return OrderPayments.findOne(buildFindOrderPaymentByIdSelector(orderPaymentId), options);
|
|
54
49
|
},
|
|
@@ -70,7 +65,6 @@ export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
|
|
|
70
65
|
return OrderPayments.countDocuments(selector, options);
|
|
71
66
|
},
|
|
72
67
|
normalizedStatus,
|
|
73
|
-
// Mutations
|
|
74
68
|
create: async (doc) => {
|
|
75
69
|
const { insertedId: orderPaymentId } = await OrderPayments.insertOne({
|
|
76
70
|
_id: generateDbObjectId(),
|
|
@@ -140,4 +134,3 @@ export const configureOrderPaymentsModule = ({ OrderPayments, }) => {
|
|
|
140
134
|
},
|
|
141
135
|
};
|
|
142
136
|
};
|
|
143
|
-
//# sourceMappingURL=configureOrderPaymentsModule.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
-
import { OrderPosition } from '../db/OrderPositionsCollection.
|
|
2
|
+
import type { PricingCalculation } from '@unchainedshop/utils';
|
|
3
|
+
import type { OrderPosition } from '../db/OrderPositionsCollection.ts';
|
|
4
4
|
export interface OrderPositionAggregateParams {
|
|
5
5
|
match?: mongodb.Document;
|
|
6
6
|
matchAfterGroup?: mongodb.Document;
|
|
@@ -11,6 +11,11 @@ export interface OrderPositionAggregateParams {
|
|
|
11
11
|
limit?: number;
|
|
12
12
|
pipeline?: mongodb.Document[];
|
|
13
13
|
}
|
|
14
|
+
export interface TopProductRecord {
|
|
15
|
+
productId: string;
|
|
16
|
+
totalSold: number;
|
|
17
|
+
totalRevenue: number;
|
|
18
|
+
}
|
|
14
19
|
export declare const buildFindOrderPositionByIdSelector: (orderPositionId: string, orderId?: string) => mongodb.Filter<OrderPosition>;
|
|
15
20
|
export declare const configureOrderPositionsModule: ({ OrderPositions, }: {
|
|
16
21
|
OrderPositions: mongodb.Collection<OrderPosition>;
|
|
@@ -50,6 +55,8 @@ export declare const configureOrderPositionsModule: ({ OrderPositions, }: {
|
|
|
50
55
|
}) => Promise<OrderPosition>;
|
|
51
56
|
deleteOrderPositions: (orderId: string) => Promise<number>;
|
|
52
57
|
aggregatePositions: ({ match, project, group, addFields, sort, limit, pipeline, }: OrderPositionAggregateParams) => Promise<mongodb.Document[]>;
|
|
58
|
+
getTopProducts: (orderIds: string[], options?: {
|
|
59
|
+
limit?: number;
|
|
60
|
+
}) => Promise<TopProductRecord[]>;
|
|
53
61
|
};
|
|
54
62
|
export type OrderPositionsModule = ReturnType<typeof configureOrderPositionsModule>;
|
|
55
|
-
//# sourceMappingURL=configureOrderPositionsModule.d.ts.map
|