@chevre/domain 22.11.0-alpha.34 → 22.11.0-alpha.35

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.
@@ -18,11 +18,18 @@ function createAggregation(params: {
18
18
  }) => {
19
19
  const { order, orderDateGte, orderDateLte } = params;
20
20
 
21
- return repos.order.aggregateOrderOfCustomer({
22
- project: { id: { $eq: PROJECT_ID } },
23
- orderDate: { $gte: orderDateGte, $lte: orderDateLte },
24
- customer: { email: { $eq: String(order.customer.email) } }
25
- });
21
+ if (PROJECT_ID === '*') {
22
+ return repos.order.aggregateOrderOfCustomerGlobally({
23
+ orderDate: { $gte: orderDateGte, $lte: orderDateLte },
24
+ customer: { email: { $eq: String(order.customer.email) } }
25
+ });
26
+ } else {
27
+ return repos.order.aggregateOrderOfCustomerByProject({
28
+ project: { id: { $eq: PROJECT_ID } },
29
+ orderDate: { $gte: orderDateGte, $lte: orderDateLte },
30
+ customer: { email: { $eq: String(order.customer.email) } }
31
+ });
32
+ }
26
33
  };
27
34
  }
28
35
 
@@ -41,12 +48,16 @@ async function main() {
41
48
 
42
49
  const cursor = orderRepo.getCursor(
43
50
  {
44
- 'project.id': { $eq: PROJECT_ID },
51
+ ...(PROJECT_ID !== '*') ? { 'project.id': { $eq: PROJECT_ID } } : undefined,
45
52
  orderDate: {
46
53
  $gte: orderDateGte,
47
54
  $lte: orderDateLte
48
55
  },
49
- typeOf: { $eq: chevre.factory.order.OrderType.Order }
56
+ typeOf: { $eq: chevre.factory.order.OrderType.Order },
57
+ 'customer.id': { // exclude pos,tvm
58
+ $exists: true,
59
+ $in: []
60
+ }
50
61
  },
51
62
  {
52
63
  customer: 1,
@@ -79,11 +90,11 @@ async function main() {
79
90
  if (typeof email === 'string') {
80
91
  console.log(
81
92
  'aggregating...',
82
- order.project.id, order.orderNumber, order.orderDate, i);
93
+ order.project.id, order.orderNumber, email, order.orderDate, i);
83
94
  const aggregateResult = await createAggregation({ order, orderDateGte, orderDateLte })({ order: orderRepo });
84
95
  await aggregateOrderRepo.save(
85
96
  {
86
- project: order.project,
97
+ project: { id: PROJECT_ID, typeOf: chevre.factory.organizationType.Project },
87
98
  identifier: email,
88
99
  typeOf: chevre.factory.personType.Person
89
100
  },
@@ -92,7 +103,7 @@ async function main() {
92
103
  updateCount += 1;
93
104
  console.log(
94
105
  'aggregated.',
95
- order.project.id, order.orderNumber, order.orderDate, i);
106
+ order.project.id, order.orderNumber, email, order.orderDate, i);
96
107
 
97
108
  const sumGraceTime = (typeof aggregateResult.aggregation.sumGraceTime === 'number')
98
109
  ? aggregateResult.aggregation.sumGraceTime
@@ -204,8 +204,8 @@ export declare class OrderRepo {
204
204
  emailCount?: number;
205
205
  };
206
206
  }>;
207
- aggregateOrderOfCustomer(params: {
208
- project: {
207
+ aggregateOrderOfCustomerByProject(params: {
208
+ project?: {
209
209
  id: {
210
210
  $eq: string;
211
211
  };
@@ -225,5 +225,20 @@ export declare class OrderRepo {
225
225
  emailCount?: number;
226
226
  };
227
227
  }>;
228
+ aggregateOrderOfCustomerGlobally(params: {
229
+ orderDate: {
230
+ $gte: Date;
231
+ $lte: Date;
232
+ };
233
+ customer: {
234
+ email: {
235
+ $eq: string;
236
+ };
237
+ };
238
+ }): Promise<{
239
+ aggregation: Pick<IAggregation, 'orderCount'> & {
240
+ sumGraceTime?: never;
241
+ };
242
+ }>;
228
243
  }
229
244
  export {};
@@ -1198,17 +1198,13 @@ class OrderRepo {
1198
1198
  };
1199
1199
  });
1200
1200
  }
1201
- aggregateOrderOfCustomer(params) {
1201
+ aggregateOrderOfCustomerByProject(params) {
1202
1202
  return __awaiter(this, void 0, void 0, function* () {
1203
- const matchConditions = {
1204
- orderDate: {
1203
+ var _a;
1204
+ const matchConditions = Object.assign(Object.assign({ orderDate: {
1205
1205
  $gte: params.orderDate.$gte,
1206
1206
  $lte: params.orderDate.$lte
1207
- },
1208
- typeOf: { $eq: factory.order.OrderType.Order },
1209
- 'project.id': { $eq: params.project.id.$eq },
1210
- 'customer.email': { $exists: true, $eq: params.customer.email.$eq }
1211
- };
1207
+ }, typeOf: { $eq: factory.order.OrderType.Order } }, (typeof ((_a = params.project) === null || _a === void 0 ? void 0 : _a.id.$eq) === 'string') ? { 'project.id': { $eq: params.project.id.$eq } } : undefined), { 'customer.email': { $exists: true, $eq: params.customer.email.$eq } });
1212
1208
  const aggregations = yield this.orderModel.aggregate([
1213
1209
  { $match: matchConditions },
1214
1210
  {
@@ -1250,5 +1246,48 @@ class OrderRepo {
1250
1246
  };
1251
1247
  });
1252
1248
  }
1249
+ aggregateOrderOfCustomerGlobally(params) {
1250
+ return __awaiter(this, void 0, void 0, function* () {
1251
+ const matchConditions = {
1252
+ orderDate: {
1253
+ $gte: params.orderDate.$gte,
1254
+ $lte: params.orderDate.$lte
1255
+ },
1256
+ typeOf: { $eq: factory.order.OrderType.Order },
1257
+ 'customer.email': { $exists: true, $eq: params.customer.email.$eq }
1258
+ };
1259
+ const aggregations = yield this.orderModel.aggregate([
1260
+ { $match: matchConditions },
1261
+ {
1262
+ $project: {
1263
+ typeOf: '$typeOf'
1264
+ }
1265
+ },
1266
+ {
1267
+ $group: {
1268
+ _id: '$typeOf',
1269
+ orderCount: { $sum: 1 }
1270
+ }
1271
+ },
1272
+ {
1273
+ $project: {
1274
+ _id: 0,
1275
+ orderCount: '$orderCount'
1276
+ }
1277
+ }
1278
+ ])
1279
+ .exec();
1280
+ if (aggregations.length === 0) {
1281
+ return {
1282
+ aggregation: {
1283
+ orderCount: 0
1284
+ }
1285
+ };
1286
+ }
1287
+ return {
1288
+ aggregation: Object.assign({}, aggregations[0])
1289
+ };
1290
+ });
1291
+ }
1253
1292
  }
1254
1293
  exports.OrderRepo = OrderRepo;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.396.0-alpha.5",
14
+ "@chevre/factory": "4.396.0-alpha.6",
15
15
  "@cinerino/sdk": "11.2.0-alpha.0",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.0",
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "22.11.0-alpha.34"
118
+ "version": "22.11.0-alpha.35"
119
119
  }
@@ -1,100 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- const PROJECT_ID = String(process.env.PROJECT_ID);
7
-
8
- // tslint:disable-next-line:max-func-body-length
9
- async function main() {
10
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
-
12
- const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
13
-
14
- const result = await productRepo.upsertManyByProductId(
15
- [
16
- {
17
- $set: {
18
- project: {
19
- typeOf: chevre.factory.organizationType.Project,
20
- id: PROJECT_ID
21
- },
22
- typeOf: chevre.factory.product.ProductType.EventService,
23
- productID: '2023122601EventService',
24
- name: {
25
- en: 'xxx',
26
- ja: 'xxx'
27
- },
28
- // hasOfferCatalog: {
29
- // id: 'blpc770py',
30
- // typeOf: 'OfferCatalog'
31
- // },
32
- // serviceType: {
33
- // codeValue: '0001',
34
- // typeOf: 'CategoryCode',
35
- // inCodeSet: {
36
- // identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType,
37
- // typeOf: 'CategoryCodeSet'
38
- // }
39
- // },
40
- availableChannel: {
41
- typeOf: 'ServiceChannel',
42
- credentials: {}
43
- },
44
- description: {
45
- en: 'xxx',
46
- ja: 'xxx'
47
- }
48
- },
49
- $unset: {
50
- hasOfferCatalog: 1,
51
- serviceType: 1
52
- }
53
- },
54
- {
55
- $set: {
56
- project: {
57
- typeOf: chevre.factory.organizationType.Project,
58
- id: PROJECT_ID
59
- },
60
- typeOf: chevre.factory.product.ProductType.EventService,
61
- productID: '2023122602EventService',
62
- name: {
63
- en: 'xxx',
64
- ja: 'xxx'
65
- },
66
- hasOfferCatalog: {
67
- // id: 'blpc770py',
68
- typeOf: 'OfferCatalog',
69
- itemListElement: [{ id: 'blpc770py' }]
70
- },
71
- // serviceType: {
72
- // codeValue: '0001',
73
- // typeOf: 'CategoryCode',
74
- // inCodeSet: {
75
- // identifier: chevre.factory.categoryCode.CategorySetIdentifier.ServiceType,
76
- // typeOf: 'CategoryCodeSet'
77
- // }
78
- // },
79
- availableChannel: {
80
- typeOf: 'ServiceChannel',
81
- credentials: {}
82
- },
83
- description: {
84
- en: 'xxx',
85
- ja: 'xxx'
86
- }
87
- },
88
- $unset: {
89
- }
90
- }
91
- ]
92
- // { replace: true }
93
- );
94
- // tslint:disable-next-line:no-null-keyword
95
- console.log(result);
96
- }
97
-
98
- main()
99
- .then(console.log)
100
- .catch(console.error);