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

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
@@ -0,0 +1,28 @@
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
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
+
11
+ const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
12
+
13
+ const products = await productRepo.projectFields(
14
+ {
15
+ limit: 10,
16
+ project: { id: { $eq: PROJECT_ID } },
17
+ additionalPropertyMatch: { nameEq: 'xxxxx' }
18
+ // seller: { id: { $eq: 'xxx' } }
19
+ },
20
+ ['additionalProperty', 'productID']
21
+ );
22
+ console.log(products);
23
+ console.log(products.length, 'products found');
24
+ }
25
+
26
+ main()
27
+ .then(console.log)
28
+ .catch(console.error);
@@ -120,6 +120,15 @@ const indexes = [
120
120
  'name.en': { $exists: true }
121
121
  }
122
122
  }
123
+ ],
124
+ [
125
+ { additionalProperty: 1, productID: 1 },
126
+ {
127
+ name: 'additionalProperty',
128
+ partialFilterExpression: {
129
+ additionalProperty: { $exists: true }
130
+ }
131
+ }
123
132
  ]
124
133
  ];
125
134
  exports.indexes = indexes;
@@ -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;
@@ -48,7 +48,7 @@ class ProductRepo {
48
48
  }
49
49
  // tslint:disable-next-line:max-func-body-length
50
50
  static CREATE_MONGO_CONDITIONS(params) {
51
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
52
52
  // MongoDB検索条件
53
53
  const andConditions = [];
54
54
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -151,25 +151,20 @@ class ProductRepo {
151
151
  const nameRegexExp = new RegExp(nameRegex);
152
152
  andConditions.push({
153
153
  $or: [
154
- {
155
- 'name.ja': {
156
- $exists: true,
157
- $regex: nameRegexExp
158
- }
159
- },
160
- {
161
- 'name.en': {
162
- $exists: true,
163
- $regex: nameRegexExp
164
- }
165
- }
154
+ { 'name.ja': { $exists: true, $regex: nameRegexExp } },
155
+ { 'name.en': { $exists: true, $regex: nameRegexExp } }
166
156
  ]
167
157
  });
168
158
  }
169
- // const providerIdEq = params.provider?.id?.$eq;
170
- // if (typeof providerIdEq === 'string') {
171
- // andConditions.push({ 'provider.id': { $exists: true, $eq: providerIdEq } });
172
- // }
159
+ const additionalPropertyElemMatchNameEq = (_w = params.additionalPropertyMatch) === null || _w === void 0 ? void 0 : _w.nameEq;
160
+ if (typeof additionalPropertyElemMatchNameEq === 'string') {
161
+ andConditions.push({
162
+ additionalProperty: {
163
+ $exists: true,
164
+ $elemMatch: { name: { $eq: additionalPropertyElemMatchNameEq } }
165
+ }
166
+ });
167
+ }
173
168
  return andConditions;
174
169
  }
