@unchainedshop/core-orders 2.13.2 → 2.14.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureOrdersModule-queries.d.ts","sourceRoot":"","sources":["../../src/module/configureOrdersModule-queries.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"configureOrdersModule-queries.d.ts","sourceRoot":"","sources":["../../src/module/configureOrdersModule-queries.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EACL,YAAY,EACZ,UAAU,EAGX,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAA0C,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEzF,eAAO,MAAM,iBAAiB,kDAAmD,UAAU,0BAkB1F,CAAC;AAiBF,eAAO,MAAM,4BAA4B,gBAEtC;IACD,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CACnC,KAAG,YA+GH,CAAC"}
|
|
@@ -16,6 +16,19 @@ export const buildFindSelector = ({ includeCarts, status, userId, queryString })
|
|
|
16
16
|
}
|
|
17
17
|
return selector;
|
|
18
18
|
};
|
|
19
|
+
const normalizeOrderAggregateResult = (data = {}) => {
|
|
20
|
+
const statusToFieldMap = {
|
|
21
|
+
newCount: 0,
|
|
22
|
+
checkoutCount: 0,
|
|
23
|
+
rejectCount: 0,
|
|
24
|
+
confirmCount: 0,
|
|
25
|
+
fulfillCount: 0,
|
|
26
|
+
};
|
|
27
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
28
|
+
statusToFieldMap[key] = value;
|
|
29
|
+
});
|
|
30
|
+
return statusToFieldMap;
|
|
31
|
+
};
|
|
19
32
|
export const configureOrdersModuleQueries = ({ Orders, }) => {
|
|
20
33
|
return {
|
|
21
34
|
count: async (query) => {
|
|
@@ -43,6 +56,76 @@ export const configureOrdersModuleQueries = ({ Orders, }) => {
|
|
|
43
56
|
}
|
|
44
57
|
return Orders.find(selector, findOptions).toArray();
|
|
45
58
|
},
|
|
59
|
+
getReport: async ({ from, to } = { from: null, to: null }) => {
|
|
60
|
+
const selector = { $exists: true };
|
|
61
|
+
if (from || to) {
|
|
62
|
+
if (from) {
|
|
63
|
+
const fromDate = new Date(from);
|
|
64
|
+
selector.$gte = fromDate;
|
|
65
|
+
}
|
|
66
|
+
if (to) {
|
|
67
|
+
const toDate = new Date(to);
|
|
68
|
+
selector.$lte = toDate;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const pipeline = [
|
|
72
|
+
{
|
|
73
|
+
$facet: {
|
|
74
|
+
checkoutCount: [
|
|
75
|
+
{
|
|
76
|
+
$match: {
|
|
77
|
+
ordered: selector,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{ $count: 'count' },
|
|
81
|
+
],
|
|
82
|
+
fulfillCount: [
|
|
83
|
+
{
|
|
84
|
+
$match: {
|
|
85
|
+
fullfilled: selector,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{ $count: 'count' },
|
|
89
|
+
],
|
|
90
|
+
rejectCount: [
|
|
91
|
+
{
|
|
92
|
+
$match: {
|
|
93
|
+
rejected: selector,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
{ $count: 'count' },
|
|
97
|
+
],
|
|
98
|
+
newCount: [
|
|
99
|
+
{
|
|
100
|
+
$match: {
|
|
101
|
+
created: selector,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{ $count: 'count' },
|
|
105
|
+
],
|
|
106
|
+
confirmCount: [
|
|
107
|
+
{
|
|
108
|
+
$match: {
|
|
109
|
+
confirmed: selector,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{ $count: 'count' },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
$project: {
|
|
118
|
+
checkoutCount: { $arrayElemAt: ['$checkoutCount.count', 0] },
|
|
119
|
+
fulfillCount: { $arrayElemAt: ['$fulfillCount.count', 0] },
|
|
120
|
+
rejectCount: { $arrayElemAt: ['$rejectCount.count', 0] },
|
|
121
|
+
newCount: { $arrayElemAt: ['$newCount.count', 0] },
|
|
122
|
+
confirmCount: { $arrayElemAt: ['$confirmCount.count', 0] },
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
const [facetedResult] = await Orders.aggregate(pipeline).toArray();
|
|
127
|
+
return normalizeOrderAggregateResult(facetedResult);
|
|
128
|
+
},
|
|
46
129
|
orderExists: async ({ orderId }) => {
|
|
47
130
|
const orderCount = await Orders.countDocuments(generateDbFilterById(orderId), {
|
|
48
131
|
limit: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureOrdersModule-queries.js","sourceRoot":"","sources":["../../src/module/configureOrdersModule-queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"configureOrdersModule-queries.js","sourceRoot":"","sources":["../../src/module/configureOrdersModule-queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;AAQxE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAW,MAAM,wBAAwB,CAAC;AAEzF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAc,EAAE,EAAE;IAC7F,MAAM,QAAQ,GAA0B,EAAE,CAAC;IAE3C,IAAI,MAAM,EAAE,CAAC;QACX,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC;IAC3B,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACX,QAAQ,CAAC,MAAM,GAAG,MAAqB,CAAC;IAC1C,CAAC;SAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QACzB,QAAQ,CAAC,MAAM,GAAG,EAAE,GAAG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3D;iBACF;aACF,CAAC;YACF,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE,CAAC;YACnE,OAAO,6BAA6B,CAAC,aAAa,CAAC,CAAC;QACtD,CAAC;QAED,WAAW,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;YACjC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE;gBAC5E,KAAK,EAAE,CAAC;aACT,CAAC,CAAC;YACH,OAAO,CAAC,CAAC,UAAU,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-orders",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"main": "lib/orders-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/orders-index.js",
|
|
@@ -32,16 +32,16 @@
|
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@kontsedal/locco": "0.1.0",
|
|
35
|
-
"@unchainedshop/events": "^2.
|
|
36
|
-
"@unchainedshop/logger": "^2.
|
|
37
|
-
"@unchainedshop/utils": "^2.
|
|
35
|
+
"@unchainedshop/events": "^2.14.0",
|
|
36
|
+
"@unchainedshop/logger": "^2.14.0",
|
|
37
|
+
"@unchainedshop/utils": "^2.14.0",
|
|
38
38
|
"simpl-schema": "^3.4.6"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^20.
|
|
42
|
-
"@unchainedshop/types": "^2.
|
|
41
|
+
"@types/node": "^20.16.4",
|
|
42
|
+
"@unchainedshop/types": "^2.14.0",
|
|
43
43
|
"jest": "^29.7.0",
|
|
44
|
-
"ts-jest": "^29.2.
|
|
44
|
+
"ts-jest": "^29.2.5",
|
|
45
45
|
"typescript": "^5.5.4"
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { SortDirection, SortOption } from '@unchainedshop/types/api.js';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Order,
|
|
4
|
+
OrderQueries,
|
|
5
|
+
OrderQuery,
|
|
6
|
+
OrderReport,
|
|
7
|
+
OrderStatus,
|
|
8
|
+
} from '@unchainedshop/types/orders.js';
|
|
3
9
|
import { generateDbFilterById, buildSortOptions, mongodb } from '@unchainedshop/mongodb';
|
|
4
10
|
|
|
5
11
|
export const buildFindSelector = ({ includeCarts, status, userId, queryString }: OrderQuery) => {
|
|
@@ -22,6 +28,21 @@ export const buildFindSelector = ({ includeCarts, status, userId, queryString }:
|
|
|
22
28
|
return selector;
|
|
23
29
|
};
|
|
24
30
|
|
|
31
|
+
const normalizeOrderAggregateResult = (data = {}): OrderReport => {
|
|
32
|
+
const statusToFieldMap = {
|
|
33
|
+
newCount: 0,
|
|
34
|
+
checkoutCount: 0,
|
|
35
|
+
rejectCount: 0,
|
|
36
|
+
confirmCount: 0,
|
|
37
|
+
fulfillCount: 0,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
41
|
+
statusToFieldMap[key] = value;
|
|
42
|
+
});
|
|
43
|
+
return statusToFieldMap;
|
|
44
|
+
};
|
|
45
|
+
|
|
25
46
|
export const configureOrdersModuleQueries = ({
|
|
26
47
|
Orders,
|
|
27
48
|
}: {
|
|
@@ -58,6 +79,78 @@ export const configureOrdersModuleQueries = ({
|
|
|
58
79
|
return Orders.find(selector, findOptions).toArray();
|
|
59
80
|
},
|
|
60
81
|
|
|
82
|
+
getReport: async ({ from, to } = { from: null, to: null }) => {
|
|
83
|
+
const selector: any = { $exists: true };
|
|
84
|
+
if (from || to) {
|
|
85
|
+
if (from) {
|
|
86
|
+
const fromDate = new Date(from);
|
|
87
|
+
selector.$gte = fromDate;
|
|
88
|
+
}
|
|
89
|
+
if (to) {
|
|
90
|
+
const toDate = new Date(to);
|
|
91
|
+
selector.$lte = toDate;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const pipeline = [
|
|
96
|
+
{
|
|
97
|
+
$facet: {
|
|
98
|
+
checkoutCount: [
|
|
99
|
+
{
|
|
100
|
+
$match: {
|
|
101
|
+
ordered: selector,
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{ $count: 'count' },
|
|
105
|
+
],
|
|
106
|
+
fulfillCount: [
|
|
107
|
+
{
|
|
108
|
+
$match: {
|
|
109
|
+
fullfilled: selector,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{ $count: 'count' },
|
|
113
|
+
],
|
|
114
|
+
rejectCount: [
|
|
115
|
+
{
|
|
116
|
+
$match: {
|
|
117
|
+
rejected: selector,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{ $count: 'count' },
|
|
121
|
+
],
|
|
122
|
+
newCount: [
|
|
123
|
+
{
|
|
124
|
+
$match: {
|
|
125
|
+
created: selector,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{ $count: 'count' },
|
|
129
|
+
],
|
|
130
|
+
confirmCount: [
|
|
131
|
+
{
|
|
132
|
+
$match: {
|
|
133
|
+
confirmed: selector,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
{ $count: 'count' },
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
$project: {
|
|
142
|
+
checkoutCount: { $arrayElemAt: ['$checkoutCount.count', 0] },
|
|
143
|
+
fulfillCount: { $arrayElemAt: ['$fulfillCount.count', 0] },
|
|
144
|
+
rejectCount: { $arrayElemAt: ['$rejectCount.count', 0] },
|
|
145
|
+
newCount: { $arrayElemAt: ['$newCount.count', 0] },
|
|
146
|
+
confirmCount: { $arrayElemAt: ['$confirmCount.count', 0] },
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
const [facetedResult] = await Orders.aggregate(pipeline).toArray();
|
|
151
|
+
return normalizeOrderAggregateResult(facetedResult);
|
|
152
|
+
},
|
|
153
|
+
|
|
61
154
|
orderExists: async ({ orderId }) => {
|
|
62
155
|
const orderCount = await Orders.countDocuments(generateDbFilterById(orderId), {
|
|
63
156
|
limit: 1,
|