@chevre/domain 21.9.0-alpha.8 → 21.9.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.
Files changed (32) hide show
  1. package/example/src/chevre/searchAvaialbleAppliesToMovieTicketByOfferCatalogId.ts +4 -1
  2. package/example/src/chevre/searchEventTicketOffers.ts +1 -0
  3. package/example/src/chevre/searchOfferCatalogItemAvailability.ts +38 -0
  4. package/example/src/chevre/searchOfferCatalogItems.ts +41 -26
  5. package/example/src/chevre/searchOffers.ts +16 -4
  6. package/example/src/chevre/searchOffersByCatalog.ts +9 -3
  7. package/example/src/chevre/syncCatalogs2aggregateOffers.ts +23 -21
  8. package/lib/chevre/repo/aggregateOffer.d.ts +19 -3
  9. package/lib/chevre/repo/aggregateOffer.js +227 -27
  10. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +45 -45
  11. package/lib/chevre/repo/offer.d.ts +21 -13
  12. package/lib/chevre/repo/offer.js +145 -58
  13. package/lib/chevre/repo/offerCatalog.d.ts +11 -3
  14. package/lib/chevre/repo/offerCatalog.js +30 -15
  15. package/lib/chevre/repo/offerCatalogItem.d.ts +20 -1
  16. package/lib/chevre/repo/offerCatalogItem.js +67 -23
  17. package/lib/chevre/repo/task.d.ts +1 -1
  18. package/lib/chevre/service/assetTransaction/reserve.js +1 -0
  19. package/lib/chevre/service/offer/event/authorize.js +1 -0
  20. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +53 -7
  21. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +127 -6
  22. package/lib/chevre/service/offer/event.d.ts +2 -2
  23. package/lib/chevre/service/offer/event.js +3 -1
  24. package/lib/chevre/service/offer/product/searchProductOffers.js +4 -3
  25. package/lib/chevre/service/offer/product.js +3 -30
  26. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +3 -3
  27. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.d.ts +20 -0
  28. package/lib/chevre/service/task/onResourceUpdated/onOfferCatalogUpdated.js +28 -0
  29. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +15 -5
  30. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +45 -33
  31. package/lib/chevre/service/task/onResourceUpdated.js +2 -2
  32. package/package.json +3 -3
@@ -42,7 +42,6 @@ exports.schema = schema;
42
42
  schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
43
43
  schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