175
170
  /**
@@ -56,6 +56,10 @@ function start(params) {
56
56
  if (product === undefined) {
57
57
  throw new factory.errors.NotFound('Product');
58
58
  }
59
+ if (product.typeOf !== factory.product.ProductType.MembershipService
60
+ && product.typeOf !== factory.product.ProductType.PaymentCard) {
61
+ throw new factory.errors.Argument('object.itemOffered.id', `invalid product type: ${product.typeOf}`);
62
+ }
59
63
  const transactionNumber = params.transactionNumber;
60
64
  if (typeof transactionNumber !== 'string' || transactionNumber.length === 0) {
61
65
  throw new factory.errors.ArgumentNull('transactionNumber');
@@ -187,22 +187,25 @@ function searchAvailableAddOns(params) {
187
187
  const { offers, product } = yield OfferService.product.search(Object.assign({ ids: params.ids, project: { id: params.project.id }, itemOffered: { id: addOnProductId }, onlyValid: true, addSortIndex: false, includedInDataCatalog: { id: '' }, useIncludeInDataCatalog: false }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
188
188
  ? { availableAt: { id: params.availableAtOrFrom.id } }
189
189
  : undefined))(repos);
190
- availableAddOns.push(...offers.map((o) => {
191
- const itemOffered4addOn = {
192
- description: product.description,
193
- id: product.id,
194
- name: product.name,
195
- productID: product.productID,
196
- typeOf: product.typeOf
197
- };
198
- const unitPriceSpec = o.priceSpecification.priceComponent.find((component) => {
199
- return component.typeOf === factory.priceSpecificationType.UnitPriceSpecification;
200
- });
201
- if ((unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.typeOf) !== factory.priceSpecificationType.UnitPriceSpecification) {
202
- throw new factory.errors.NotFound('UnitPriceSpecification of an addOn');
203
- }
204
- return Object.assign(Object.assign({ alternateName: o.alternateName, availability: o.availability, description: o.description, id: String(o.id), identifier: o.identifier, itemOffered: itemOffered4addOn, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: unitPriceSpec, typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
205
- }));
190
+ const productType = product.typeOf;
191
+ if (productType === factory.product.ProductType.Product) {
192
+ availableAddOns.push(...offers.map((o) => {
193
+ const itemOffered4addOn = {
194
+ description: product.description,
195
+ id: product.id,
196
+ name: product.name,
197
+ productID: product.productID,
198
+ typeOf: productType
199
+ };
200
+ const unitPriceSpec = o.priceSpecification.priceComponent.find((component) => {
201
+ return component.typeOf === factory.priceSpecificationType.UnitPriceSpecification;
202
+ });
203
+ if ((unitPriceSpec === null || unitPriceSpec === void 0 ? void 0 : unitPriceSpec.typeOf) !== factory.priceSpecificationType.UnitPriceSpecification) {
204
+ throw new factory.errors.NotFound('UnitPriceSpecification of an addOn');
205
+ }
206
+ return Object.assign(Object.assign({ alternateName: o.alternateName, availability: o.availability, description: o.description, id: String(o.id), identifier: o.identifier, itemOffered: itemOffered4addOn, name: o.name, priceCurrency: o.priceCurrency, priceSpecification: unitPriceSpec, typeOf: o.typeOf }, (o.validFrom instanceof Date) ? { validFrom: o.validFrom } : undefined), (o.validThrough instanceof Date) ? { validThrough: o.validThrough } : undefined);
207
+ }));
208
+ }
206
209
  }
207
210
  }
208
211
  return availableAddOns;
@@ -189,6 +189,10 @@ function fixProductAndOffers(params) {
189
189
  if (product === undefined) {
190
190
  throw new factory.errors.NotFound('Product');
191
191
  }
192
+ if (product.typeOf !== factory.product.ProductType.MembershipService
193
+ && product.typeOf !== factory.product.ProductType.PaymentCard) {
194
+ throw new factory.errors.Argument('object.itemOffered.id', `invalid product type: ${product.typeOf}`);
195
+ }
192
196
  const { offers } = yield search(Object.assign({ ids: params.object.map((o) => String(o.id)), project: { id: params.project.id }, itemOffered: { id: String(product.id) }, onlyValid: true, includedInDataCatalog: { id: '' }, addSortIndex: false, useIncludeInDataCatalog: false }, (typeof ((_c = params.location) === null || _c === void 0 ? void 0 : _c.id) === 'string') ? { availableAt: { id: params.location.id } } : undefined))(repos);
193
197
  return { product, availableOffers: offers };
194
198
  });
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.7",
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.36"
119
119
  }
@@ -1,29 +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
- async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
10
-
11
- const productOfferRepo = await chevre.repository.ProductOffer.createInstance(mongoose.connection);
12
-
13
- const offers = await productOfferRepo.search({
14
- project: { id: { $eq: PROJECT_ID } }
15
- // seller: { id: { $eq: 'xxx' } }
16
- });
17
- console.log(offers);
18
- console.log(offers.length);
19
-
20
- // await productOfferRepo.deleteOne({
21
- // project: { id: PROJECT_ID },
22
- // seller: { id: 'xxx' },
23
- // itemOffered: { id: 'xxx' }
24
- // });
25
- }
26
-
27
- main()
28
- .then(console.log)
29
- .catch(console.error);
@@ -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);