@unchainedshop/core-orders 3.0.0-alpha2 → 3.0.0-alpha3
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/lib/db/OrderDeliveriesCollection.d.ts +1 -1
- package/lib/db/OrderDeliveriesCollection.d.ts.map +1 -1
- package/lib/db/OrderDiscountsCollection.d.ts +1 -1
- package/lib/db/OrderDiscountsCollection.d.ts.map +1 -1
- package/lib/db/OrderPaymentsCollection.d.ts +1 -1
- package/lib/db/OrderPaymentsCollection.d.ts.map +1 -1
- package/lib/db/OrderPositionsCollection.d.ts +1 -1
- package/lib/db/OrderPositionsCollection.d.ts.map +1 -1
- package/lib/db/OrdersCollection.d.ts +1 -1
- package/lib/db/OrdersCollection.d.ts.map +1 -1
- package/lib/director/OrderDiscountAdapter.d.ts +1 -1
- package/lib/director/OrderDiscountAdapter.d.ts.map +1 -1
- package/lib/director/OrderDiscountAdapter.js.map +1 -1
- package/lib/director/OrderDiscountDirector.d.ts +1 -1
- package/lib/director/OrderDiscountDirector.d.ts.map +1 -1
- package/lib/director/OrderPricingAdapter.d.ts +20 -2
- package/lib/director/OrderPricingAdapter.d.ts.map +1 -1
- package/lib/director/OrderPricingAdapter.js.map +1 -1
- package/lib/director/OrderPricingDirector.d.ts +16 -1
- package/lib/director/OrderPricingDirector.d.ts.map +1 -1
- package/lib/director/OrderPricingDirector.js.map +1 -1
- package/lib/director/OrderPricingSheet.d.ts +34 -2
- package/lib/director/OrderPricingSheet.d.ts.map +1 -1
- package/lib/director/OrderPricingSheet.js +9 -2
- package/lib/director/OrderPricingSheet.js.map +1 -1
- package/lib/module/configureOrderDeliveriesModule.d.ts +31 -1
- package/lib/module/configureOrderDeliveriesModule.d.ts.map +1 -1
- package/lib/module/configureOrderDeliveriesModule.js +15 -9
- package/lib/module/configureOrderDeliveriesModule.js.map +1 -1
- package/lib/module/configureOrderDiscountsModule.d.ts +21 -1
- package/lib/module/configureOrderDiscountsModule.d.ts.map +1 -1
- package/lib/module/configureOrderDiscountsModule.js +19 -15
- package/lib/module/configureOrderDiscountsModule.js.map +1 -1
- package/lib/module/configureOrderPaymentsModule.d.ts +45 -1
- package/lib/module/configureOrderPaymentsModule.d.ts.map +1 -1
- package/lib/module/configureOrderPaymentsModule.js +5 -8
- package/lib/module/configureOrderPaymentsModule.js.map +1 -1
- package/lib/module/configureOrderPositionsModule.d.ts +57 -1
- package/lib/module/configureOrderPositionsModule.d.ts.map +1 -1
- package/lib/module/configureOrderPositionsModule.js.map +1 -1
- package/lib/module/configureOrdersModule-mutations.d.ts +31 -5
- package/lib/module/configureOrdersModule-mutations.d.ts.map +1 -1
- package/lib/module/configureOrdersModule-mutations.js +5 -9
- package/lib/module/configureOrdersModule-mutations.js.map +1 -1
- package/lib/module/configureOrdersModule-processing.d.ts +22 -4
- package/lib/module/configureOrdersModule-processing.d.ts.map +1 -1
- package/lib/module/configureOrdersModule-processing.js +15 -20
- package/lib/module/configureOrdersModule-processing.js.map +1 -1
- package/lib/module/configureOrdersModule-queries.d.ts +23 -3
- package/lib/module/configureOrdersModule-queries.d.ts.map +1 -1
- package/lib/module/configureOrdersModule-queries.js +89 -5
- package/lib/module/configureOrdersModule-queries.js.map +1 -1
- package/lib/module/configureOrdersModule-transformations.d.ts +15 -1
- package/lib/module/configureOrdersModule-transformations.d.ts.map +1 -1
- package/lib/module/configureOrdersModule-transformations.js +4 -5
- package/lib/module/configureOrdersModule-transformations.js.map +1 -1
- package/lib/module/configureOrdersModule.d.ts +20 -2
- package/lib/module/configureOrdersModule.d.ts.map +1 -1
- package/lib/module/configureOrdersModule.js +2 -2
- package/lib/module/configureOrdersModule.js.map +1 -1
- package/lib/orders-index.d.ts +10 -12
- package/lib/orders-index.d.ts.map +1 -1
- package/lib/orders-index.js +10 -11
- package/lib/orders-index.js.map +1 -1
- package/lib/orders-settings.d.ts +18 -1
- package/lib/orders-settings.d.ts.map +1 -1
- package/lib/orders-settings.js.map +1 -1
- package/lib/service/migrateOrderCartService.d.ts +8 -1
- package/lib/service/migrateOrderCartService.d.ts.map +1 -1
- package/lib/service/migrateOrderCartService.js.map +1 -1
- package/lib/service/nextUserCartService.d.ts +9 -1
- package/lib/service/nextUserCartService.d.ts.map +1 -1
- package/lib/service/nextUserCartService.js.map +1 -1
- package/lib/service/orderServices.d.ts +6 -1
- package/lib/service/orderServices.d.ts.map +1 -1
- package/lib/service/orderServices.js.map +1 -1
- package/lib/types.d.ts +116 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +25 -0
- package/lib/types.js.map +1 -0
- package/package.json +7 -9
- package/src/db/OrderDeliveriesCollection.ts +1 -1
- package/src/db/OrderDiscountsCollection.ts +1 -1
- package/src/db/OrderPaymentsCollection.ts +1 -1
- package/src/db/OrderPositionsCollection.ts +1 -1
- package/src/db/OrdersCollection.ts +1 -1
- package/src/director/OrderDiscountAdapter.ts +1 -1
- package/src/director/OrderPricingAdapter.ts +26 -6
- package/src/director/OrderPricingDirector.ts +21 -5
- package/src/director/OrderPricingSheet.ts +25 -6
- package/src/module/buildFindSelector.test.ts +7 -2
- package/src/module/configureOrderDeliveriesModule.ts +81 -15
- package/src/module/configureOrderDiscountsModule.ts +70 -19
- package/src/module/configureOrderPaymentsModule.ts +93 -14
- package/src/module/configureOrderPositionsModule.ts +72 -1
- package/src/module/configureOrdersModule-mutations.ts +47 -14
- package/src/module/configureOrdersModule-processing.ts +53 -26
- package/src/module/configureOrdersModule-queries.ts +121 -13
- package/src/module/configureOrdersModule-transformations.ts +28 -6
- package/src/module/configureOrdersModule.ts +35 -14
- package/src/orders-index.ts +12 -16
- package/src/orders-settings.ts +20 -1
- package/src/service/migrateOrderCartService.ts +12 -1
- package/src/service/nextUserCartService.ts +13 -1
- package/src/service/orderServices.ts +7 -3
- package/src/types.ts +129 -0
- package/lib/db/OrderDeliveriesSchema.d.ts +0 -3
- package/lib/db/OrderDeliveriesSchema.d.ts.map +0 -1
- package/lib/db/OrderDeliveriesSchema.js +0 -20
- package/lib/db/OrderDeliveriesSchema.js.map +0 -1
- package/lib/db/OrderDiscountsSchema.d.ts +0 -3
- package/lib/db/OrderDiscountsSchema.d.ts.map +0 -1
- package/lib/db/OrderDiscountsSchema.js +0 -12
- package/lib/db/OrderDiscountsSchema.js.map +0 -1
- package/lib/db/OrderPaymentsSchema.d.ts +0 -3
- package/lib/db/OrderPaymentsSchema.d.ts.map +0 -1
- package/lib/db/OrderPaymentsSchema.js +0 -20
- package/lib/db/OrderPaymentsSchema.js.map +0 -1
- package/lib/db/OrderPositionsSchema.d.ts +0 -3
- package/lib/db/OrderPositionsSchema.d.ts.map +0 -1
- package/lib/db/OrderPositionsSchema.js +0 -37
- package/lib/db/OrderPositionsSchema.js.map +0 -1
- package/lib/db/OrdersSchema.d.ts +0 -3
- package/lib/db/OrdersSchema.d.ts.map +0 -1
- package/lib/db/OrdersSchema.js +0 -30
- package/lib/db/OrdersSchema.js.map +0 -1
- package/src/db/OrderDeliveriesSchema.ts +0 -24
- package/src/db/OrderDiscountsSchema.ts +0 -15
- package/src/db/OrderPaymentsSchema.ts +0 -24
- package/src/db/OrderPositionsSchema.ts +0 -41
- package/src/db/OrdersSchema.ts +0 -34
package/lib/types.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export var OrderStatus;
|
|
2
|
+
(function (OrderStatus) {
|
|
3
|
+
OrderStatus["PENDING"] = "PENDING";
|
|
4
|
+
OrderStatus["CONFIRMED"] = "CONFIRMED";
|
|
5
|
+
OrderStatus["FULLFILLED"] = "FULLFILLED";
|
|
6
|
+
OrderStatus["REJECTED"] = "REJECTED";
|
|
7
|
+
})(OrderStatus || (OrderStatus = {}));
|
|
8
|
+
export var OrderDiscountTrigger;
|
|
9
|
+
(function (OrderDiscountTrigger) {
|
|
10
|
+
OrderDiscountTrigger["USER"] = "USER";
|
|
11
|
+
OrderDiscountTrigger["SYSTEM"] = "SYSTEM";
|
|
12
|
+
})(OrderDiscountTrigger || (OrderDiscountTrigger = {}));
|
|
13
|
+
export var OrderDeliveryStatus;
|
|
14
|
+
(function (OrderDeliveryStatus) {
|
|
15
|
+
OrderDeliveryStatus["OPEN"] = "OPEN";
|
|
16
|
+
OrderDeliveryStatus["DELIVERED"] = "DELIVERED";
|
|
17
|
+
OrderDeliveryStatus["RETURNED"] = "RETURNED";
|
|
18
|
+
})(OrderDeliveryStatus || (OrderDeliveryStatus = {}));
|
|
19
|
+
export var OrderPaymentStatus;
|
|
20
|
+
(function (OrderPaymentStatus) {
|
|
21
|
+
OrderPaymentStatus["OPEN"] = "OPEN";
|
|
22
|
+
OrderPaymentStatus["PAID"] = "PAID";
|
|
23
|
+
OrderPaymentStatus["REFUNDED"] = "REFUNDED";
|
|
24
|
+
})(OrderPaymentStatus || (OrderPaymentStatus = {}));
|
|
25
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAN,IAAY,WAKX;AALD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,sCAAuB,CAAA;IACvB,wCAAyB,CAAA;IACzB,oCAAqB,CAAA;AACvB,CAAC,EALW,WAAW,KAAX,WAAW,QAKtB;AAoCD,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,yCAAiB,CAAA;AACnB,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAqBD,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC7B,oCAAa,CAAA;IACb,8CAAuB,CAAA;IACvB,4CAAqB,CAAA;AACvB,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B;AAED,MAAM,CAAN,IAAY,kBAIX;AAJD,WAAY,kBAAkB;IAC5B,mCAAa,CAAA;IACb,mCAAa,CAAA;IACb,2CAAqB,CAAA;AACvB,CAAC,EAJW,kBAAkB,KAAlB,kBAAkB,QAI7B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-orders",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-alpha3",
|
|
4
4
|
"main": "lib/orders-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/orders-index.js",
|
|
@@ -32,16 +32,14 @@
|
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@kontsedal/locco": "0.1.0",
|
|
35
|
-
"@unchainedshop/events": "^3.0.0-
|
|
36
|
-
"@unchainedshop/logger": "^3.0.0-
|
|
37
|
-
"@unchainedshop/utils": "^3.0.0-
|
|
38
|
-
"simpl-schema": "^3.4.6"
|
|
35
|
+
"@unchainedshop/events": "^3.0.0-alpha3",
|
|
36
|
+
"@unchainedshop/logger": "^3.0.0-alpha3",
|
|
37
|
+
"@unchainedshop/utils": "^3.0.0-alpha3"
|
|
39
38
|
},
|
|
40
39
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^
|
|
42
|
-
"@unchainedshop/types": "^3.0.0-alpha2",
|
|
40
|
+
"@types/node": "^22.5.5",
|
|
43
41
|
"jest": "^29.7.0",
|
|
44
|
-
"ts-jest": "^29.2.
|
|
45
|
-
"typescript": "^5.
|
|
42
|
+
"ts-jest": "^29.2.5",
|
|
43
|
+
"typescript": "^5.6.2"
|
|
46
44
|
}
|
|
47
45
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrderDelivery } from '@unchainedshop/
|
|
2
|
+
import { OrderDelivery } from '@unchainedshop/core-orders';
|
|
3
3
|
|
|
4
4
|
export const OrderDeliveriesCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const OrderDeliveries = db.collection<OrderDelivery>('order_deliveries');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrderDiscount } from '@unchainedshop/
|
|
2
|
+
import { OrderDiscount } from '@unchainedshop/core-orders';
|
|
3
3
|
|
|
4
4
|
export const OrderDiscountsCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const OrderDiscounts = db.collection<OrderDiscount>('order_discounts');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrderPayment } from '@unchainedshop/
|
|
2
|
+
import { OrderPayment } from '@unchainedshop/core-orders';
|
|
3
3
|
|
|
4
4
|
export const OrderPaymentsCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const OrderPayments = db.collection<OrderPayment>('order_payments');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { OrderPosition } from '@unchainedshop/
|
|
2
|
+
import { OrderPosition } from '@unchainedshop/core-orders';
|
|
3
3
|
|
|
4
4
|
export const OrderPositionsCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const OrderPositions = db.collection<OrderPosition>('order_positions');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Order } from '
|
|
2
|
+
import { Order } from '../types.js';
|
|
3
3
|
|
|
4
4
|
export const OrdersCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const Orders = db.collection<Order>('orders');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IDiscountAdapter } from '@unchainedshop/types/discount.js';
|
|
2
1
|
import { BaseDiscountAdapter } from '@unchainedshop/utils';
|
|
3
2
|
import { OrderDiscountConfiguration } from './OrderDiscountConfiguration.js';
|
|
3
|
+
import { IDiscountAdapter } from '@unchainedshop/utils';
|
|
4
4
|
|
|
5
5
|
export const OrderDiscountAdapter: Omit<
|
|
6
6
|
IDiscountAdapter<OrderDiscountConfiguration>,
|
|
@@ -1,11 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { BasePricingAdapter, IPricingAdapter, BasePricingAdapterContext } from '@unchainedshop/utils';
|
|
2
|
+
import { IOrderPricingSheet, OrderPricingCalculation, OrderPricingSheet } from './OrderPricingSheet.js';
|
|
3
|
+
import { Order, OrderDelivery, OrderDiscount, OrderPayment, OrderPosition } from '../types.js';
|
|
4
|
+
import { User } from '@unchainedshop/core-users';
|
|
5
|
+
|
|
6
|
+
export interface OrderPricingAdapterContext extends BasePricingAdapterContext {
|
|
7
|
+
currency?: string;
|
|
8
|
+
discounts: Array<OrderDiscount>;
|
|
9
|
+
order: Order;
|
|
10
|
+
orderDelivery: OrderDelivery;
|
|
11
|
+
orderPositions: Array<OrderPosition>;
|
|
12
|
+
orderPayment: OrderPayment;
|
|
13
|
+
user: User;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface OrderPricingContext {
|
|
17
|
+
order: Order;
|
|
18
|
+
orderDelivery: OrderDelivery;
|
|
19
|
+
orderPositions: Array<OrderPosition>;
|
|
20
|
+
orderPayment: OrderPayment;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type IOrderPricingAdapter<DiscountConfiguration = unknown> = IPricingAdapter<
|
|
3
24
|
OrderPricingAdapterContext,
|
|
4
25
|
OrderPricingCalculation,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { OrderPricingSheet } from './OrderPricingSheet.js';
|
|
26
|
+
IOrderPricingSheet,
|
|
27
|
+
DiscountConfiguration
|
|
28
|
+
>;
|
|
9
29
|
|
|
10
30
|
const basePricingAdapter = BasePricingAdapter<OrderPricingAdapterContext, OrderPricingCalculation>();
|
|
11
31
|
|
|
@@ -1,12 +1,28 @@
|
|
|
1
|
+
import { BasePricingDirector, PricingDiscount, IPricingDirector } from '@unchainedshop/utils';
|
|
2
|
+
import { IOrderPricingSheet, OrderPricingCalculation, OrderPricingSheet } from './OrderPricingSheet.js';
|
|
3
|
+
import { Order, OrderDelivery, OrderPayment, OrderPosition } from '../types.js';
|
|
1
4
|
import {
|
|
2
5
|
IOrderPricingAdapter,
|
|
3
|
-
IOrderPricingDirector,
|
|
4
6
|
OrderPricingAdapterContext,
|
|
5
|
-
OrderPricingCalculation,
|
|
6
7
|
OrderPricingContext,
|
|
7
|
-
} from '
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
} from './OrderPricingAdapter.js';
|
|
9
|
+
|
|
10
|
+
export type OrderPrice = { _id?: string; amount: number; currency: string };
|
|
11
|
+
|
|
12
|
+
export type OrderPricingDiscount = PricingDiscount & {
|
|
13
|
+
delivery?: OrderDelivery;
|
|
14
|
+
item?: OrderPosition;
|
|
15
|
+
order?: Order;
|
|
16
|
+
payment?: OrderPayment;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type IOrderPricingDirector<DiscountConfiguration = unknown> = IPricingDirector<
|
|
20
|
+
OrderPricingContext,
|
|
21
|
+
OrderPricingCalculation,
|
|
22
|
+
OrderPricingAdapterContext,
|
|
23
|
+
IOrderPricingSheet,
|
|
24
|
+
IOrderPricingAdapter<DiscountConfiguration>
|
|
25
|
+
>;
|
|
10
26
|
|
|
11
27
|
const baseDirector = BasePricingDirector<
|
|
12
28
|
OrderPricingContext,
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { BasePricingSheet } from '@unchainedshop/utils';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
BasePricingSheet,
|
|
3
|
+
IPricingSheet,
|
|
4
|
+
IBasePricingSheet,
|
|
5
|
+
PricingCalculation,
|
|
6
|
+
PricingSheetParams,
|
|
7
|
+
} from '@unchainedshop/utils';
|
|
8
|
+
|
|
9
|
+
export interface OrderPricingCalculation extends PricingCalculation {
|
|
10
|
+
discountId?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export enum OrderPricingRowCategory {
|
|
14
|
+
Items = 'ITEMS',
|
|
15
|
+
Discounts = 'DISCOUNTS',
|
|
16
|
+
Taxes = 'TAXES',
|
|
17
|
+
Delivery = 'DELIVERY',
|
|
18
|
+
Payment = 'PAYMENT',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IOrderPricingSheet extends IPricingSheet<OrderPricingCalculation> {
|
|
22
|
+
addDelivery: (params: { amount: number; taxAmount: number; meta?: any }) => void;
|
|
23
|
+
addDiscount: (params: { amount: number; taxAmount: number; discountId: string; meta?: any }) => void;
|
|
24
|
+
addItems: (params: { amount: number; taxAmount: number; meta?: any }) => void;
|
|
25
|
+
addPayment: (params: { amount: number; taxAmount: number; meta?: any }) => void;
|
|
26
|
+
}
|
|
8
27
|
|
|
9
28
|
export const OrderPricingSheet = (
|
|
10
29
|
params: PricingSheetParams<OrderPricingCalculation>,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OrderStatus } from "../types.js"
|
|
1
2
|
import {buildFindByIdSelector as buildFindByIdSelectorForDelivery} from "./configureOrderDeliveriesModule.js"
|
|
2
3
|
import {buildFindByIdSelector as buildFindByIdSelectorForDiscount } from "./configureOrderDiscountsModule.js"
|
|
3
4
|
import {buildFindByIdSelector as buildFindByIdSelectorForPayment, buildFindByContextDataSelector } from "./configureOrderPaymentsModule.js"
|
|
@@ -13,9 +14,13 @@ describe('OrderPosition', () => {
|
|
|
13
14
|
});
|
|
14
15
|
|
|
15
16
|
it('Return filter object when passed no argument includeCarts, queryString, status, userId and (status should take precedence over includeCarts', async () => {
|
|
16
|
-
expect(buildFindSelectorForOrder({includeCarts: false, queryString: "hello world", status:
|
|
17
|
+
expect(buildFindSelectorForOrder({includeCarts: false, queryString: "hello world", status: [OrderStatus.CONFIRMED], userId: "admin-id"})).toEqual({
|
|
17
18
|
userId: 'admin-id',
|
|
18
|
-
status:
|
|
19
|
+
"status": {
|
|
20
|
+
"$in": [
|
|
21
|
+
"CONFIRMED",
|
|
22
|
+
],
|
|
23
|
+
},
|
|
19
24
|
'$text': { '$search': 'hello world' }
|
|
20
25
|
}
|
|
21
26
|
)
|
|
@@ -1,12 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { mongodb, generateDbFilterById,
|
|
3
|
-
import {
|
|
4
|
-
OrderDeliveriesModule,
|
|
5
|
-
OrderDelivery,
|
|
6
|
-
OrderDeliveryStatus,
|
|
7
|
-
} from '@unchainedshop/types/orders.deliveries.js';
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
2
|
+
import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
8
3
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
9
|
-
import {
|
|
4
|
+
import { Order, OrderDelivery, OrderDeliveryStatus, OrderDiscount } from '../types.js';
|
|
5
|
+
import { DeliveryLocation, IDeliveryPricingSheet } from '@unchainedshop/core-delivery';
|
|
6
|
+
import { DeliveryDirector } from '@unchainedshop/core-delivery';
|
|
7
|
+
import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';
|
|
8
|
+
|
|
9
|
+
export type OrderDeliveriesModule = {
|
|
10
|
+
// Queries
|
|
11
|
+
findDelivery: (
|
|
12
|
+
params: { orderDeliveryId: string },
|
|
13
|
+
options?: mongodb.FindOptions,
|
|
14
|
+
) => Promise<OrderDelivery>;
|
|
15
|
+
|
|
16
|
+
// Transformations
|
|
17
|
+
discounts: (
|
|
18
|
+
orderDelivery: OrderDelivery,
|
|
19
|
+
params: { order: Order; orderDiscount: OrderDiscount },
|
|
20
|
+
unchainedAPI: UnchainedCore,
|
|
21
|
+
) => Array<OrderPricingDiscount>;
|
|
22
|
+
isBlockingOrderConfirmation: (
|
|
23
|
+
orderDelivery: OrderDelivery,
|
|
24
|
+
unchainedAPI: UnchainedCore,
|
|
25
|
+
) => Promise<boolean>;
|
|
26
|
+
isBlockingOrderFullfillment: (orderDelivery: OrderDelivery) => boolean;
|
|
27
|
+
normalizedStatus: (orderDelivery: OrderDelivery) => string;
|
|
28
|
+
pricingSheet: (
|
|
29
|
+
orderDelivery: OrderDelivery,
|
|
30
|
+
currency: string,
|
|
31
|
+
unchainedAPI: UnchainedCore,
|
|
32
|
+
) => IDeliveryPricingSheet;
|
|
33
|
+
|
|
34
|
+
// Mutations
|
|
35
|
+
create: (doc: OrderDelivery) => Promise<OrderDelivery>;
|
|
36
|
+
delete: (orderDeliveryId: string) => Promise<number>;
|
|
37
|
+
|
|
38
|
+
markAsDelivered: (orderDelivery: OrderDelivery) => Promise<void>;
|
|
39
|
+
|
|
40
|
+
activePickUpLocation: (
|
|
41
|
+
orderDelivery: OrderDelivery,
|
|
42
|
+
unchainedAPI: UnchainedCore,
|
|
43
|
+
) => Promise<DeliveryLocation | null>;
|
|
44
|
+
|
|
45
|
+
send: (
|
|
46
|
+
orderDelivery: OrderDelivery,
|
|
47
|
+
params: { order: Order; deliveryContext?: any },
|
|
48
|
+
unchainedAPI: UnchainedCore,
|
|
49
|
+
) => Promise<OrderDelivery>;
|
|
50
|
+
|
|
51
|
+
updateContext: (orderDeliveryId: string, context: any) => Promise<OrderDelivery | null>;
|
|
52
|
+
|
|
53
|
+
updateStatus: (
|
|
54
|
+
orderDeliveryId: string,
|
|
55
|
+
params: { status: OrderDeliveryStatus; info?: string },
|
|
56
|
+
) => Promise<OrderDelivery>;
|
|
57
|
+
|
|
58
|
+
updateCalculation: (
|
|
59
|
+
orderDelivery: OrderDelivery,
|
|
60
|
+
unchainedAPI: UnchainedCore,
|
|
61
|
+
) => Promise<OrderDelivery>;
|
|
62
|
+
};
|
|
10
63
|
|
|
11
64
|
const ORDER_DELIVERY_EVENTS: string[] = ['ORDER_DELIVER', 'ORDER_UPDATE_DELIVERY'];
|
|
12
65
|
|
|
@@ -20,11 +73,6 @@ export const configureOrderDeliveriesModule = ({
|
|
|
20
73
|
}): OrderDeliveriesModule => {
|
|
21
74
|
registerEvents(ORDER_DELIVERY_EVENTS);
|
|
22
75
|
|
|
23
|
-
const mutations = generateDbMutations<OrderDelivery>(OrderDeliveries, OrderDeliveriesSchema, {
|
|
24
|
-
permanentlyDeleteByDefault: true,
|
|
25
|
-
hasCreateOnly: false,
|
|
26
|
-
}) as ModuleMutations<OrderDelivery>;
|
|
27
|
-
|
|
28
76
|
const normalizedStatus: OrderDeliveriesModule['normalizedStatus'] = (orderDelivery) => {
|
|
29
77
|
return orderDelivery.status === null
|
|
30
78
|
? OrderDeliveryStatus.OPEN
|
|
@@ -91,6 +139,22 @@ export const configureOrderDeliveriesModule = ({
|
|
|
91
139
|
|
|
92
140
|
return !isAutoReleaseAllowed;
|
|
93
141
|
},
|
|
142
|
+
|
|
143
|
+
activePickUpLocation: async (orderDelivery, unchainedAPI) => {
|
|
144
|
+
const { orderPickUpLocationId } = orderDelivery.context || {};
|
|
145
|
+
|
|
146
|
+
const provider = await unchainedAPI.modules.delivery.findProvider({
|
|
147
|
+
deliveryProviderId: orderDelivery.deliveryProviderId,
|
|
148
|
+
});
|
|
149
|
+
const director = await DeliveryDirector.actions(
|
|
150
|
+
provider,
|
|
151
|
+
{ orderDelivery: orderDelivery },
|
|
152
|
+
unchainedAPI,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
return director.pickUpLocationById(orderPickUpLocationId);
|
|
156
|
+
},
|
|
157
|
+
|
|
94
158
|
isBlockingOrderFullfillment: (orderDelivery) => {
|
|
95
159
|
if (orderDelivery.status === OrderDeliveryStatus.DELIVERED) return false;
|
|
96
160
|
return true;
|
|
@@ -108,7 +172,9 @@ export const configureOrderDeliveriesModule = ({
|
|
|
108
172
|
// Mutations
|
|
109
173
|
|
|
110
174
|
create: async (doc) => {
|
|
111
|
-
const orderDeliveryId = await
|
|
175
|
+
const { insertedId: orderDeliveryId } = await OrderDeliveries.insertOne({
|
|
176
|
+
_id: generateDbObjectId(),
|
|
177
|
+
created: new Date(),
|
|
112
178
|
...doc,
|
|
113
179
|
context: doc.context || {},
|
|
114
180
|
status: null,
|
|
@@ -119,7 +185,7 @@ export const configureOrderDeliveriesModule = ({
|
|
|
119
185
|
},
|
|
120
186
|
|
|
121
187
|
delete: async (orderDeliveryId) => {
|
|
122
|
-
const deletedCount = await
|
|
188
|
+
const { deletedCount } = await OrderDeliveries.deleteOne({ _id: orderDeliveryId });
|
|
123
189
|
return deletedCount;
|
|
124
190
|
},
|
|
125
191
|
|
|
@@ -1,10 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OrderDiscount, OrderDiscountsModule } from '@unchainedshop/types/orders.discounts.js';
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
3
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
4
|
-
import { generateDbFilterById,
|
|
5
|
-
import { OrderDiscountsSchema } from '../db/OrderDiscountsSchema.js';
|
|
3
|
+
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
|
|
6
4
|
import { OrderDiscountTrigger } from '../db/OrderDiscountTrigger.js';
|
|
7
5
|
import { OrderDiscountDirector } from '../director/OrderDiscountDirector.js';
|
|
6
|
+
import { Order, OrderDiscount } from '../types.js';
|
|
7
|
+
import {
|
|
8
|
+
IPricingSheet,
|
|
9
|
+
PricingCalculation,
|
|
10
|
+
DiscountAdapterActions,
|
|
11
|
+
DiscountContext,
|
|
12
|
+
} from '@unchainedshop/utils';
|
|
13
|
+
|
|
14
|
+
export type OrderDiscountsModule = {
|
|
15
|
+
// Queries
|
|
16
|
+
findOrderDiscount: (
|
|
17
|
+
params: { discountId: string },
|
|
18
|
+
options?: mongodb.FindOptions,
|
|
19
|
+
) => Promise<OrderDiscount>;
|
|
20
|
+
findOrderDiscounts: (params: { orderId: string }) => Promise<Array<OrderDiscount>>;
|
|
21
|
+
|
|
22
|
+
// Transformations
|
|
23
|
+
interface: (
|
|
24
|
+
orderDiscount: OrderDiscount,
|
|
25
|
+
unchainedAPI: UnchainedCore,
|
|
26
|
+
) => Promise<DiscountAdapterActions<any>>;
|
|
27
|
+
|
|
28
|
+
isValid: (orderDiscount: OrderDiscount, unchainedAPI: UnchainedCore) => Promise<boolean>;
|
|
29
|
+
|
|
30
|
+
// Adapter
|
|
31
|
+
configurationForPricingAdapterKey: (
|
|
32
|
+
orderDiscount: OrderDiscount,
|
|
33
|
+
adapterKey: string,
|
|
34
|
+
calculationSheet: IPricingSheet<PricingCalculation>,
|
|
35
|
+
pricingContext: DiscountContext & UnchainedCore,
|
|
36
|
+
) => Promise<any>;
|
|
37
|
+
|
|
38
|
+
// Mutations
|
|
39
|
+
createManualOrderDiscount: (
|
|
40
|
+
params: { code: string; order: Order },
|
|
41
|
+
unchainedAPI: UnchainedCore,
|
|
42
|
+
) => Promise<OrderDiscount>;
|
|
43
|
+
|
|
44
|
+
create: (doc: OrderDiscount) => Promise<OrderDiscount>;
|
|
45
|
+
update: (orderDiscountId: string, doc: OrderDiscount) => Promise<OrderDiscount>;
|
|
46
|
+
delete: (orderDiscountId: string, unchainedAPI: UnchainedCore) => Promise<OrderDiscount>;
|
|
47
|
+
};
|
|
8
48
|
|
|
9
49
|
const ORDER_DISCOUNT_EVENTS: string[] = [
|
|
10
50
|
'ORDER_CREATE_DISCOUNT',
|
|
@@ -28,11 +68,6 @@ export const configureOrderDiscountsModule = ({
|
|
|
28
68
|
}): OrderDiscountsModule => {
|
|
29
69
|
registerEvents(ORDER_DISCOUNT_EVENTS);
|
|
30
70
|
|
|
31
|
-
const mutations = generateDbMutations<OrderDiscount>(OrderDiscounts, OrderDiscountsSchema, {
|
|
32
|
-
permanentlyDeleteByDefault: true,
|
|
33
|
-
hasCreateOnly: false,
|
|
34
|
-
}) as ModuleMutations<OrderDiscount>;
|
|
35
|
-
|
|
36
71
|
const getAdapter = async (orderDiscount: OrderDiscount, unchainedAPI: UnchainedCore) => {
|
|
37
72
|
const order = await unchainedAPI.modules.orders.findOrder({
|
|
38
73
|
orderId: orderDiscount.orderId,
|
|
@@ -47,7 +82,12 @@ export const configureOrderDiscountsModule = ({
|
|
|
47
82
|
|
|
48
83
|
const createDiscount: OrderDiscountsModule['create'] = async (doc) => {
|
|
49
84
|
const normalizedTrigger = doc.trigger || OrderDiscountTrigger.USER;
|
|
50
|
-
const discountId = await
|
|
85
|
+
const { insertedId: discountId } = await OrderDiscounts.insertOne({
|
|
86
|
+
_id: generateDbObjectId(),
|
|
87
|
+
created: new Date(),
|
|
88
|
+
...doc,
|
|
89
|
+
trigger: normalizedTrigger,
|
|
90
|
+
});
|
|
51
91
|
const discount = await OrderDiscounts.findOne(buildFindByIdSelector(discountId));
|
|
52
92
|
return discount;
|
|
53
93
|
};
|
|
@@ -67,12 +107,16 @@ export const configureOrderDiscountsModule = ({
|
|
|
67
107
|
};
|
|
68
108
|
|
|
69
109
|
const updateDiscount: OrderDiscountsModule['update'] = async (orderDiscountId, doc) => {
|
|
70
|
-
await
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
110
|
+
const discount = await OrderDiscounts.findOneAndUpdate(
|
|
111
|
+
generateDbFilterById(orderDiscountId),
|
|
112
|
+
{
|
|
113
|
+
$set: {
|
|
114
|
+
updated: new Date(),
|
|
115
|
+
...doc,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{ returnDocument: 'after' },
|
|
119
|
+
);
|
|
76
120
|
await emit('ORDER_UPDATE_DISCOUNT', { discount });
|
|
77
121
|
return discount;
|
|
78
122
|
};
|
|
@@ -200,10 +244,17 @@ export const configureOrderDiscountsModule = ({
|
|
|
200
244
|
delete: deleteDiscount,
|
|
201
245
|
|
|
202
246
|
update: async (orderDiscountId, doc) => {
|
|
203
|
-
await
|
|
247
|
+
const discount = await OrderDiscounts.findOneAndUpdate(
|
|
248
|
+
generateDbFilterById(orderDiscountId),
|
|
249
|
+
{
|
|
250
|
+
$set: {
|
|
251
|
+
updated: new Date(),
|
|
252
|
+
...doc,
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
{ returnDocument: 'after' },
|
|
256
|
+
);
|
|
204
257
|
|
|
205
|
-
const selector = buildFindByIdSelector(orderDiscountId);
|
|
206
|
-
const discount = await OrderDiscounts.findOne(selector, {});
|
|
207
258
|
await emit('ORDER_UPDATE_DISCOUNT', { discount });
|
|
208
259
|
return discount;
|
|
209
260
|
},
|
|
@@ -1,12 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
OrderPayment,
|
|
4
|
-
OrderPaymentsModule,
|
|
5
|
-
OrderPaymentStatus,
|
|
6
|
-
} from '@unchainedshop/types/orders.payments.js';
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/core';
|
|
7
2
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
8
|
-
import { generateDbFilterById,
|
|
9
|
-
import {
|
|
3
|
+
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
|
|
4
|
+
import { Order, OrderDiscount, OrderPayment, OrderPaymentStatus } from '../types.js';
|
|
5
|
+
import { IPaymentPricingSheet } from '@unchainedshop/core-payment';
|
|
6
|
+
import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';
|
|
7
|
+
|
|
8
|
+
export type OrderPaymentsModule = {
|
|
9
|
+
// Queries
|
|
10
|
+
findOrderPayment: (
|
|
11
|
+
params: {
|
|
12
|
+
orderPaymentId: string;
|
|
13
|
+
},
|
|
14
|
+
options?: mongodb.FindOptions,
|
|
15
|
+
) => Promise<OrderPayment>;
|
|
16
|
+
|
|
17
|
+
findOrderPaymentByContextData: (
|
|
18
|
+
params: {
|
|
19
|
+
context: any;
|
|
20
|
+
},
|
|
21
|
+
options?: mongodb.FindOptions,
|
|
22
|
+
) => Promise<OrderPayment>;
|
|
23
|
+
|
|
24
|
+
countOrderPaymentsByContextData: (
|
|
25
|
+
params: {
|
|
26
|
+
context: any;
|
|
27
|
+
},
|
|
28
|
+
options?: mongodb.FindOptions,
|
|
29
|
+
) => Promise<number>;
|
|
30
|
+
|
|
31
|
+
// Transformations
|
|
32
|
+
discounts: (
|
|
33
|
+
orderPayment: OrderPayment,
|
|
34
|
+
params: { order: Order; orderDiscount: OrderDiscount },
|
|
35
|
+
unchainedAPI: UnchainedCore,
|
|
36
|
+
) => Array<OrderPricingDiscount>;
|
|
37
|
+
isBlockingOrderConfirmation: (
|
|
38
|
+
orderPayment: OrderPayment,
|
|
39
|
+
unchainedAPI: UnchainedCore,
|
|
40
|
+
) => Promise<boolean>;
|
|
41
|
+
isBlockingOrderFullfillment: (orderPayment: OrderPayment) => boolean;
|
|
42
|
+
normalizedStatus: (orderPayment: OrderPayment) => string;
|
|
43
|
+
pricingSheet: (
|
|
44
|
+
orderPayment: OrderPayment,
|
|
45
|
+
currency: string,
|
|
46
|
+
unchainedAPI: UnchainedCore,
|
|
47
|
+
) => IPaymentPricingSheet;
|
|
48
|
+
|
|
49
|
+
// Mutations
|
|
50
|
+
create: (doc: OrderPayment) => Promise<OrderPayment>;
|
|
51
|
+
|
|
52
|
+
cancel: (
|
|
53
|
+
orderPayment: OrderPayment,
|
|
54
|
+
paymentContext: {
|
|
55
|
+
transactionContext: any;
|
|
56
|
+
userId: string;
|
|
57
|
+
},
|
|
58
|
+
unchainedAPI: UnchainedCore,
|
|
59
|
+
) => Promise<OrderPayment>;
|
|
60
|
+
|
|
61
|
+
confirm: (
|
|
62
|
+
orderPayment: OrderPayment,
|
|
63
|
+
paymentContext: {
|
|
64
|
+
transactionContext: any;
|
|
65
|
+
userId: string;
|
|
66
|
+
},
|
|
67
|
+
unchainedAPI: UnchainedCore,
|
|
68
|
+
) => Promise<OrderPayment>;
|
|
69
|
+
|
|
70
|
+
charge: (
|
|
71
|
+
orderPayment: OrderPayment,
|
|
72
|
+
paymentContext: {
|
|
73
|
+
transactionContext: any;
|
|
74
|
+
userId: string;
|
|
75
|
+
},
|
|
76
|
+
unchainedAPI: UnchainedCore,
|
|
77
|
+
) => Promise<OrderPayment>;
|
|
78
|
+
|
|
79
|
+
logEvent: (orderPaymentId: string, event: any) => Promise<boolean>;
|
|
80
|
+
|
|
81
|
+
markAsPaid: (payment: OrderPayment, meta: any) => Promise<void>;
|
|
82
|
+
|
|
83
|
+
updateContext: (orderPaymentId: string, context: any) => Promise<OrderPayment | null>;
|
|
84
|
+
|
|
85
|
+
updateStatus: (
|
|
86
|
+
orderPaymentId: string,
|
|
87
|
+
params: { transactionId?: string; status: OrderPaymentStatus; info?: string },
|
|
88
|
+
) => Promise<OrderPayment>;
|
|
89
|
+
|
|
90
|
+
updateCalculation: (orderPayment: OrderPayment, unchainedAPI: UnchainedCore) => Promise<OrderPayment>;
|
|
91
|
+
};
|
|
10
92
|
|
|
11
93
|
const ORDER_PAYMENT_EVENTS: string[] = ['ORDER_UPDATE_PAYMENT', 'ORDER_SIGN_PAYMENT', 'ORDER_PAY'];
|
|
12
94
|
|
|
@@ -38,11 +120,6 @@ export const configureOrderPaymentsModule = ({
|
|
|
38
120
|
}): OrderPaymentsModule => {
|
|
39
121
|
registerEvents(ORDER_PAYMENT_EVENTS);
|
|
40
122
|
|
|
41
|
-
const mutations = generateDbMutations<OrderPayment>(OrderPayments, OrderPaymentsSchema, {
|
|
42
|
-
permanentlyDeleteByDefault: true,
|
|
43
|
-
hasCreateOnly: false,
|
|
44
|
-
}) as ModuleMutations<OrderPayment>;
|
|
45
|
-
|
|
46
123
|
const normalizedStatus: OrderPaymentsModule['normalizedStatus'] = (orderPayment) => {
|
|
47
124
|
return orderPayment.status === null
|
|
48
125
|
? OrderPaymentStatus.OPEN
|
|
@@ -149,7 +226,9 @@ export const configureOrderPaymentsModule = ({
|
|
|
149
226
|
// Mutations
|
|
150
227
|
|
|
151
228
|
create: async (doc) => {
|
|
152
|
-
const orderPaymentId = await
|
|
229
|
+
const { insertedId: orderPaymentId } = await OrderPayments.insertOne({
|
|
230
|
+
_id: generateDbObjectId(),
|
|
231
|
+
created: new Date(),
|
|
153
232
|
...doc,
|
|
154
233
|
status: null,
|
|
155
234
|
context: doc.context || {},
|