@unchainedshop/core-orders 4.3.4 → 4.4.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 +9 -9
- 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 +1 -2
- package/lib/module/buildFindSelector.js +1 -2
- 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 +2 -3
- package/lib/module/configureOrderPositionsModule.js +1 -4
- package/lib/module/configureOrdersModule-mutations.d.ts +3 -4
- package/lib/module/configureOrdersModule-mutations.js +2 -3
- package/lib/module/configureOrdersModule-queries.d.ts +2 -3
- package/lib/module/configureOrdersModule-queries.js +3 -3
- package/lib/module/configureOrdersModule.d.ts +39 -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 +11 -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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configureOrdersModule.js","sourceRoot":"","sources":["../../src/module/configureOrdersModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAwB,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAS,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,cAAc,EAAyB,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AACrF,OAAO,EAAE,4BAA4B,EAA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EAAE;oBACf,iBAAiB;oBACjB,GAAG,EAAE,EAAE;oBACP,OAAO;oBACP,MAAM,EAAE,IAAI;iBACb,CAAC,CACH,CAAC,GAAG,CAAC;YAER,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,gBAAgB,CACzC,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAC/C;gBACE,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,EAAE;aACzC,EACD,EAAE,cAAc,EAAE,OAAO,EAAE,CAC5B,CAAC;YAEF,IAAI,CAAC,KAAK;gBAAE,OAAO,IAAI,CAAC;YACxB,MAAM,IAAI,CAAC,4BAA4B,EAAE;gBACvC,KAAK;gBACL,iBAAiB;aAClB,CAAC,CAAC;YAEH,OAAO,KAAK,CAAC;QACf,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orders-index.d.ts","sourceRoot":"","sources":["../src/orders-index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,0CAA0C,CAAC;AACzD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,6CAA6C,CAAC;AAC5D,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC"}
|
package/lib/orders-index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orders-index.js","sourceRoot":"","sources":["../src/orders-index.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAC;AAClD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,2CA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AAE,aAAa,GAAG,kBAI/E,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAgB5B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"orders-settings.js","sourceRoot":"","sources":["../src/orders-settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAsB1D,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,EAAO,EAAE,EAAE;IAClF,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,iBAAiB,EAAE,KAAK;IACxB,iBAAiB,EAAE,kBAAkB;IACrC,qBAAqB,EAAE,4BAA4B;IACnD,uBAAuB,EAAE,KAAK;IAC9B,iBAAiB,CAAC,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,GAAG,EAAE;QACJ,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,IAAI,KAAK,CAAC;QACpD,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,IAAI,kBAAkB,CAAC;QACjE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,IAAI,4BAA4B,CAAC;QACnF,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,IAAI,KAAK,CAAC;IAClE,CAAC;CACF,CAAC"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { mongodb, buildDbIndexes, LogFields, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
|
|
4
|
-
export enum OrderDeliveryStatus {
|
|
5
|
-
OPEN = 'OPEN', // Null value is mapped to OPEN status
|
|
6
|
-
DELIVERED = 'DELIVERED',
|
|
7
|
-
RETURNED = 'RETURNED',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type OrderDelivery = {
|
|
11
|
-
_id: string;
|
|
12
|
-
orderId: string;
|
|
13
|
-
deliveryProviderId: string;
|
|
14
|
-
delivered?: Date;
|
|
15
|
-
status: OrderDeliveryStatus | null;
|
|
16
|
-
context?: any;
|
|
17
|
-
calculation: any[];
|
|
18
|
-
} & LogFields &
|
|
19
|
-
TimestampFields;
|
|
20
|
-
|
|
21
|
-
export type OrderDeliveryDiscount = Omit<Price, '_id'> & {
|
|
22
|
-
_id: string;
|
|
23
|
-
discountId: string;
|
|
24
|
-
item: OrderDelivery;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const OrderDeliveriesCollection = async (db: mongodb.Db) => {
|
|
28
|
-
const OrderDeliveries = db.collection<OrderDelivery>('order_deliveries');
|
|
29
|
-
|
|
30
|
-
// Order Indexes
|
|
31
|
-
await buildDbIndexes<OrderDelivery>(OrderDeliveries, [{ index: { orderId: 1 } }]);
|
|
32
|
-
|
|
33
|
-
return OrderDeliveries;
|
|
34
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mongodb, buildDbIndexes, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
|
|
4
|
-
export type OrderDiscount = {
|
|
5
|
-
_id: string;
|
|
6
|
-
orderId: string;
|
|
7
|
-
code?: string;
|
|
8
|
-
total?: Price;
|
|
9
|
-
trigger?: OrderDiscountTrigger;
|
|
10
|
-
discountKey: string;
|
|
11
|
-
reservation?: any;
|
|
12
|
-
context?: any;
|
|
13
|
-
} & TimestampFields;
|
|
14
|
-
|
|
15
|
-
export const OrderDiscountsCollection = async (db: mongodb.Db) => {
|
|
16
|
-
const OrderDiscounts = db.collection<OrderDiscount>('order_discounts');
|
|
17
|
-
|
|
18
|
-
// Order Indexes
|
|
19
|
-
await buildDbIndexes<OrderDiscount>(OrderDiscounts, [
|
|
20
|
-
{ index: { orderId: 1 } },
|
|
21
|
-
{ index: { trigger: 1 } },
|
|
22
|
-
]);
|
|
23
|
-
|
|
24
|
-
return OrderDiscounts;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export enum OrderDiscountTrigger {
|
|
28
|
-
USER = 'USER',
|
|
29
|
-
SYSTEM = 'SYSTEM',
|
|
30
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { mongodb, buildDbIndexes, LogFields, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
|
|
4
|
-
export enum OrderPaymentStatus {
|
|
5
|
-
OPEN = 'OPEN', // Null value is mapped to OPEN status
|
|
6
|
-
PAID = 'PAID',
|
|
7
|
-
REFUNDED = 'REFUNDED',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type OrderPayment = {
|
|
11
|
-
_id: string;
|
|
12
|
-
orderId: string;
|
|
13
|
-
context?: any;
|
|
14
|
-
paid?: Date;
|
|
15
|
-
transactionId?: string;
|
|
16
|
-
paymentProviderId: string;
|
|
17
|
-
status?: OrderPaymentStatus | null;
|
|
18
|
-
calculation?: any[];
|
|
19
|
-
} & LogFields &
|
|
20
|
-
TimestampFields;
|
|
21
|
-
|
|
22
|
-
export type OrderPaymentDiscount = Omit<Price, '_id'> & {
|
|
23
|
-
_id: string;
|
|
24
|
-
discountId: string;
|
|
25
|
-
item: OrderPayment;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const OrderPaymentsCollection = async (db: mongodb.Db) => {
|
|
29
|
-
const OrderPayments = db.collection<OrderPayment>('order_payments');
|
|
30
|
-
|
|
31
|
-
// Order Indexes
|
|
32
|
-
await buildDbIndexes<OrderPayment>(OrderPayments, [{ index: { orderId: 1 } }]);
|
|
33
|
-
|
|
34
|
-
return OrderPayments;
|
|
35
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { mongodb, buildDbIndexes, TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Price } from '@unchainedshop/utils';
|
|
3
|
-
|
|
4
|
-
export type OrderPosition = {
|
|
5
|
-
_id: string;
|
|
6
|
-
calculation: any[];
|
|
7
|
-
configuration: { key: string; value: string }[] | null;
|
|
8
|
-
context?: any;
|
|
9
|
-
orderId: string;
|
|
10
|
-
originalProductId: string;
|
|
11
|
-
productId: string;
|
|
12
|
-
quantity: number;
|
|
13
|
-
quotationId?: string;
|
|
14
|
-
scheduling: any[];
|
|
15
|
-
} & TimestampFields;
|
|
16
|
-
|
|
17
|
-
export type OrderPositionDiscount = Omit<Price, '_id'> & {
|
|
18
|
-
discountId: string;
|
|
19
|
-
item: OrderPosition;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const OrderPositionsCollection = async (db: mongodb.Db) => {
|
|
23
|
-
const OrderPositions = db.collection<OrderPosition>('order_positions');
|
|
24
|
-
|
|
25
|
-
// Order Indexes
|
|
26
|
-
await buildDbIndexes<OrderPosition>(OrderPositions, [
|
|
27
|
-
{ index: { productId: 1 } },
|
|
28
|
-
{ index: { orderId: 1 } },
|
|
29
|
-
]);
|
|
30
|
-
|
|
31
|
-
return OrderPositions;
|
|
32
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
mongodb,
|
|
3
|
-
buildDbIndexes,
|
|
4
|
-
Address,
|
|
5
|
-
Contact,
|
|
6
|
-
LogFields,
|
|
7
|
-
TimestampFields,
|
|
8
|
-
isDocumentDBCompatModeEnabled,
|
|
9
|
-
} from '@unchainedshop/mongodb';
|
|
10
|
-
import { DateFilterInput } from '@unchainedshop/utils';
|
|
11
|
-
|
|
12
|
-
export enum OrderStatus {
|
|
13
|
-
PENDING = 'PENDING',
|
|
14
|
-
CONFIRMED = 'CONFIRMED',
|
|
15
|
-
FULLFILLED = 'FULLFILLED',
|
|
16
|
-
REJECTED = 'REJECTED',
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type Order = {
|
|
20
|
-
_id: string;
|
|
21
|
-
billingAddress?: Address;
|
|
22
|
-
calculation: any[];
|
|
23
|
-
confirmed?: Date;
|
|
24
|
-
rejected?: Date;
|
|
25
|
-
contact?: Contact;
|
|
26
|
-
context?: any;
|
|
27
|
-
countryCode: string;
|
|
28
|
-
currencyCode: string;
|
|
29
|
-
deliveryId?: string;
|
|
30
|
-
fullfilled?: Date;
|
|
31
|
-
ordered?: Date;
|
|
32
|
-
orderNumber?: string;
|
|
33
|
-
originEnrollmentId?: string;
|
|
34
|
-
paymentId?: string;
|
|
35
|
-
status: OrderStatus | null;
|
|
36
|
-
userId: string;
|
|
37
|
-
} & LogFields &
|
|
38
|
-
TimestampFields;
|
|
39
|
-
|
|
40
|
-
export interface OrderQuery extends mongodb.Filter<Order> {
|
|
41
|
-
includeCarts?: boolean;
|
|
42
|
-
queryString?: string;
|
|
43
|
-
status?: OrderStatus[];
|
|
44
|
-
userId?: string;
|
|
45
|
-
deliveryIds?: string[];
|
|
46
|
-
paymentIds?: string[];
|
|
47
|
-
dateRange?: DateFilterInput;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const OrdersCollection = async (db: mongodb.Db) => {
|
|
51
|
-
const Orders = db.collection<Order>('orders');
|
|
52
|
-
|
|
53
|
-
if (!isDocumentDBCompatModeEnabled()) {
|
|
54
|
-
await buildDbIndexes<Order>(Orders, [
|
|
55
|
-
{
|
|
56
|
-
index: {
|
|
57
|
-
_id: 'text',
|
|
58
|
-
userId: 'text',
|
|
59
|
-
orderNumber: 'text',
|
|
60
|
-
status: 'text',
|
|
61
|
-
'contact.emailAddress': 'text',
|
|
62
|
-
'contact.telNumber': 'text',
|
|
63
|
-
} as any,
|
|
64
|
-
options: {
|
|
65
|
-
weights: {
|
|
66
|
-
_id: 8,
|
|
67
|
-
userId: 3,
|
|
68
|
-
orderNumber: 6,
|
|
69
|
-
'contact.telNumber': 5,
|
|
70
|
-
'contact.emailAddress': 4,
|
|
71
|
-
status: 1,
|
|
72
|
-
},
|
|
73
|
-
name: 'order_fulltext_search',
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Order Indexes
|
|
80
|
-
await buildDbIndexes<Order>(Orders, [
|
|
81
|
-
{ index: { userId: 1 } },
|
|
82
|
-
{ index: { status: 1 } },
|
|
83
|
-
{ index: { orderNumber: 1 } },
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
return Orders;
|
|
87
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { MigrationRepository } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrdersCollection } from '../orders-index.js';
|
|
3
|
-
|
|
4
|
-
export default function renameCurrencyCode(repository: MigrationRepository) {
|
|
5
|
-
repository?.register({
|
|
6
|
-
id: 20250502111800,
|
|
7
|
-
name: 'Rename order.currency to order.currencyCode',
|
|
8
|
-
up: async () => {
|
|
9
|
-
const Orders = await OrdersCollection(repository.db);
|
|
10
|
-
await Orders.updateMany(
|
|
11
|
-
{},
|
|
12
|
-
{
|
|
13
|
-
$rename: { currency: 'currencyCode' },
|
|
14
|
-
},
|
|
15
|
-
);
|
|
16
|
-
},
|
|
17
|
-
});
|
|
18
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { OrderStatus } from '../db/OrdersCollection.js';
|
|
4
|
-
import { buildFindByIdSelector as buildFindByIdSelectorForDelivery } from './configureOrderDeliveriesModule.js';
|
|
5
|
-
import { buildFindOrderDiscountByIdSelector } from './configureOrderDiscountsModule.js';
|
|
6
|
-
import {
|
|
7
|
-
buildFindOrderPaymentByIdSelector,
|
|
8
|
-
buildFindByContextDataSelector,
|
|
9
|
-
} from './configureOrderPaymentsModule.js';
|
|
10
|
-
import { buildFindOrderPositionByIdSelector } from './configureOrderPositionsModule.js';
|
|
11
|
-
import buildFindSelectorForOrder from './buildFindSelector.js';
|
|
12
|
-
|
|
13
|
-
describe('OrderPosition', () => {
|
|
14
|
-
describe('buildFindSelector', () => {
|
|
15
|
-
it('Return filter object when passed no argument', () => {
|
|
16
|
-
assert.deepStrictEqual(buildFindSelectorForOrder({}), { status: { $ne: null } });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('Return filter object when passed includeCarts, queryString, status, userId and (status should take precedence over includeCarts)', () => {
|
|
20
|
-
assert.deepStrictEqual(
|
|
21
|
-
buildFindSelectorForOrder({
|
|
22
|
-
includeCarts: false,
|
|
23
|
-
queryString: 'hello world',
|
|
24
|
-
status: [OrderStatus.CONFIRMED],
|
|
25
|
-
userId: 'admin-id',
|
|
26
|
-
}),
|
|
27
|
-
{
|
|
28
|
-
userId: 'admin-id',
|
|
29
|
-
status: {
|
|
30
|
-
$in: ['CONFIRMED'],
|
|
31
|
-
},
|
|
32
|
-
$text: { $search: 'hello world' },
|
|
33
|
-
},
|
|
34
|
-
);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('Return filter object when passed includeCarts, queryString, userId', () => {
|
|
38
|
-
assert.deepStrictEqual(
|
|
39
|
-
buildFindSelectorForOrder({
|
|
40
|
-
includeCarts: true,
|
|
41
|
-
queryString: 'hello world',
|
|
42
|
-
userId: 'admin-id',
|
|
43
|
-
}),
|
|
44
|
-
{
|
|
45
|
-
userId: 'admin-id',
|
|
46
|
-
$text: { $search: 'hello world' },
|
|
47
|
-
},
|
|
48
|
-
);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('Return filter object when passed queryString, userId', () => {
|
|
52
|
-
assert.deepStrictEqual(
|
|
53
|
-
buildFindSelectorForOrder({ queryString: 'hello world', userId: 'admin-id' }),
|
|
54
|
-
{
|
|
55
|
-
userId: 'admin-id',
|
|
56
|
-
$text: { $search: 'hello world' },
|
|
57
|
-
status: { $ne: null },
|
|
58
|
-
},
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('Return filter object when passed queryString', () => {
|
|
63
|
-
assert.deepStrictEqual(buildFindSelectorForOrder({ queryString: 'hello world' }), {
|
|
64
|
-
$text: { $search: 'hello world' },
|
|
65
|
-
status: { $ne: null },
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe('OrderDelivery', () => {
|
|
72
|
-
describe('buildFindByIdSelector', () => {
|
|
73
|
-
it('Return correct db _id selector', () => {
|
|
74
|
-
assert.deepStrictEqual(buildFindByIdSelectorForDelivery('order-delivery-id'), {
|
|
75
|
-
_id: 'order-delivery-id',
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('OrderDiscount', () => {
|
|
82
|
-
describe('buildFindByIdSelector', () => {
|
|
83
|
-
it('Return correct db _id selector', () => {
|
|
84
|
-
assert.deepStrictEqual(buildFindOrderDiscountByIdSelector('order-discount-id'), {
|
|
85
|
-
_id: 'order-discount-id',
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('OrderPayment', () => {
|
|
92
|
-
describe('buildFindByIdSelector', () => {
|
|
93
|
-
it('Return correct db _id selector', () => {
|
|
94
|
-
assert.deepStrictEqual(buildFindOrderPaymentByIdSelector('order-payment-id'), {
|
|
95
|
-
_id: 'order-payment-id',
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe('buildFindByContextDataSelector', () => {
|
|
101
|
-
it('Return correct db context field selector object', () => {
|
|
102
|
-
assert.deepStrictEqual(
|
|
103
|
-
buildFindByContextDataSelector({ first: 'first value', second: 'second value' }),
|
|
104
|
-
{
|
|
105
|
-
'context.first': 'first value',
|
|
106
|
-
'context.second': 'second value',
|
|
107
|
-
},
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe('OrderPosition', () => {
|
|
114
|
-
describe('buildFindByIdSelector', () => {
|
|
115
|
-
it('Return correct db _id selector', () => {
|
|
116
|
-
assert.deepStrictEqual(buildFindOrderPositionByIdSelector('order-position-id'), {
|
|
117
|
-
_id: 'order-position-id',
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { OrderQuery, Order } from '../db/OrdersCollection.js';
|
|
2
|
-
import { assertDocumentDBCompatMode, mongodb } from '@unchainedshop/mongodb';
|
|
3
|
-
|
|
4
|
-
export const buildFindSelector = ({
|
|
5
|
-
includeCarts,
|
|
6
|
-
status,
|
|
7
|
-
userId,
|
|
8
|
-
queryString,
|
|
9
|
-
paymentIds,
|
|
10
|
-
deliveryIds,
|
|
11
|
-
dateRange,
|
|
12
|
-
...rest
|
|
13
|
-
}: OrderQuery) => {
|
|
14
|
-
const selector: mongodb.Filter<Order> = { ...rest };
|
|
15
|
-
|
|
16
|
-
if (userId) {
|
|
17
|
-
selector.userId = userId;
|
|
18
|
-
}
|
|
19
|
-
if (dateRange) {
|
|
20
|
-
const dateFilter: mongodb.Filter<Order> = {};
|
|
21
|
-
if (dateRange.start) dateFilter.$gte = new Date(dateRange.start);
|
|
22
|
-
if (dateRange.end) dateFilter.$lte = new Date(dateRange.end);
|
|
23
|
-
if (Object.keys(dateFilter).length > 0) {
|
|
24
|
-
selector.ordered = dateFilter;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (Array.isArray(deliveryIds) && deliveryIds?.length) {
|
|
29
|
-
selector.deliveryId = { $in: deliveryIds };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (Array.isArray(paymentIds) && paymentIds?.length) {
|
|
33
|
-
selector.paymentId = { $in: paymentIds };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (Array.isArray(status) && status?.length) {
|
|
37
|
-
selector.status = { $in: status };
|
|
38
|
-
} else if (!includeCarts) {
|
|
39
|
-
selector.status = { $ne: null };
|
|
40
|
-
}
|
|
41
|
-
if (queryString) {
|
|
42
|
-
assertDocumentDBCompatMode();
|
|
43
|
-
(selector as any).$text = { $search: queryString };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return selector;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export default buildFindSelector;
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
2
|
-
import { emit, registerEvents } from '@unchainedshop/events';
|
|
3
|
-
import { PricingCalculation } from '@unchainedshop/utils';
|
|
4
|
-
import { OrderDelivery, OrderDeliveryStatus } from '../db/OrderDeliveriesCollection.js';
|
|
5
|
-
|
|
6
|
-
const ORDER_DELIVERY_EVENTS: string[] = ['ORDER_DELIVER', 'ORDER_UPDATE_DELIVERY'];
|
|
7
|
-
|
|
8
|
-
export const buildFindByIdSelector = (orderDeliveryId: string) =>
|
|
9
|
-
generateDbFilterById(orderDeliveryId) as mongodb.Filter<OrderDelivery>;
|
|
10
|
-
|
|
11
|
-
export const configureOrderDeliveriesModule = ({
|
|
12
|
-
OrderDeliveries,
|
|
13
|
-
}: {
|
|
14
|
-
OrderDeliveries: mongodb.Collection<OrderDelivery>;
|
|
15
|
-
}) => {
|
|
16
|
-
registerEvents(ORDER_DELIVERY_EVENTS);
|
|
17
|
-
|
|
18
|
-
const normalizedStatus = (orderDelivery: OrderDelivery) => {
|
|
19
|
-
return orderDelivery.status === null
|
|
20
|
-
? OrderDeliveryStatus.OPEN
|
|
21
|
-
: (orderDelivery.status as OrderDeliveryStatus);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const updateStatus = async (
|
|
25
|
-
orderDeliveryId: string,
|
|
26
|
-
{ status, info }: { status: OrderDeliveryStatus; info?: string },
|
|
27
|
-
) => {
|
|
28
|
-
const date = new Date();
|
|
29
|
-
const modifier: mongodb.UpdateFilter<OrderDelivery> = {
|
|
30
|
-
$set: { status, updated: new Date() },
|
|
31
|
-
$push: {
|
|
32
|
-
log: {
|
|
33
|
-
date,
|
|
34
|
-
status,
|
|
35
|
-
info,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
if (status === OrderDeliveryStatus.DELIVERED) {
|
|
40
|
-
// eslint-disable-next-line
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
modifier.$set.delivered = date;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const selector = buildFindByIdSelector(orderDeliveryId);
|
|
46
|
-
return OrderDeliveries.findOneAndUpdate(selector, modifier, { returnDocument: 'after' });
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
// Queries
|
|
51
|
-
findDelivery: async (
|
|
52
|
-
{ orderDeliveryId }: { orderDeliveryId: string },
|
|
53
|
-
options?: mongodb.FindOptions,
|
|
54
|
-
) => {
|
|
55
|
-
return OrderDeliveries.findOne(buildFindByIdSelector(orderDeliveryId), options);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
findDeliveryByProvidersId: async (
|
|
59
|
-
{ deliveryProviderIds }: { deliveryProviderIds: string[] },
|
|
60
|
-
options?: mongodb.FindOptions,
|
|
61
|
-
): Promise<OrderDelivery[]> => {
|
|
62
|
-
if (!deliveryProviderIds?.length) return [];
|
|
63
|
-
return OrderDeliveries.find(
|
|
64
|
-
{ deliveryProviderId: { $in: deliveryProviderIds } },
|
|
65
|
-
options,
|
|
66
|
-
).toArray();
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
normalizedStatus,
|
|
70
|
-
|
|
71
|
-
// Mutations
|
|
72
|
-
|
|
73
|
-
create: async (
|
|
74
|
-
doc: Omit<OrderDelivery, '_id' | 'created'> & Pick<Partial<OrderDelivery>, '_id' | 'created'>,
|
|
75
|
-
) => {
|
|
76
|
-
const { insertedId: orderDeliveryId } = await OrderDeliveries.insertOne({
|
|
77
|
-
_id: generateDbObjectId(),
|
|
78
|
-
created: new Date(),
|
|
79
|
-
...doc,
|
|
80
|
-
context: doc.context || {},
|
|
81
|
-
status: null,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const orderDelivery = (await OrderDeliveries.findOne(
|
|
85
|
-
buildFindByIdSelector(orderDeliveryId),
|
|
86
|
-
)) as OrderDelivery;
|
|
87
|
-
return orderDelivery;
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
delete: async (orderDeliveryId: string) => {
|
|
91
|
-
const { deletedCount } = await OrderDeliveries.deleteOne({ _id: orderDeliveryId });
|
|
92
|
-
return deletedCount;
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
markAsDelivered: async (orderDelivery: OrderDelivery) => {
|
|
96
|
-
if (normalizedStatus(orderDelivery) !== OrderDeliveryStatus.OPEN) return;
|
|
97
|
-
const updatedOrderDelivery = await updateStatus(orderDelivery._id, {
|
|
98
|
-
status: OrderDeliveryStatus.DELIVERED,
|
|
99
|
-
info: 'mark delivered manually',
|
|
100
|
-
});
|
|
101
|
-
await emit('ORDER_DELIVER', { orderDelivery: updatedOrderDelivery });
|
|
102
|
-
return updatedOrderDelivery;
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
updateContext: async (orderDeliveryId: string, context: any) => {
|
|
106
|
-
const selector = buildFindByIdSelector(orderDeliveryId);
|
|
107
|
-
if (!context || Object.keys(context).length === 0) return OrderDeliveries.findOne(selector, {});
|
|
108
|
-
const contextSetters = Object.fromEntries(
|
|
109
|
-
Object.entries(context).map(([key, value]) => [`context.${key}`, value]),
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const orderDelivery = await OrderDeliveries.findOneAndUpdate(
|
|
113
|
-
selector,
|
|
114
|
-
{
|
|
115
|
-
$set: {
|
|
116
|
-
...contextSetters,
|
|
117
|
-
updated: new Date(),
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
{ returnDocument: 'after' },
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
if (!orderDelivery) return null;
|
|
124
|
-
await emit('ORDER_UPDATE_DELIVERY', {
|
|
125
|
-
orderDelivery,
|
|
126
|
-
});
|
|
127
|
-
return orderDelivery;
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
updateStatus,
|
|
131
|
-
|
|
132
|
-
updateCalculation: async <T extends PricingCalculation>(
|
|
133
|
-
orderDeliveryId: string,
|
|
134
|
-
calculation: T[],
|
|
135
|
-
) => {
|
|
136
|
-
return OrderDeliveries.findOneAndUpdate(
|
|
137
|
-
{ _id: orderDeliveryId },
|
|
138
|
-
{
|
|
139
|
-
$set: {
|
|
140
|
-
calculation,
|
|
141
|
-
updated: new Date(),
|
|
142
|
-
},
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
returnDocument: 'after',
|
|
146
|
-
},
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
|
|
150
|
-
deleteOrderDeliveries: async (orderId: string) => {
|
|
151
|
-
const { deletedCount } = await OrderDeliveries.deleteMany({ orderId });
|
|
152
|
-
return deletedCount;
|
|
153
|
-
},
|
|
154
|
-
};
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export type OrderDeliveriesModule = ReturnType<typeof configureOrderDeliveriesModule>;
|