@chevre/domain 21.8.0-alpha.35 → 21.8.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.
@@ -11,9 +11,12 @@ async function main() {
11
11
 
12
12
  const offers = await offerRepo.search(
13
13
  {
14
- limit: 5,
14
+ limit: 10,
15
15
  page: 1,
16
- sort: { 'priceSpecification.price': 1 },
16
+ sort: {
17
+ 'priceSpecification.price': 1,
18
+ identifier: 1
19
+ },
17
20
  project: { id: { $eq: String(process.env.PROJECT_ID) } },
18
21
  availability: { $eq: chevre.factory.itemAvailability.InStock },
19
22
  itemOffered: {
@@ -101,8 +104,8 @@ async function main() {
101
104
  }
102
105
  },
103
106
  price: {
104
- // $gte: 100,
105
- // $lte: 500
107
+ // $gte: 2000,
108
+ // $lte: 2000
106
109
  },
107
110
  referenceQuantity: {
108
111
  value: {
@@ -147,14 +150,16 @@ async function main() {
147
150
  identifier: 1,
148
151
  name: 1,
149
152
  alternateName: 1,
150
- priceSpecification: 1
153
+ priceSpecification: 1,
154
+ project: 1
151
155
  }
152
156
  );
153
157
  console.log(offers);
154
158
  console.log(offers.map((offer) => {
155
- return `${offer.project?.id} ${offer.id} ${offer.identifier} ${offer.name?.ja} ${offer.priceSpecification?.price}`;
159
+ return `${offer.project?.id} ${offer.identifier} ${offer.priceSpecification?.price} ${offer.name?.ja} ${offer.id}`;
156
160
  }));
157
161
  console.log(offers.length);
162
+ console.log('USE_AGGREGATE_OFFERS_AS_PRIMARY:', process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY);
158
163
  }
159
164
 
160
165
  main()
@@ -48,7 +48,7 @@ class MongoRepository {
48
48
  }
49
49
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
50
50
  static CREATE_OFFER_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, _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;
51
+ 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;
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;
@@ -303,13 +303,16 @@ class MongoRepository {
303
303
  const addOnItemOfferedIdEq = (_29 = (_28 = (_27 = params.addOn) === null || _27 === void 0 ? void 0 : _27.itemOffered) === null || _28 === void 0 ? void 0 : _28.id) === null || _29 === void 0 ? void 0 : _29.$eq;
304
304
  if (typeof addOnItemOfferedIdEq === 'string') {
305
305
  andConditions.push({
306
- 'addOn.itemOffered.id': {
307
- $exists: true,
308
- $eq: addOnItemOfferedIdEq
309
- }
306
+ 'addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
307
+ });
308
+ }
309
+ const addOnItemOfferedIdIn = (_32 = (_31 = (_30 = params.addOn) === null || _30 === void 0 ? void 0 : _30.itemOffered) === null || _31 === void 0 ? void 0 : _31.id) === null || _32 === void 0 ? void 0 : _32.$in;
310
+ if (Array.isArray(addOnItemOfferedIdIn)) {
311
+ andConditions.push({
312
+ 'addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
310
313
  });
311
314
  }
312
- const hasMerchantReturnPolicyIdEq = (_31 = (_30 = params.hasMerchantReturnPolicy) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
315
+ const hasMerchantReturnPolicyIdEq = (_34 = (_33 = params.hasMerchantReturnPolicy) === null || _33 === void 0 ? void 0 : _33.id) === null || _34 === void 0 ? void 0 : _34.$eq;
313
316
  if (typeof hasMerchantReturnPolicyIdEq === 'string') {
314
317
  andConditions.push({
315
318
  'hasMerchantReturnPolicy.id': {
@@ -318,7 +321,7 @@ class MongoRepository {
318
321
  }
319
322
  });
320
323
  }
321
- const additionalPropertyAll = (_32 = params.additionalProperty) === null || _32 === void 0 ? void 0 : _32.$all;
324
+ const additionalPropertyAll = (_35 = params.additionalProperty) === null || _35 === void 0 ? void 0 : _35.$all;
322
325
  if (Array.isArray(additionalPropertyAll)) {
323
326
  andConditions.push({
324
327
  additionalProperty: {
@@ -327,7 +330,7 @@ class MongoRepository {
327
330
  }
328
331
  });
329
332
  }
330
- const additionalPropertyElemMatch = (_33 = params.additionalProperty) === null || _33 === void 0 ? void 0 : _33.$elemMatch;
333
+ const additionalPropertyElemMatch = (_36 = params.additionalProperty) === null || _36 === void 0 ? void 0 : _36.$elemMatch;
331
334
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
332
335
  andConditions.push({
333
336
  additionalProperty: {
@@ -354,7 +357,7 @@ class MongoRepository {
354
357
  }
355
358
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
356
359
  static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
357
- 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;
360
+ 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;
358
361
  const matchStages = [];
359
362
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
360
363
  if (typeof projectIdEq === 'string') {
@@ -659,14 +662,19 @@ class MongoRepository {
659
662
  if (typeof addOnItemOfferedIdEq === 'string') {
660
663
  matchStages.push({
661
664
  $match: {
662
- 'offers.addOn.itemOffered.id': {
663
- $exists: true,
664
- $eq: addOnItemOfferedIdEq
665
- }
665
+ 'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
666
666
  }
667
667
  });
668
668
  }
669
- const hasMerchantReturnPolicyIdEq = (_31 = (_30 = params.hasMerchantReturnPolicy) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
669
+ const addOnItemOfferedIdIn = (_32 = (_31 = (_30 = params.addOn) === null || _30 === void 0 ? void 0 : _30.itemOffered) === null || _31 === void 0 ? void 0 : _31.id) === null || _32 === void 0 ? void 0 : _32.$in;
670
+ if (Array.isArray(addOnItemOfferedIdIn)) {
671
+ matchStages.push({
672
+ $match: {
673
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
674
+ }
675
+ });
676
+ }
677
+ const hasMerchantReturnPolicyIdEq = (_34 = (_33 = params.hasMerchantReturnPolicy) === null || _33 === void 0 ? void 0 : _33.id) === null || _34 === void 0 ? void 0 : _34.$eq;
670
678
  if (typeof hasMerchantReturnPolicyIdEq === 'string') {
671
679
  matchStages.push({
672
680
  $match: {
@@ -677,7 +685,7 @@ class MongoRepository {
677
685
  }
678
686
  });
679
687
  }
680
- const additionalPropertyAll = (_32 = params.additionalProperty) === null || _32 === void 0 ? void 0 : _32.$all;
688
+ const additionalPropertyAll = (_35 = params.additionalProperty) === null || _35 === void 0 ? void 0 : _35.$all;
681
689
  if (Array.isArray(additionalPropertyAll)) {
682
690
  matchStages.push({
683
691
  $match: {
@@ -688,7 +696,7 @@ class MongoRepository {
688
696
  }
689
697
  });
690
698
  }
691
- const additionalPropertyElemMatch = (_33 = params.additionalProperty) === null || _33 === void 0 ? void 0 : _33.$elemMatch;
699
+ const additionalPropertyElemMatch = (_36 = params.additionalProperty) === null || _36 === void 0 ? void 0 : _36.$elemMatch;
692
700
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
693
701
  matchStages.push({
694
702
  $match: {
@@ -824,8 +832,8 @@ class MongoRepository {
824
832
  }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
825
833
  ? { sort: { _id: factory.sortType.Ascending } }
826
834
  : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
827
- // USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
828
- offers = yield this.search(searchOffersConditions, params.projection, settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY);
835
+ // USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG対応(2023-09-06~)
836
+ offers = yield this.search(searchOffersConditions, params.projection, settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG);
829
837
  // 完全廃止(基本的にsortedOfferIdsと合わせて利用する想定)(2023-09-04~)
830
838
  // if (params.sort) {
831
839
  // // sorting
@@ -897,7 +905,7 @@ class MongoRepository {
897
905
  * 強制的にoffersコレクションを使用する
898
906
  */
899
907
  useOffersAsPrimary) {
900
- var _a;
908
+ var _a, _b;
901
909
  return __awaiter(this, void 0, void 0, function* () {
902
910
  // primaryコレクションをコントロール(2023-09-05~)
903
911
  const useAggregateOfferAsPrimary = settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY && (useOffersAsPrimary !== true);
@@ -920,8 +928,10 @@ class MongoRepository {
920
928
  }
921
929
  // tslint:disable-next-line:no-single-line-block-comment
922
930
  /* istanbul ignore else */
923
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) !== undefined) {
924
- query.sort({ 'priceSpecification.price': params.sort['priceSpecification.price'] });
931
+ if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) === 'number') {
932
+ query.sort(Object.assign({ 'priceSpecification.price': params.sort['priceSpecification.price'] }, (typeof ((_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier) === 'number')
933
+ ? { identifier: params.sort.identifier }
934
+ : undefined));
925
935
  }
926
936
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
927
937
  .exec()
@@ -1079,44 +1089,36 @@ class MongoRepository {
1079
1089
  if (params.addOn.itemOffered.id.$in.length === 0) {
1080
1090
  return;
1081
1091
  }
1082
- // tslint:disable-next-line:no-suspicious-comment
1083
- // TODO USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
1092
+ // USE_AGGREGATE_OFFERS_AS_PRIMARY対応(2023-09-05~)
1084
1093
  if (settings_1.USE_AGGREGATE_OFFERS_AS_PRIMARY) {
1085
- throw new factory.errors.NotImplemented('USE_AGGREGATE_OFFERS_AS_PRIMARY not implemented');
1086
- // const conditions: any = {
1087
- // 'project.id': { $eq: params.project.id },
1088
- // 'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
1089
- // };
1090
- // const updatingOffers = <Pick<factory.unitPriceOffer.IUnitPriceOffer, 'id'>[]>await this.searchFromAggregateOffer(
1091
- // {
1092
- // project: { id: { $eq: params.project.id } },
1093
- // addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
1094
- // },
1095
- // { id: 1 }
1096
- // );
1097
- // const result = await this.aggregateOfferModel.updateMany(
1098
- // conditions,
1099
- // {
1100
- // $pull: {
1101
- // 'offers.addOn': {
1102
- // 'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
1103
- // }
1104
- // }
1105
- // }
1106
- // )
1107
- // .exec();
1108
- // // 同期タスク作成(2023-09-05~)
1109
- // if (updatingOffers.length > 0) {
1110
- // await this.saveSyncTask({
1111
- // project: { id: params.project.id },
1112
- // id: { $in: updatingOffers.map((offer) => String(offer.id)) },
1113
- // identifier: { $in: [] },
1114
- // isDeleted: false,
1115
- // typeOf: factory.offerType.AggregateOffer,
1116
- // options: { emitImmediately: true }
1117
- // });
1118
- // }
1119
- // return result;
1094
+ const conditions = {
1095
+ 'project.id': { $eq: params.project.id },
1096
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
1097
+ };
1098
+ const updatingOffers = yield this.searchFromAggregateOffer({
1099
+ project: { id: { $eq: params.project.id } },
1100
+ addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
1101
+ }, { id: 1 });
1102
+ const result = yield this.aggregateOfferModel.updateMany(conditions, {
1103
+ $pull: {
1104
+ 'offers.addOn': {
1105
+ 'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
1106
+ }
1107
+ }
1108
+ })
1109
+ .exec();
1110
+ // 同期タスク作成(2023-09-05~)
1111
+ if (updatingOffers.length > 0) {
1112
+ yield this.saveSyncTask({
1113
+ project: { id: params.project.id },
1114
+ id: { $in: updatingOffers.map((offer) => String(offer.id)) },
1115
+ identifier: { $in: [] },
1116
+ isDeleted: false,
1117
+ typeOf: factory.offerType.AggregateOffer,
1118
+ options: { emitImmediately: true }
1119
+ });
1120
+ }
1121
+ return result;
1120
1122
  }
1121
1123
  else {
1122
1124
  const conditions = {
@@ -1393,7 +1395,7 @@ class MongoRepository {
1393
1395
  });
1394
1396
  }
1395
1397
  searchFromAggregateOffer(params, projection) {
1396
- var _a;
1398
+ var _a, _b;
1397
1399
  return __awaiter(this, void 0, void 0, function* () {
1398
1400
  const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
1399
1401
  const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
@@ -1406,7 +1408,13 @@ class MongoRepository {
1406
1408
  },
1407
1409
  ...matchStages,
1408
1410
  ...(typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) === 'number')
1409
- ? [{ $sort: { 'offers.priceSpecification.price': params.sort['priceSpecification.price'] } }]
1411
+ ? [
1412
+ {
1413
+ $sort: Object.assign({ 'offers.priceSpecification.price': params.sort['priceSpecification.price'] }, (typeof ((_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier) === 'number')
1414
+ ? { 'offers.identifier': params.sort.identifier }
1415
+ : undefined)
1416
+ }
1417
+ ]
1410
1418
  : [],
1411
1419
  { $project: projectStage }
1412
1420
  ]);
@@ -44,6 +44,7 @@ export declare const USE_CUSTOM_SENDER_EMAIL: boolean;
44
44
  export declare const USE_ORDER_PAYMENT_DUE_ON_PLACED: boolean;
45
45
  export declare const USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY: boolean;
46
46
  export declare const USE_AGGREGATE_OFFERS_AS_PRIMARY: boolean;
47
+ export declare const USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG: boolean;
47
48
  export declare const MONGO_MAX_TIME_MS: number;
48
49
  /**
49
50
  * グローバル設定
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = exports.MONGO_MAX_TIME_MS = exports.USE_AGGREGATE_OFFERS_AS_PRIMARY = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_CUSTOM_SENDER_EMAIL = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
3
+ exports.settings = exports.MONGO_MAX_TIME_MS = exports.USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG = exports.USE_AGGREGATE_OFFERS_AS_PRIMARY = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_CUSTOM_SENDER_EMAIL = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_ADVANCE_BOOKING_REQUIREMENT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("./factory");
6
6
  const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
@@ -76,6 +76,7 @@ exports.USE_CUSTOM_SENDER_EMAIL = process.env.USE_CUSTOM_SENDER_EMAIL === '1';
76
76
  exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = process.env.USE_ORDER_PAYMENT_DUE_ON_PLACED === '1';
77
77
  exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = process.env.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY === '1';
78
78
  exports.USE_AGGREGATE_OFFERS_AS_PRIMARY = process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY === '1';
79
+ exports.USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG = process.env.USE_AGGREGATE_OFFERS_AS_PRIMARY_ON_SEARCH_BY_CATALOG === '1';
79
80
  exports.MONGO_MAX_TIME_MS = (typeof process.env.MONGO_MAX_TIME_MS === 'string')
80
81
  ? Number(process.env.MONGO_MAX_TIME_MS)
81
82
  // tslint:disable-next-line:no-magic-numbers
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.329.0-alpha.6",
13
- "@cinerino/sdk": "3.166.0-alpha.5",
12
+ "@chevre/factory": "4.329.0-alpha.7",
13
+ "@cinerino/sdk": "3.166.0-alpha.7",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@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.8.0-alpha.35"
120
+ "version": "21.8.0-alpha.36"
121
121
  }