44
44
  schema.index({ 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersPriceSpecificationPrice' });
45
- schema.index({ 'project.id': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByProjectId' });
46
45
  // オファーIDはグローバルユニーク
47
46
  schema.index({ 'offers.id': 1 }, {
48
47
  name: 'uniqueOfferId',
@@ -59,130 +58,131 @@ schema.index({ 'includedInDataCatalog.id': 1 }, {
59
58
  'includedInDataCatalog.id': { $exists: true }
60
59
  }
61
60
  });
62
- schema.index({ 'offers.includedInDataCatalog.id': 1, 'offers.priceSpecification.price': 1 }, {
63
- name: 'searchByOffersIncludedInDataCatalogId',
61
+ schema.index({ 'offers.includedInDataCatalog.id': 1 }, {
62
+ name: 'searchByOffersIncludedInDataCatalogId-v2',
64
63
  partialFilterExpression: {
65
64
  'offers.includedInDataCatalog.id': { $exists: true }
66
65
  }
67
66
  });
68
- schema.index({ 'offers.availability': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersAvailability' });
69
- schema.index({ 'offers.itemOffered.typeOf': 1, 'offers.priceSpecification.price': 1 }, { name: 'searchByOffersItemOfferedTypeOf' });
70
- schema.index({ 'offers.identifier': 1, 'offers.priceSpecification.price': 1 }, {
71
- name: 'searchByOffersIdentifier',
67
+ schema.index({ 'project.id': 1 }, { name: 'searchByProjectId-v2' });
68
+ schema.index({ 'offers.availability': 1 }, { name: 'searchByOffersAvailability-v2' });
69
+ schema.index({ 'offers.itemOffered.typeOf': 1 }, { name: 'searchByOffersItemOfferedTypeOf-v2' });
70
+ schema.index({ 'offers.identifier': 1 }, {
71
+ name: 'searchByOffersIdentifier-v2',
72
72
  partialFilterExpression: {
73
73
  'offers.identifier': { $exists: true }
74
74
  }
75
75
  });
76
- schema.index({ 'offers.priceSpecification.referenceQuantity.value': 1, 'offers.priceSpecification.price': 1 }, {
77
- name: 'searchByOffersPriceSpecificationReferenceQuantityValue',
76
+ schema.index({ 'offers.priceSpecification.referenceQuantity.value': 1 }, {
77
+ name: 'searchByOffersPriceSpecificationReferenceQuantityValue-v2',
78
78
  partialFilterExpression: {
79
79
  'offers.priceSpecification.referenceQuantity.value': { $exists: true }
80
80
  }
81
81
  });
82
- schema.index({ 'offers.priceSpecification.accounting.accountsReceivable': 1, 'offers.priceSpecification.price': 1 }, {
83
- name: 'searchByOffersPriceSpecificationAccountingAccountsReceivable',
82
+ schema.index({ 'offers.priceSpecification.accounting.accountsReceivable': 1 }, {
83
+ name: 'searchByOffersPriceSpecificationAccountingAccountsReceivable-v2',
84
84
  partialFilterExpression: {
85
85
  'offers.priceSpecification.accounting.accountsReceivable': { $exists: true }
86
86
  }
87
87
  });
88
- schema.index({ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
89
- name: 'searchByOffersPriceSpecificationAccountingOperatingRevenueCodeValue',
88
+ schema.index({ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': 1 }, {
89
+ name: 'searchByOffersPriceSpecificationAccountingOperatingRevenueCodeValue-v2',
90
90
  partialFilterExpression: {
91
91
  'offers.priceSpecification.accounting.operatingRevenue.codeValue': { $exists: true }
92
92
  }
93
93
  });
94
- schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceType': 1, 'offers.priceSpecification.price': 1 }, {
95
- name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceType',
94
+ schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceType': 1 }, {
95
+ name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceType-v2',
96
96
  partialFilterExpression: {
97
97
  'offers.priceSpecification.appliesToMovieTicket.serviceType': { $exists: true }
98
98
  }
99
99
  });
100
- schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': 1, 'offers.priceSpecification.price': 1 }, {
101
- name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceOutputTypeOf',
100
+ schema.index({ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': 1 }, {
101
+ name: 'searchByOffersPriceSpecificationAppliesToMovieTicketServiceOutputTypeOf-v2',
102
102
  partialFilterExpression: {
103
103
  'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': { $exists: true }
104
104
  }
105
105
  });
106
- schema.index({ 'offers.name.ja': 1, 'offers.priceSpecification.price': 1 }, {
107
- name: 'searchByOffersNameJa',
106
+ schema.index({ 'offers.name.ja': 1 }, {
107
+ name: 'searchByOffersNameJa-v2',
108
108
  partialFilterExpression: {
109
109
  'offers.name.ja': { $exists: true }
110
110
  }
111
111
  });
112
- schema.index({ 'offers.name.en': 1, 'offers.priceSpecification.price': 1 }, {
113
- name: 'searchByOffersNameEn',
112
+ schema.index({ 'offers.name.en': 1 }, {
113
+ name: 'searchByOffersNameEn-v2',
114
114
  partialFilterExpression: {
115
115
  'offers.name.en': { $exists: true }
116
116
  }
117
117
  });
118
- schema.index({ 'offers.alternateName': 1, 'offers.priceSpecification.price': 1 }, {
119
- name: 'searchByOffersAlternateName',
118
+ schema.index({ 'offers.alternateName': 1 }, {
119
+ name: 'searchByOffersAlternateName-v2',
120
120
  partialFilterExpression: {
121
121
  'offers.alternateName': { $exists: true }
122
122
  }
123
123
  });
124
- schema.index({ 'offers.category.id': 1, 'offers.priceSpecification.price': 1 }, {
125
- name: 'searchOffersCategoryId',
124
+ schema.index({ 'offers.category.id': 1 }, {
125
+ name: 'searchOffersCategoryId-v2',
126
126
  partialFilterExpression: {
127
127
  'offers.category.id': { $exists: true }
128
128
  }
129
129
  });
130
- schema.index({ 'offers.category.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
131
- name: 'searchByOffersCategoryCodeValue',
130
+ schema.index({ 'offers.category.codeValue': 1 }, {
131
+ name: 'searchByOffersCategoryCodeValue-v2',
132
132
  partialFilterExpression: {
133
133
  'offers.category.codeValue': { $exists: true }
134
134
  }
135
135
  });
136
- schema.index({ 'offers.availableAtOrFrom.id': 1, 'offers.priceSpecification.price': 1 }, {
137
- name: 'searchByOffersAvailableAtOrFromId',
136
+ schema.index({ 'offers.availableAtOrFrom.id': 1 }, {
137
+ name: 'searchByOffersAvailableAtOrFromId-v2',
138
138
  partialFilterExpression: {
139
139
  'offers.availableAtOrFrom.id': { $exists: true }
140
140
  }
141
141
  });
142
- schema.index({ 'offers.eligibleMembershipType.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
143
- name: 'searchByOffersEligibleMembershipTypeCodeValue',
142
+ schema.index({ 'offers.eligibleMembershipType.codeValue': 1 }, {
143
+ name: 'searchByOffersEligibleMembershipTypeCodeValue-v2',
144
144
  partialFilterExpression: {
145
145
  'offers.eligibleMembershipType.codeValue': { $exists: true }
146
146
  }
147
147
  });
148
- schema.index({ 'offers.eligibleMonetaryAmount.currency': 1, 'offers.priceSpecification.price': 1 }, {
149
- name: 'searchByOffersEligibleMonetaryAmountCurrency',
148
+ schema.index({ 'offers.eligibleMonetaryAmount.currency': 1 }, {
149
+ name: 'searchByOffersEligibleMonetaryAmountCurrency-v2',
150
150
  partialFilterExpression: {
151
151
  'offers.eligibleMonetaryAmount.currency': { $exists: true }
152
152
  }
153
153
  });
154
- schema.index({ 'offers.eligibleSeatingType.codeValue': 1, 'offers.priceSpecification.price': 1 }, {
155
- name: 'searchByOffersEligibleSeatingTypeCodeValue',
154
+ schema.index({ 'offers.eligibleSeatingType.codeValue': 1 }, {
155
+ name: 'searchByOffersEligibleSeatingTypeCodeValue-v2',
156
156
  partialFilterExpression: {
157
157
  'offers.eligibleSeatingType.codeValue': { $exists: true }
158
158
  }
159
159
  });
160
- schema.index({ 'offers.addOn.itemOffered.id': 1, 'offers.priceSpecification.price': 1 }, {
161
- name: 'searchByOffersAddOnItemOfferedId',
160
+ schema.index({ 'offers.addOn.itemOffered.id': 1 }, {
161
+ name: 'searchByOffersAddOnItemOfferedId-v2',
162
162
  partialFilterExpression: {
163
163
  'offers.addOn.itemOffered.id': { $exists: true }
164
164
  }
165
165
  });
166
- schema.index({ 'offers.hasMerchantReturnPolicy.id': 1, 'offers.priceSpecification.price': 1 }, {
167
- name: 'searchByOffersHasMerchantReturnPolicyId',
166
+ schema.index({ 'offers.hasMerchantReturnPolicy.id': 1 }, {
167
+ name: 'searchByOffersHasMerchantReturnPolicyId-v2',
168
168
  partialFilterExpression: {
169
169
  'offers.hasMerchantReturnPolicy.id': { $exists: true }
170
170
  }
171
171
  });
172
- schema.index({ 'offers.additionalProperty': 1, 'offers.priceSpecification.price': 1 }, {
173
- name: 'searchByOffersAdditionalProperty',
172
+ schema.index({ 'offers.additionalProperty': 1 }, {
173
+ name: 'searchByOffersAdditionalProperty-v2',
174
174
  partialFilterExpression: {
175
175
  'offers.additionalProperty': { $exists: true }
176
176
  }
177
177
  });
178
- schema.index({ 'offers.validFrom': 1, 'offers.priceSpecification.price': 1 }, {
179
- name: 'searchByOffersValidFrom',
178
+ schema.index({ 'offers.validFrom': 1 }, {
179
+ name: 'searchByOffersValidFrom-v2',
180
180
  partialFilterExpression: {
181
181
  'offers.validFrom': { $exists: true }
182
182
  }
183
183
  });
184
- schema.index({ 'offers.validThrough': 1, 'offers.priceSpecification.price': 1 }, {
185
- name: 'searchByOffersValidThrough',
184
+ schema.index({ 'offers.validThrough': 1 }, {
185
+ name: 'searchByOffersValidThrough-v2',
186
186
  partialFilterExpression: {
187
187
  'offers.validThrough': { $exists: true }
188
188
  }
@@ -40,10 +40,10 @@ export declare class MongoRepository {
40
40
  offers: IUnitPriceOfferFromAggregateOffer[];
41
41
  }>;
42
42
  /**
43
- * 単価オファーIDとカタログIDで単価オファーを検索する
44
- * 必ずカタログデータから単価オファーIDを参照する
43
+ * 単価オファーIDとカタログIDで単価オファーを全て検索する
44
+ * 単価オファーIDを一定数指定する想定なのでpagingは不要
45
45
  */
46
- searchByIdsAndOfferCatalogId(params: {
46
+ searchAllByIdsAndOfferCatalogId(params: {
47
47
  /**
48
48
  * 指定したIDの単価オファーだけ取得
49
49
  */
@@ -61,8 +61,6 @@ export declare class MongoRepository {
61
61
  unacceptedPaymentMethod?: string[];
62
62
  excludeAppliesToMovieTicket: boolean;
63
63
  onlyValid?: boolean;
64
- limit?: number;
65
- page?: number;
66
64
  projection?: IProjection;
67
65
  }): Promise<{
68
66
  offers: IUnitPriceOfferFromAggregateOffer[];
@@ -84,6 +82,10 @@ export declare class MongoRepository {
84
82
  };
85
83
  unacceptedPaymentMethod?: string[];
86
84
  excludeAppliesToMovieTicket: boolean;
85
+ /**
86
+ * 適用決済カード条件
87
+ */
88
+ priceSpecification: Pick<factory.unitPriceOffer.IPriceSpecificationSearchConditions, 'appliesToMovieTicket'>;
87
89
  onlyValid?: boolean;
88
90
  useIncludeInDataCatalog: boolean;
89
91
  limit?: number;
@@ -105,22 +107,34 @@ export declare class MongoRepository {
105
107
  * サブカタログID
106
108
  */
107
109
  id: string;
110
+ isOfferCatalogItem: boolean;
108
111
  };
109
112
  availableAtOrFrom?: {
110
113
  id?: string;
111
114
  };
112
115
  unacceptedPaymentMethod?: string[];
113
116
  excludeAppliesToMovieTicket: boolean;
117
+ useIncludeInDataCatalog: boolean;
114
118
  onlyValid?: boolean;
115
119
  limit?: number;
116
120
  page?: number;
117
121
  }): Promise<Pick<factory.priceSpecification.unitPrice.IAppliesToMovieTicket, 'serviceOutput'>[]>;
118
- findAggregateOfferById(params: {
122
+ /**
123
+ * クライアントの利用可能カタログを検索する
124
+ */
125
+ searchAvailableCatalogs(params: {
119
126
  project: {
120
127
  id: string;
121
128
  };
129
+ includedInDataCatalog: {
130
+ id: string[];
131
+ };
132
+ availableAtOrFrom: {
133
+ id: string;
134
+ };
135
+ }): Promise<{
122
136
  id: string;
123
- }): Promise<factory.aggregateOffer.IAggregateOffer>;
137
+ }[]>;
124
138
  count(params: Omit<factory.unitPriceOffer.ISearchConditions, 'limit' | 'page' | 'sort'>): Promise<number>;
125
139
  search(params: factory.unitPriceOffer.ISearchConditions, projection?: IProjection): Promise<IUnitPriceOfferFromAggregateOffer[]>;
126
140
  save(params: factory.unitPriceOffer.IUnitPriceOffer & {
@@ -148,12 +162,6 @@ export declare class MongoRepository {
148
162
  };
149
163
  };
150
164
  }): Promise<import("mongodb").UpdateResult | undefined>;
151
- deleteById(params: {
152
- project: {
153
- id: string;
154
- };
155
- id: string;
156
- }): Promise<void>;
157
165
  /**
158
166
  * サブカタログから集計オファーIDリストを検索する
159
167
  */
@@ -21,12 +21,14 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
+ const createDebug = require("debug");
24
25
  const mongoose_1 = require("mongoose");
25
26
  const uniqid = require("uniqid");
26
27
  const factory = require("../factory");
27
28
  const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
28
29
  const offerCatalog_1 = require("./mongoose/schemas/offerCatalog");
29
30
  const offerCatalogItem_1 = require("./mongoose/schemas/offerCatalogItem");
31
+ const debug = createDebug('chevre-domain:repo:offer');
30
32
  const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
31
33
  /**
32
34
  * 単価オファーリポジトリ
@@ -51,10 +53,25 @@ class MongoRepository {
51
53
  if (Array.isArray(parentOfferIdIn)) {
52
54
  matchStages.push({ $match: { _id: { $in: parentOfferIdIn } } });
53
55
  }
56
+ // aggregateOffer.includedInDataCatalogで検索する(2023-09-21~)
54
57
  const includedInDataCatalogIdIn = (_f = (_e = params.includedInDataCatalog) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$in;
58
+ // if (Array.isArray(includedInDataCatalogIdIn)) {
59
+ // matchStages.push({ $match: { 'offers.includedInDataCatalog.id': { $exists: true, $in: includedInDataCatalogIdIn } } });
60
+ // }
55
61
  if (Array.isArray(includedInDataCatalogIdIn)) {
56
- matchStages.push({ $match: { 'offers.includedInDataCatalog.id': { $exists: true, $in: includedInDataCatalogIdIn } } });
62
+ matchStages.push({ $match: { 'includedInDataCatalog.id': { $exists: true, $in: includedInDataCatalogIdIn } } });
57
63
  }
64
+ // const includedInOfferCatalogItemIncludedInDataCatalogIdIn = params.includedInOfferCatalogItem?.includedInDataCatalog?.id?.$in;
65
+ // if (Array.isArray(includedInOfferCatalogItemIncludedInDataCatalogIdIn)) {
66
+ // matchStages.push({
67
+ // $match: {
68
+ // 'offers.includedInOfferCatalogItem.includedInDataCatalog.id': {
69
+ // $exists: true,
70
+ // $in: includedInOfferCatalogItemIncludedInDataCatalogIdIn
71
+ // }
72
+ // }
73
+ // });
74
+ // }
58
75
  const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
59
76
  if (typeof idEq === 'string') {
60
77
  matchStages.push({
@@ -459,29 +476,33 @@ class MongoRepository {
459
476
  });
460
477
  }
461
478
  /**
462
- * 単価オファーIDとカタログIDで単価オファーを検索する
463
- * 必ずカタログデータから単価オファーIDを参照する
479
+ * 単価オファーIDとカタログIDで単価オファーを全て検索する
480
+ * 単価オファーIDを一定数指定する想定なのでpagingは不要
464
481
  */
465
- searchByIdsAndOfferCatalogId(params) {
482
+ searchAllByIdsAndOfferCatalogId(params) {
466
483
  var _a;
467
484
  return __awaiter(this, void 0, void 0, function* () {
468
- const unitPriceOfferIds = params.ids;
469
- let aggregateOfferIds; // 集計オファーIDでフィルターする場合
470
- if (Array.isArray(unitPriceOfferIds)) {
471
- // 解釈を集計オファーIDに変更する必要がある(2023-09-11~)
472
- // 単価オファーIDリスト→集計オファーIDに変換→カタログ条件にセット
473
- const searchDistinctAggregateOfferIdsResult = yield this.aggregateOfferModel.distinct('_id', { 'offers.id': { $in: unitPriceOfferIds } })
474
- .exec();
475
- aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
485
+ if (!Array.isArray(params.ids) || params.ids.length === 0) {
486
+ throw new factory.errors.ArgumentNull('offer.ids');
487
+ }
488
+ // 解釈を集計オファーIDに変更する必要がある(2023-09-11~)
489
+ // 単価オファーIDリスト→集計オファーIDに変換→カタログ条件にセット
490
+ const aggregateOfferIds = yield this.aggregateOfferModel.distinct('_id', { 'offers.id': { $in: params.ids } })
491
+ .exec();
492
+ if (aggregateOfferIds.length === 0) {
493
+ throw new factory.errors.NotFound(factory.offerType.AggregateOffer);
476
494
  }
477
- const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog(Object.assign({ id: params.subOfferCatalog.id, isOfferCatalogItem: params.subOfferCatalog.isOfferCatalogItem }, (Array.isArray(aggregateOfferIds)) ? { itemListElementIds: aggregateOfferIds } : undefined));
495
+ const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
496
+ id: params.subOfferCatalog.id,
497
+ isOfferCatalogItem: params.subOfferCatalog.isOfferCatalogItem,
498
+ itemListElementIds: aggregateOfferIds
499
+ });
478
500
  let offers = [];
479
501
  if (sortedOfferIds.length > 0) {
480
- const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
502
+ debug('searchAllByIdsAndOfferCatalogId:searching offers...,sortedOfferIds:', sortedOfferIds, 'ids:', params.ids);
503
+ const searchOffersConditions = Object.assign({
481
504
  // aggregateOffer.idで検索する(2023-09-09~)
482
- parentOffer: { id: { $in: sortedOfferIds } } }, (Array.isArray(unitPriceOfferIds)) ? { id: { $in: unitPriceOfferIds } } : undefined), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
483
- ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
484
- : undefined), { priceSpecification: {
505
+ parentOffer: { id: { $in: sortedOfferIds } }, id: { $in: params.ids }, priceSpecification: {
485
506
  appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
486
507
  ? {
487
508
  serviceOutput: {
@@ -493,10 +514,16 @@ class MongoRepository {
493
514
  serviceType: { $exists: false }
494
515
  }
495
516
  : undefined)
496
- }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
497
- // 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
498
- ? { sort: { identifier: factory.sortType.Ascending } }
499
- : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
517
+ }, onlyValid: params.onlyValid === true }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
518
+ ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } } // store.idでのフィルターをmongoで処理(2023-01-27~)
519
+ : undefined
520
+ // ...(typeof params.limit === 'number' && typeof params.page === 'number')
521
+ // // 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
522
+ // ? { sort: { identifier: factory.sortType.Ascending } }
523
+ // : undefined,
524
+ // ...(typeof params.limit === 'number') ? { limit: params.limit } : undefined,
525
+ // ...(typeof params.page === 'number') ? { page: params.page } : undefined
526
+ );
500
527
  offers = yield this.search(searchOffersConditions, params.projection);
501
528
  }
502
529
  return { offers };
@@ -507,7 +534,7 @@ class MongoRepository {
507
534
  * カタログ内ソートインデックスはsortedOfferIdsで判断する
508
535
  */
509
536
  searchByOfferCatalogIdWithSortIndex(params) {
510
- var _a;
537
+ var _a, _b, _c, _d, _e, _f, _g, _h;
511
538
  return __awaiter(this, void 0, void 0, function* () {
512
539
  const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
513
540
  id: params.subOfferCatalog.id,
@@ -515,23 +542,30 @@ class MongoRepository {
515
542
  });
516
543
  let offers = [];
517
544
  if (sortedOfferIds.length > 0) {
518
- const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
545
+ const appliesToMovieTicketServiceOutputTypeOfEq = (_d = (_c = (_b = (_a = params.priceSpecification) === null || _a === void 0 ? void 0 : _a.appliesToMovieTicket) === null || _b === void 0 ? void 0 : _b.serviceOutput) === null || _c === void 0 ? void 0 : _c.typeOf) === null || _d === void 0 ? void 0 : _d.$eq;
546
+ const appliesToMovieTicketServiceTypeExists = (_g = (_f = (_e = params.priceSpecification) === null || _e === void 0 ? void 0 : _e.appliesToMovieTicket) === null || _f === void 0 ? void 0 : _f.serviceType) === null || _g === void 0 ? void 0 : _g.$exists;
547
+ // 適用決済カード条件なしのみを検索するかどうか
548
+ const onlyNoAppliesToMovieTicket = params.excludeAppliesToMovieTicket || (appliesToMovieTicketServiceTypeExists === false);
549
+ const onlyAppliesToMovieTicket = !params.excludeAppliesToMovieTicket && (appliesToMovieTicketServiceTypeExists === true);
550
+ const priceSpecificationConditions = {
551
+ appliesToMovieTicket: Object.assign(Object.assign({ serviceOutput: {
552
+ typeOf: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
553
+ // 利用不可決済方法区分条件を追加(2023-02-21~)
554
+ ? { $nin: params.unacceptedPaymentMethod }
555
+ : undefined), (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string')
556
+ ? { $eq: appliesToMovieTicketServiceOutputTypeOfEq }
557
+ : undefined)
558
+ } }, (onlyNoAppliesToMovieTicket)
559
+ ? { serviceType: { $exists: false } }
560
+ : undefined), (onlyAppliesToMovieTicket)
561
+ ? { serviceType: { $exists: true } }
562
+ : undefined)
563
+ };
564
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ priceSpecification: priceSpecificationConditions, onlyValid: params.onlyValid === true }, (params.useIncludeInDataCatalog)
519
565
  ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
520
- : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
566
+ : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_h = params.availableAtOrFrom) === null || _h === void 0 ? void 0 : _h.id) === 'string')
521
567
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } } // store.idでのフィルターをmongoで処理(2023-01-27~)
522
- : undefined), { priceSpecification: {
523
- appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
524
- ? {
525
- serviceOutput: {
526
- typeOf: { $nin: params.unacceptedPaymentMethod }
527
- }
528
- }
529
- : undefined), (params.excludeAppliesToMovieTicket)
530
- ? {
531
- serviceType: { $exists: false }
532
- }
533
- : undefined)
534
- }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
568
+ : undefined), (typeof params.limit === 'number' && typeof params.page === 'number')
535
569
  // 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
536
570
  ? { sort: { identifier: factory.sortType.Ascending } }
537
571
  : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
@@ -546,7 +580,17 @@ class MongoRepository {
546
580
  searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params) {
547
581
  var _a;
548
582
  return __awaiter(this, void 0, void 0, function* () {
549
- const searchOffersConditions = Object.assign(Object.assign({ includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
583
+ let sortedOfferIds = [];
584
+ if (!params.useIncludeInDataCatalog) {
585
+ // useIncludeInDataCatalogでない場合のみ集計オファーIDリストを検索する
586
+ sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
587
+ id: params.subOfferCatalog.id,
588
+ isOfferCatalogItem: params.subOfferCatalog.isOfferCatalogItem
589
+ });
590
+ }
591
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
592
+ ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
593
+ : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
550
594
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
551
595
  : undefined), { priceSpecification: {
552
596
  appliesToMovieTicket: Object.assign({
@@ -582,23 +626,62 @@ class MongoRepository {
582
626
  return aggregate.exec();
583
627
  });
584
628
  }
585
- findAggregateOfferById(params) {
629
+ /**
630
+ * クライアントの利用可能カタログを検索する
631
+ */
632
+ searchAvailableCatalogs(params) {
586
633
  return __awaiter(this, void 0, void 0, function* () {
587
- const doc = yield this.aggregateOfferModel.findOne({
588
- _id: { $eq: params.id },
589
- 'project.id': { $eq: params.project.id }
590
- }, {
591
- __v: 0,
592
- createdAt: 0,
593
- updatedAt: 0
594
- })
595
- .exec();
596
- if (doc === null) {
597
- throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
598
- }
599
- return doc.toObject();
634
+ const aggregate = this.aggregateOfferModel.aggregate([
635
+ { $unwind: { path: '$offers' } },
636
+ // { $unwind: { path: '$offers.includedInDataCatalog' } },
637
+ { $unwind: { path: '$includedInDataCatalog' } },
638
+ {
639
+ $match: {
640
+ 'project.id': { $eq: params.project.id },
641
+ // 'offers.includedInDataCatalog.id': { $exists: true, $in: params.includedInDataCatalog.id },
642
+ 'includedInDataCatalog.id': { $exists: true, $in: params.includedInDataCatalog.id },
643
+ 'offers.availableAtOrFrom.id': { $exists: true, $eq: params.availableAtOrFrom.id }
644
+ }
645
+ },
646
+ {
647
+ $group: {
648
+ // _id: '$offers.includedInDataCatalog.id',
649
+ // includedInDataCatalog: { $first: '$offers.includedInDataCatalog' }
650
+ _id: '$includedInDataCatalog.id'
651
+ // includedInDataCatalog: { $first: '$includedInDataCatalog' }
652
+ }
653
+ },
654
+ {
655
+ $project: {
656
+ _id: 0,
657
+ id: '$_id'
658
+ }
659
+ }
660
+ ]);
661
+ return aggregate.exec();
600
662
  });
601
663
  }
664
+ // public async findAggregateOfferById(params: {
665
+ // project: { id: string };
666
+ // id: string;
667
+ // }): Promise<factory.aggregateOffer.IAggregateOffer> {
668
+ // const doc = await this.aggregateOfferModel.findOne(
669
+ // {
670
+ // _id: { $eq: params.id },
671
+ // 'project.id': { $eq: params.project.id }
672
+ // },
673
+ // {
674
+ // __v: 0,
675
+ // createdAt: 0,
676
+ // updatedAt: 0
677
+ // }
678
+ // )
679
+ // .exec();
680
+ // if (doc === null) {
681
+ // throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
682
+ // }
683
+ // return doc.toObject();
684
+ // }
602
685
  count(params) {
603
686
  return __awaiter(this, void 0, void 0, function* () {
604
687
  const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
@@ -790,12 +873,16 @@ class MongoRepository {
790
873
  return result;
791
874
  });
792
875
  }
793
- deleteById(params) {
794
- return __awaiter(this, void 0, void 0, function* () {
795
- yield this.aggregateOfferModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
796
- .exec();
797
- });
798
- }
876
+ // public async deleteById(params: {
877
+ // project: { id: string };
878
+ // id: string;
879
+ // }) {
880
+ // await this.aggregateOfferModel.findOneAndRemove(
881
+ // { _id: { $eq: params.id } },
882
+ // { projection: { _id: 1 } }
883
+ // )
884
+ // .exec();
885
+ // }
799
886
  /**
800
887
  * サブカタログから集計オファーIDリストを検索する
801
888
  */
@@ -82,9 +82,6 @@ export declare class MongoRepository {
82
82
  };
83
83
  }): Promise<import("mongodb").UpdateResult | undefined>;
84
84
  search(params: factory.offerCatalog.ISearchConditions): Promise<IAggregatedOfferCatalog[]>;
85
- /**
86
- * 強制的に親カタログのみ検索する
87
- */
88
85
  findItemListElementById(params: {
89
86
  id: string;
90
87
  project: {
@@ -97,6 +94,17 @@ export declare class MongoRepository {
97
94
  findFirstItemListElementById(params: {
98
95
  id: string;
99
96
  }): Promise<factory.offerCatalog.IItemListElement>;
97
+ /**
98
+ * カタログのitemListElementをpaging有で検索する
99
+ */
100
+ searchItemListElementById(params: {
101
+ id: string;
102
+ limit: number;
103
+ page: number;
104
+ }): Promise<{
105
+ id: string;
106
+ elementIndex: number;
107
+ }[]>;
100
108
  deleteById(params: {
101
109
  id: string;
102
110
  }): Promise<void>;
@@ -270,7 +270,8 @@ class MongoRepository {
270
270
  }
271
271
  },
272
272
  // itemListElement.typeOfを追加(2023-09-14~)
273
- itemListElementTypeOf: { $first: '$itemListElement.typeOf' }
273
+ itemListElementTypeOf: { $first: '$itemListElement.typeOf' },
274
+ dateSynced: '$dateSynced'
274
275
  }
275
276
  }
276
277
  ]);
@@ -282,20 +283,6 @@ class MongoRepository {
282
283
  return aggregate.exec();
283
284
  });
284
285
  }
285
- /**
286
- * 強制的に親カタログのみ検索する
287
- */
288
- // public async searchParentCatalogsForcibly(
289
- // params: factory.offerCatalog.ISearchConditions
290
- // ): Promise<IAggregatedOfferCatalog[]> {
291
- // return this.search({
292
- // ...params,
293
- // itemListElement: {
294
- // ...params.itemListElement,
295
- // typeOf: { $eq: factory.offerType.Offer }
296
- // }
297
- // });
298
- // }
299
286
  findItemListElementById(params) {
300
287
  return __awaiter(this, void 0, void 0, function* () {
301
288
  const doc = yield this.offerCatalogModel.findOne({
@@ -333,6 +320,34 @@ class MongoRepository {
333
320
  return firstElement;
334
321
  });
335
322
  }
323
+ /**
324
+ * カタログのitemListElementをpaging有で検索する
325
+ */
326
+ searchItemListElementById(params) {
327
+ return __awaiter(this, void 0, void 0, function* () {
328
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
329
+ const matchStages = [{ $match: { _id: { $eq: params.id } } }];
330
+ return this.offerCatalogModel.aggregate([
331
+ {
332
+ $unwind: {
333
+ path: '$itemListElement',
334
+ includeArrayIndex: 'elementIndex'
335
+ }
336
+ },
337
+ ...matchStages,
338
+ {
339
+ $project: {
340
+ _id: 0,
341
+ id: '$itemListElement.id',
342
+ elementIndex: '$elementIndex'
343
+ }
344
+ }
345
+ ])
346
+ .limit(params.limit * page)
347
+ .skip(params.limit * (page - 1))
348
+ .exec();
349
+ });
350
+ }
336
351
  deleteById(params) {
337
352
  return __awaiter(this, void 0, void 0, function* () {
338
353
  yield this.offerCatalogModel.findOneAndRemove({