@chevre/domain 21.17.0-alpha.17 → 21.17.0-alpha.19

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.
@@ -3,8 +3,17 @@ import * as mongoose from 'mongoose';
3
3
 
4
4
  import { chevre } from '../../../lib/index';
5
5
 
6
+ mongoose.Model.on('index', (...args) => {
7
+ console.error('******** index event emitted. ********\n', args);
8
+ });
9
+
6
10
  async function main() {
7
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
12
+
13
+ const indexes = await mongoose.connection.db.collection('aggregateOffers')
14
+ .indexes();
15
+ console.log(indexes);
16
+ console.log(indexes.length);
8
17
 
9
18
  const aggregateOfferRepo = await chevre.repository.AggregateOffer.createInstance(mongoose.connection);
10
19
 
@@ -15,6 +24,7 @@ async function main() {
15
24
  project: { id: { $eq: String(process.env.PROJECT_ID) } },
16
25
  availability: { $eq: chevre.factory.itemAvailability.InStock },
17
26
  itemOffered: { typeOf: { $eq: chevre.factory.product.ProductType.EventService } },
27
+ acceptedPaymentMethod: { identifier: { $in: ['xxx'] } },
18
28
  // identifier: { $eq: '901' },
19
29
  sort: {
20
30
  'priceSpecification.price': 1,
@@ -34,13 +44,6 @@ async function main() {
34
44
  return `${offer.project.id} ${(<any>offer).offerCount} ${offer.offers[0].identifier} ${offer.offers[0].name.ja} ${offer.offers[0].priceSpecification.price}`;
35
45
  }));
36
46
  console.log(offers.length);
37
-
38
- const aggregateOfferCount = await aggregateOfferRepo.count({
39
- project: { id: { $eq: String(process.env.PROJECT_ID) } },
40
- availability: { $eq: chevre.factory.itemAvailability.InStock },
41
- itemOffered: { typeOf: { $eq: chevre.factory.product.ProductType.EventService } }
42
- });
43
- console.log('aggregateOfferCount:', aggregateOfferCount);
44
47
  }
45
48
 
46
49
  main()
