@unchainedshop/core-events 2.13.1 → 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.
|
@@ -2,6 +2,7 @@ import type { mongodb } from '@unchainedshop/mongodb';
|
|
|
2
2
|
import { SortOption } from '@unchainedshop/types/api.js';
|
|
3
3
|
import { ModuleCreateMutation, ModuleInput } from '@unchainedshop/types/core.js';
|
|
4
4
|
import { Event } from '../db/EventsCollection.js';
|
|
5
|
+
import { EventReport } from '@unchainedshop/types/events.js';
|
|
5
6
|
export type EventQuery = {
|
|
6
7
|
types?: Array<string>;
|
|
7
8
|
queryString?: string;
|
|
@@ -23,6 +24,11 @@ export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
|
23
24
|
}, options?: mongodb.FindOptions) => Promise<Array<Event>>;
|
|
24
25
|
type: (event: Event) => string;
|
|
25
26
|
count: (query: EventQuery) => Promise<number>;
|
|
27
|
+
getReport: (params?: {
|
|
28
|
+
from?: Date;
|
|
29
|
+
to?: Date;
|
|
30
|
+
types?: string[];
|
|
31
|
+
}) => Promise<EventReport[]>;
|
|
26
32
|
}
|
|
27
33
|
export declare const configureEventsModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<EventsModule>;
|
|
28
34
|
//# sourceMappingURL=configureEventsModule.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.d.ts","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAItD,OAAO,EAAiB,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAmB,MAAM,8BAA8B,CAAC;AAClG,OAAO,EAAoB,KAAK,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"configureEventsModule.d.ts","sourceRoot":"","sources":["../../src/module/configureEvents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9C,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,IAAI,CAAC;QAAC,EAAE,CAAC,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAC9F;AAED,eAAO,MAAM,qBAAqB,YAE/B,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAG,OAAO,CAAC,YAAY,CA8F3D,CAAC"}
|
|
@@ -44,6 +44,58 @@ export const configureEventsModule = async ({ db, }) => {
|
|
|
44
44
|
const count = await Events.countDocuments(buildFindSelector(query));
|
|
45
45
|
return count;
|
|
46
46
|
},
|
|
47
|
+
getReport: async ({ from, to, types } = { from: null, to: null, types: null }) => {
|
|
48
|
+
const pipeline = [];
|
|
49
|
+
const matchConditions = [];
|
|
50
|
+
// build date filter based on provided values it can be a range if both to and from is supplied
|
|
51
|
+
// a upper or lowe limit if either from or to is provided
|
|
52
|
+
// or all if none is provided
|
|
53
|
+
if (from || to) {
|
|
54
|
+
const dateConditions = [];
|
|
55
|
+
if (from) {
|
|
56
|
+
const fromDate = new Date(from);
|
|
57
|
+
dateConditions.push({
|
|
58
|
+
$or: [{ created: { $gte: fromDate } }, { updated: { $gte: fromDate } }],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
if (to) {
|
|
62
|
+
const toDate = new Date(to);
|
|
63
|
+
dateConditions.push({
|
|
64
|
+
$or: [{ created: { $lte: toDate } }, { updated: { $lte: toDate } }],
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (dateConditions.length > 0) {
|
|
68
|
+
matchConditions.push({ $and: dateConditions });
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// build types filter if type is provided or ignore types if it is not provided
|
|
72
|
+
if (types && Array.isArray(types) && types.length) {
|
|
73
|
+
matchConditions.push({ type: { $in: types } });
|
|
74
|
+
}
|
|
75
|
+
if (matchConditions.length > 0) {
|
|
76
|
+
pipeline.push({
|
|
77
|
+
$match: {
|
|
78
|
+
$and: matchConditions,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
pipeline.push(...[
|
|
83
|
+
{
|
|
84
|
+
$group: {
|
|
85
|
+
_id: '$type',
|
|
86
|
+
emitCount: { $sum: 1 },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
$project: {
|
|
91
|
+
_id: 0,
|
|
92
|
+
type: '$_id',
|
|
93
|
+
emitCount: 1,
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
return Events.aggregate(pipeline).toArray();
|
|
98
|
+
},
|
|
47
99
|
};
|
|
48
100
|
};
|
|
49
101
|
//# sourceMappingURL=configureEventsModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAc,MAAM,6BAA6B,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAS,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"configureEventsModule.js","sourceRoot":"","sources":["../../src/module/configureEventsModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EA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AAE,CAAC,EAAE;qBACvB;iBACF;gBACD;oBACE,QAAQ,EAAE;wBACR,GAAG,EAAE,CAAC;wBACN,IAAI,EAAE,MAAM;wBACZ,SAAS,EAAE,CAAC;qBACb;iBACF;aACF,CACF,CAAC;YAEF,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO,EAA4B,CAAC;QACxE,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-events",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"main": "lib/events-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/events-index.js",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^2.
|
|
35
|
-
"@unchainedshop/utils": "^2.
|
|
34
|
+
"@unchainedshop/events": "^2.14.0",
|
|
35
|
+
"@unchainedshop/utils": "^2.14.0",
|
|
36
36
|
"simpl-schema": "^3.4.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^20.
|
|
40
|
-
"@unchainedshop/types": "^2.
|
|
39
|
+
"@types/node": "^20.16.4",
|
|
40
|
+
"@unchainedshop/types": "^2.14.0",
|
|
41
41
|
"jest": "^29.7.0",
|
|
42
|
-
"ts-jest": "^29.2.
|
|
42
|
+
"ts-jest": "^29.2.5",
|
|
43
43
|
"typescript": "^5.5.4"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -7,6 +7,7 @@ import { ModuleCreateMutation, ModuleInput, ModuleMutations } from '@unchainedsh
|
|
|
7
7
|
import { EventsCollection, Event } from '../db/EventsCollection.js';
|
|
8
8
|
import { EventsSchema } from '../db/EventsSchema.js';
|
|
9
9
|
import { configureEventHistoryAdapter } from './configureEventHistoryAdapter.js';
|
|
10
|
+
import { EventReport } from '@unchainedshop/types/events.js';
|
|
10
11
|
|
|
11
12
|
export type EventQuery = {
|
|
12
13
|
types?: Array<string>;
|
|
@@ -41,6 +42,7 @@ export interface EventsModule extends ModuleCreateMutation<Event> {
|
|
|
41
42
|
type: (event: Event) => string;
|
|
42
43
|
|
|
43
44
|
count: (query: EventQuery) => Promise<number>;
|
|
45
|
+
getReport: (params?: { from?: Date; to?: Date; types?: string[] }) => Promise<EventReport[]>;
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
export const configureEventsModule = async ({
|
|
@@ -81,5 +83,62 @@ export const configureEventsModule = async ({
|
|
|
81
83
|
const count = await Events.countDocuments(buildFindSelector(query));
|
|
82
84
|
return count;
|
|
83
85
|
},
|
|
86
|
+
|
|
87
|
+
getReport: async ({ from, to, types } = { from: null, to: null, types: null }) => {
|
|
88
|
+
const pipeline = [];
|
|
89
|
+
const matchConditions = [];
|
|
90
|
+
// build date filter based on provided values it can be a range if both to and from is supplied
|
|
91
|
+
// a upper or lowe limit if either from or to is provided
|
|
92
|
+
// or all if none is provided
|
|
93
|
+
if (from || to) {
|
|
94
|
+
const dateConditions = [];
|
|
95
|
+
if (from) {
|
|
96
|
+
const fromDate = new Date(from);
|
|
97
|
+
dateConditions.push({
|
|
98
|
+
$or: [{ created: { $gte: fromDate } }, { updated: { $gte: fromDate } }],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if (to) {
|
|
102
|
+
const toDate = new Date(to);
|
|
103
|
+
dateConditions.push({
|
|
104
|
+
$or: [{ created: { $lte: toDate } }, { updated: { $lte: toDate } }],
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (dateConditions.length > 0) {
|
|
108
|
+
matchConditions.push({ $and: dateConditions });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// build types filter if type is provided or ignore types if it is not provided
|
|
112
|
+
if (types && Array.isArray(types) && types.length) {
|
|
113
|
+
matchConditions.push({ type: { $in: types } });
|
|
114
|
+
}
|
|
115
|
+
if (matchConditions.length > 0) {
|
|
116
|
+
pipeline.push({
|
|
117
|
+
$match: {
|
|
118
|
+
$and: matchConditions,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
pipeline.push(
|
|
124
|
+
...[
|
|
125
|
+
{
|
|
126
|
+
$group: {
|
|
127
|
+
_id: '$type',
|
|
128
|
+
emitCount: { $sum: 1 },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
$project: {
|
|
133
|
+
_id: 0,
|
|
134
|
+
type: '$_id',
|
|
135
|
+
emitCount: 1,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
return Events.aggregate(pipeline).toArray() as Promise<EventReport[]>;
|
|
142
|
+
},
|
|
84
143
|
};
|
|
85
144
|
};
|