@@ -10,13 +10,10 @@ mongoose.Model.on('index', (...args) => {
10
10
  async function main() {
11
11
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
12
12
 
13
- // const indexes = await mongoose.connection.db.collection('aggregateOffers')
14
- // .indexes();
15
- // console.log(indexes);
16
- // console.log(indexes.length);
17
- // await mongoose.connection.db.collection('aggregateOffers')
18
- // .dropIndexes();
19
- // console.log('indexes droped');
13
+ const indexes = await mongoose.connection.db.collection('aggregateOffers')
14
+ .indexes();
15
+ console.log(indexes);
16
+ console.log(indexes.length);
20
17
 
21
18
  const offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
22
19
 
@@ -25,6 +22,7 @@ async function main() {
25
22
  // page: 1,
26
23
  project: { id: { $eq: String(process.env.PROJECT_ID) } },
27
24
  availability: { $eq: chevre.factory.itemAvailability.InStock },
25
+ acceptedPaymentMethod: { identifier: { $in: ['xxx'] } },
28
26
  parentOffer: {
29
27
  },
30
28
  priceSpecification: {
@@ -0,0 +1,38 @@
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 orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
12
+
13
+ const searchConditions: chevre.factory.order.ISearchConditions = {
14
+ // tslint:disable-next-line:no-magic-numbers
15
+ limit: 10,
16
+ page: 1,
17
+ project: { id: { $eq: project.id } },
18
+ confirmationNumbers: ['36684'],
19
+ orderNumbers: ['CIN1-3743286-2441943'],
20
+ acceptedOffers: { itemOffered: { typeOf: { $in: [chevre.factory.reservationType.EventReservation] } } }
21
+ // ...(typeof req.seller?.id === 'string') ? { seller: { id: { $eq: req.seller.id } } } : undefined // req.seller.idを考慮
22
+ };
23
+ const acceptedOffers = await orderRepo.searchAcceptedOffers(searchConditions, ['itemOffered', 'id']);
24
+ // tslint:disable-next-line:no-null-keyword
25
+ console.dir(acceptedOffers, { depth: 1 });
26
+ const reservationIds = acceptedOffers.map((acceptedOffer) => {
27
+ if (acceptedOffer.itemOffered.typeOf === chevre.factory.reservationType.EventReservation) {
28
+ return acceptedOffer.itemOffered.id;
29
+ } else {
30
+ return '';
31
+ }
32
+ });
33
+ console.log('reservationIds:', reservationIds);
34
+ }
35
+
36
+ main()
37
+ .then()
38
+ .catch(console.error);
@@ -22,7 +22,7 @@ class MongoRepository {
22
22
  }
23
23
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
24
24
  static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40;
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42;
26
26
  const matchStages = [];
27
27
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
28
28
  if (typeof projectIdEq === 'string') {
@@ -361,7 +361,18 @@ class MongoRepository {
361
361
  }
362
362
  });
363
363
  }
364
- const additionalPropertyAll = (_39 = params.additionalProperty) === null || _39 === void 0 ? void 0 : _39.$all;
364
+ const acceptedPaymentMethodIdentifierIn = (_40 = (_39 = params.acceptedPaymentMethod) === null || _39 === void 0 ? void 0 : _39.identifier) === null || _40 === void 0 ? void 0 : _40.$in;
365
+ if (Array.isArray(acceptedPaymentMethodIdentifierIn)) {
366
+ matchStages.push({
367
+ $match: {
368
+ 'offers.acceptedPaymentMethod.identifier': {
369
+ $exists: true,
370
+ $in: acceptedPaymentMethodIdentifierIn
371
+ }
372
+ }
373
+ });
374
+ }
375
+ const additionalPropertyAll = (_41 = params.additionalProperty) === null || _41 === void 0 ? void 0 : _41.$all;
365
376
  if (Array.isArray(additionalPropertyAll)) {
366
377
  matchStages.push({
367
378
  $match: {
@@ -372,7 +383,7 @@ class MongoRepository {
372
383
  }
373
384
  });
374
385
  }
375
- const additionalPropertyElemMatch = (_40 = params.additionalProperty) === null || _40 === void 0 ? void 0 : _40.$elemMatch;
386
+ const additionalPropertyElemMatch = (_42 = params.additionalProperty) === null || _42 === void 0 ? void 0 : _42.$elemMatch;
376
387
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
377
388
  matchStages.push({
378
389
  $match: {
@@ -1,5 +1,5 @@
1
1
  import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
2
2
  declare const modelName = "AggregateOffer";
3
- declare function createSchema(): Schema;
4
3
  declare const indexes: [d: IndexDefinition, o: IndexOptions][];
4
+ declare function createSchema(): Schema;
5
5
  export { modelName, indexes, createSchema };
@@ -39,17 +39,6 @@ const schemaOptions = {
39
39
  versionKey: false
40
40
  }
41
41
  };
42
- /**
43
- * 集計オファースキーマ
44
- */
45
- let schema;
46
- function createSchema() {
47
- if (schema === undefined) {
48
- schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
49
- }
50
- return schema;
51
- }
52
- exports.createSchema = createSchema;
53
42
  const indexes = [
54
43
  [
55
44
  { createdAt: 1 },
@@ -288,6 +277,31 @@ const indexes = [
288
277
  'offers.validThrough': { $exists: true }
289
278
  }
290
279
  }
280
+ ],
281
+ [
282
+ { 'offers.acceptedPaymentMethod.identifier': 1 },
283
+ {
284
+ name: 'searchByOffersAcceptedPaymentMethodIdentifier',
285
+ partialFilterExpression: {
286
+ 'offers.acceptedPaymentMethod.identifier': { $exists: true }
287
+ }
288
+ }
291
289
  ]
292
290
  ];
293
291
  exports.indexes = indexes;
292
+ /**
293
+ * 集計オファースキーマ
294
+ */
295
+ let schema;
296
+ function createSchema() {
297
+ if (schema === undefined) {
298
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
299
+ if (settings_1.MONGO_AUTO_INDEX) {
300
+ indexes.forEach((indexParams) => {
301
+ schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
302
+ });
303
+ }
304
+ }
305
+ return schema;
306
+ }
307
+ exports.createSchema = createSchema;
@@ -40,7 +40,7 @@ class MongoRepository {
40
40
  }
41
41
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
42
42
  static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
43
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44;
43
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46;
44
44
  const matchStages = [];
45
45
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
46
46
  if (typeof projectIdEq === 'string') {
@@ -359,7 +359,18 @@ class MongoRepository {
359
359
  }
360
360
  });
361
361
  }
362
- const additionalPropertyAll = (_43 = params.additionalProperty) === null || _43 === void 0 ? void 0 : _43.$all;
362
+ const acceptedPaymentMethodIdentifierIn = (_44 = (_43 = params.acceptedPaymentMethod) === null || _43 === void 0 ? void 0 : _43.identifier) === null || _44 === void 0 ? void 0 : _44.$in;
363
+ if (Array.isArray(acceptedPaymentMethodIdentifierIn)) {
364
+ matchStages.push({
365
+ $match: {
366
+ 'offers.acceptedPaymentMethod.identifier': {
367
+ $exists: true,
368
+ $in: acceptedPaymentMethodIdentifierIn
369
+ }
370
+ }
371
+ });
372
+ }
373
+ const additionalPropertyAll = (_45 = params.additionalProperty) === null || _45 === void 0 ? void 0 : _45.$all;
363
374
  if (Array.isArray(additionalPropertyAll)) {
364
375
  matchStages.push({
365
376
  $match: {
@@ -370,7 +381,7 @@ class MongoRepository {
370
381
  }
371
382
  });
372
383
  }
373
- const additionalPropertyElemMatch = (_44 = params.additionalProperty) === null || _44 === void 0 ? void 0 : _44.$elemMatch;
384
+ const additionalPropertyElemMatch = (_46 = params.additionalProperty) === null || _46 === void 0 ? void 0 : _46.$elemMatch;
374
385
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
375
386
  matchStages.push({
376
387
  $match: {
@@ -25,11 +25,10 @@
25
25
  import type { Connection, FilterQuery } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  type IKeyOfProjection = keyof factory.order.IOrder | '_id';
28
- type IProjection4searchWithUnwoundAcceptedOffer = {
28
+ type IProjection4searchWithUnwoundAcceptedOffers = {
29
29
  [key in keyof Omit<factory.order.IOrder, 'acceptedOffers'>]?: 1;
30
30
  } & {
31
31
  _id?: 0 | 1;
32
- acceptedOffers?: ['$acceptedOffers'];
33
32
  };
34
33
  /**
35
34
  * 注文リポジトリ
@@ -37,7 +36,7 @@ type IProjection4searchWithUnwoundAcceptedOffer = {
37
36
  export declare class MongoRepository {
38
37
  private readonly orderModel;
39
38
  constructor(connection: Connection);
40
- static CREATE_MONGO_CONDITIONS(params: factory.order.ISearchConditions): any[];
39
+ static CREATE_MONGO_CONDITIONS(params: factory.order.ISearchConditions): FilterQuery<factory.order.IOrder>[];
41
40
  /**
42
41
  * なければ作成する
43
42
  */
@@ -141,9 +140,11 @@ export declare class MongoRepository {
141
140
  /**
142
141
  * オファー展開の注文検索
143
142
  */
144
- searchWithUnwoundAcceptedOffer(params: factory.order.ISearchConditions, projection?: IProjection4searchWithUnwoundAcceptedOffer): Promise<Omit<factory.order.IOrder[], 'acceptedOffers'> & {
145
- acceptedOffers?: factory.order.IAcceptedOffer<factory.order.IItemOffered> | factory.order.IAcceptedOffer<factory.order.IItemOffered>[];
146
- }>;
143
+ searchWithUnwoundAcceptedOffers(params: factory.order.ISearchConditions, projection?: IProjection4searchWithUnwoundAcceptedOffers): Promise<factory.order.IOrder[]>;
144
+ /**
145
+ * オファーのみ展開して検索する
146
+ */
147
+ searchAcceptedOffers(params: factory.order.ISearchConditions, inclusion?: (keyof factory.order.IAcceptedOffer<factory.order.IItemOffered>)[]): Promise<factory.order.IAcceptedOffer<factory.order.IItemOffered>[]>;
147
148
  /**
148
149
  * 注文に含まれる予約番号を検索する
149
150
  */
@@ -989,7 +989,7 @@ class MongoRepository {
989
989
  /**
990
990
  * オファー展開の注文検索
991
991
  */
992
- searchWithUnwoundAcceptedOffer(params, projection) {
992
+ searchWithUnwoundAcceptedOffers(params, projection) {
993
993
  var _a;
994
994
  return __awaiter(this, void 0, void 0, function* () {
995
995
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
@@ -1005,43 +1005,67 @@ class MongoRepository {
1005
1005
  conditions.forEach((c) => {
1006
1006
  aggregate.match(c);
1007
1007
  });
1008
- aggregate.project((projection !== undefined && projection !== null)
1009
- ? projection
1010
- : {
1011
- // _id: 0,
1012
- __v: 0,
1013
- createdAt: 0,
1014
- updatedAt: 0
1008
+ aggregate.project(Object.assign(Object.assign({}, projection), { acceptedOffers: ['$acceptedOffers'] }));
1009
+ if (typeof params.limit === 'number' && params.limit > 0) {
1010
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
1011
+ aggregate.limit(params.limit * page)
1012
+ .skip(params.limit * (page - 1));
1013
+ }
1014
+ return aggregate
1015
+ // .allowDiskUse(true) // false化(2023-11-30~)
1016
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
1017
+ .exec();
1018
+ });
1019
+ }
1020
+ /**
1021
+ * オファーのみ展開して検索する
1022
+ */
1023
+ searchAcceptedOffers(params, inclusion) {
1024
+ var _a;
1025
+ return __awaiter(this, void 0, void 0, function* () {
1026
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
1027
+ const aggregate = this.orderModel.aggregate();
1028
+ // pipelineの順序に注意
1029
+ // @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
1030
+ // tslint:disable-next-line:no-single-line-block-comment
1031
+ /* istanbul ignore else */
1032
+ if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.orderDate) === 'number') {
1033
+ aggregate.sort({ orderDate: params.sort.orderDate });
1034
+ }
1035
+ aggregate.unwind('$acceptedOffers');
1036
+ conditions.forEach((c) => {
1037
+ aggregate.match(c);
1038
+ });
1039
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
1040
+ const specifiedProjection = {
1041
+ _id: 0
1042
+ };
1043
+ inclusion.forEach((key) => {
1044
+ specifiedProjection[key] = `$acceptedOffers.${key}`;
1015
1045
  });
1046
+ aggregate.project(specifiedProjection);
1047
+ }
1048
+ else {
1049
+ aggregate.project({
1050
+ _id: 0,
1051
+ itemOffered: '$acceptedOffers.itemOffered',
1052
+ priceSpecification: '$acceptedOffers.priceSpecification',
1053
+ typeOf: '$acceptedOffers.typeOf',
1054
+ id: '$acceptedOffers.id',
1055
+ offeredThrough: '$acceptedOffers.offeredThrough',
1056
+ name: '$acceptedOffers.name'
1057
+ });
1058
+ }
1016
1059
  if (typeof params.limit === 'number' && params.limit > 0) {
1017
1060
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
1018
1061
  aggregate.limit(params.limit * page)
1019
1062
  .skip(params.limit * (page - 1));
1020
1063
  }
1021
- return aggregate.allowDiskUse(true)
1064
+ return aggregate
1022
1065
  .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
1023
1066
  .exec();
1024
1067
  });
1025
1068
  }
1026
- // 廃止(2023-10-15~)
1027
- // public async saveAwardAccountsIfNotExist(parmas: {
1028
- // orderNumber: string;
1029
- // awardAccounts: factory.transaction.placeOrder.IAwardAccount[];
1030
- // }) {
1031
- // if (Array.isArray(parmas.awardAccounts)) {
1032
- // const newIdentifier: factory.propertyValue.IPropertyValue<string>
1033
- // = { name: AWARD_ACCOUNTS_IDENTIFIER_NAME, value: JSON.stringify(parmas.awardAccounts) };
1034
- // await this.orderModel.findOneAndUpdate(
1035
- // {
1036
- // orderNumber: { $eq: parmas.orderNumber },
1037
- // 'identifier.name': { $ne: AWARD_ACCOUNTS_IDENTIFIER_NAME }
1038
- // },
1039
- // { $push: { identifier: newIdentifier } },
1040
- // { new: true }
1041
- // )
1042
- // .exec();
1043
- // }
1044
- // }
1045
1069
  /**
1046
1070
  * 注文に含まれる予約番号を検索する
1047
1071
  */
package/package.json CHANGED
@@ -10,8 +10,8 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.343.0-alpha.5",
14
- "@cinerino/sdk": "5.2.0-alpha.4",
13
+ "@chevre/factory": "4.343.0",
14
+ "@cinerino/sdk": "5.2.0",
15
15
  "@motionpicture/coa-service": "9.2.0",
16
16
  "@motionpicture/gmo-service": "5.2.0",
17
17
  "@sendgrid/mail": "6.4.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.17.0-alpha.17"
120
+ "version": "21.17.0-alpha.19"
121
121
  }