@chevre/domain 21.8.0-alpha.9 → 21.9.0-alpha.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 (132) hide show
  1. package/example/src/chevre/countOffers.ts +32 -0
  2. package/example/src/chevre/findItemListElementByCatalogId.ts +30 -0
  3. package/example/src/chevre/importOffersFromCOA.ts +7 -1
  4. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  5. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  6. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -0
  7. package/example/src/chevre/optimizeCatalogs.ts +54 -0
  8. package/example/src/chevre/processPay.ts +3 -4
  9. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +56 -0
  10. package/example/src/chevre/pullAddOnsFromOffer.ts +26 -0
  11. package/example/src/chevre/pushIncludedInDataCatalog.ts +47 -0
  12. package/example/src/chevre/searchAggregateOffers.ts +48 -0
  13. package/example/src/chevre/searchAvaialbleAppliesToMovieTicketByOfferCatalogId.ts +26 -0
  14. package/example/src/chevre/searchEventTicketOffers.ts +5 -1
  15. package/example/src/chevre/searchEvents.ts +9 -7
  16. package/example/src/chevre/searchOfferCatalogs.ts +7 -3
  17. package/example/src/chevre/searchOffers.ts +5 -2
  18. package/example/src/chevre/searchOffersByCatalog.ts +15 -9
  19. package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
  20. package/example/src/chevre/searchOrders.ts +9 -7
  21. package/example/src/chevre/syncCatalogs2aggregateOffers.ts +85 -0
  22. package/lib/chevre/emailMessageBuilder.js +6 -5
  23. package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
  24. package/lib/chevre/repo/aggregateOffer.js +562 -0
  25. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  26. package/lib/chevre/repo/assetTransaction.js +54 -2
  27. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
  28. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +189 -0
  29. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
  30. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
  31. package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
  32. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +3 -0
  33. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +10 -1
  34. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  35. package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
  36. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
  37. package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
  38. package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
  39. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  40. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  41. package/lib/chevre/repo/offer.d.ts +106 -51
  42. package/lib/chevre/repo/offer.js +555 -283
  43. package/lib/chevre/repo/offerCatalog.d.ts +32 -3
  44. package/lib/chevre/repo/offerCatalog.js +97 -10
  45. package/lib/chevre/repo/order.d.ts +15 -0
  46. package/lib/chevre/repo/order.js +58 -26
  47. package/lib/chevre/repo/task.d.ts +6 -2
  48. package/lib/chevre/repo/task.js +58 -4
  49. package/lib/chevre/repository.d.ts +3 -0
  50. package/lib/chevre/repository.js +5 -1
  51. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +3 -41
  52. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.d.ts +2 -0
  53. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -40
  54. package/lib/chevre/service/aggregation/event/findEventOffers.d.ts +16 -0
  55. package/lib/chevre/service/aggregation/event/findEventOffers.js +58 -0
  56. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  57. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  58. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  59. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  60. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  61. package/lib/chevre/service/assetTransaction/registerService.js +2 -1
  62. package/lib/chevre/service/assetTransaction/reserve.js +111 -35
  63. package/lib/chevre/service/offer/event/authorize.js +39 -35
  64. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  65. package/lib/chevre/service/offer/event/factory.js +8 -8
  66. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  67. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +3 -0
  68. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +48 -17
  69. package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
  70. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  71. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
  72. package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
  73. package/lib/chevre/service/offer/factory.d.ts +12 -4
  74. package/lib/chevre/service/offer/factory.js +9 -11
  75. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +10 -1
  76. package/lib/chevre/service/offer/product/searchProductOffers.js +51 -12
  77. package/lib/chevre/service/offer/product.d.ts +2 -0
  78. package/lib/chevre/service/offer/product.js +3 -2
  79. package/lib/chevre/service/offer.d.ts +1 -0
  80. package/lib/chevre/service/offer.js +7 -1
  81. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  82. package/lib/chevre/service/order/confirmPayTransaction.js +20 -46
  83. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  84. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  85. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  86. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  87. package/lib/chevre/service/order/onOrderStatusChanged.js +49 -9
  88. package/lib/chevre/service/order/payOrder.js +4 -45
  89. package/lib/chevre/service/order/placeOrder.js +11 -24
  90. package/lib/chevre/service/order.d.ts +3 -1
  91. package/lib/chevre/service/order.js +6 -2
  92. package/lib/chevre/service/payment/any/factory.js +33 -8
  93. package/lib/chevre/service/payment/any.js +30 -21
  94. package/lib/chevre/service/payment/creditCard.js +12 -12
  95. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  96. package/lib/chevre/service/payment/movieTicket.js +10 -11
  97. package/lib/chevre/service/payment/paymentCard.js +9 -12
  98. package/lib/chevre/service/project.js +1 -1
  99. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  100. package/lib/chevre/service/reserve/checkInReservation.js +3 -2
  101. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  102. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
  103. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
  104. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
  105. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  106. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  107. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
  108. package/lib/chevre/service/task/aggregateUseActionsOnEvent.js +2 -0
  109. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  110. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  111. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  112. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  113. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
  114. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  115. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
  116. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
  117. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +78 -0
  118. package/lib/chevre/service/task/onResourceUpdated.js +12 -0
  119. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  120. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  121. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  122. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  123. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  124. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  125. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  126. package/lib/chevre/settings.d.ts +3 -3
  127. package/lib/chevre/settings.js +4 -12
  128. package/package.json +3 -3
  129. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  130. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
  131. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +0 -149
  132. package/lib/chevre/repo/mongoose/schemas/offer.js +0 -210
@@ -23,354 +23,459 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
24
  const uniqid = require("uniqid");
25
25
  const factory = require("../factory");
26
- const offer_1 = require("./mongoose/schemas/offer");
26
+ const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
27
27
  const offerCatalog_1 = require("./mongoose/schemas/offerCatalog");
28
- const settings_1 = require("../settings");
28
+ const OFFERS_ARRAY_INDEX_NAME = 'offerIndex';
29
29
  /**
30
- * オファーリポジトリ
30
+ * 単価オファーリポジトリ
31
31
  */
32
32
  class MongoRepository {
33
33
  constructor(connection) {
34
- this.offerModel = connection.model(offer_1.modelName, offer_1.schema);
34
+ this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
35
35
  this.offerCatalogModel = connection.model(offerCatalog_1.modelName, offerCatalog_1.schema);
36
36
  }
37
37
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
- static CREATE_OFFER_MONGO_CONDITIONS(params) {
39
- 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;
40
- // MongoDB検索条件
41
- const andConditions = [];
38
+ static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
39
+ 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;
40
+ const matchStages = [];
42
41
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
43
42
  if (typeof projectIdEq === 'string') {
44
- andConditions.push({
45
- 'project.id': {
46
- $eq: projectIdEq
47
- }
43
+ matchStages.push({
44
+ $match: { 'project.id': { $eq: projectIdEq } }
48
45
  });
49
46
  }
50
- const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
47
+ const parentOfferIdIn = (_d = (_c = params.parentOffer) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$in;
48
+ if (Array.isArray(parentOfferIdIn)) {
49
+ matchStages.push({ $match: { _id: { $in: parentOfferIdIn } } });
50
+ }
51
+ const includedInDataCatalogIdIn = (_f = (_e = params.includedInDataCatalog) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$in;
52
+ if (Array.isArray(includedInDataCatalogIdIn)) {
53
+ matchStages.push({ $match: { 'offers.includedInDataCatalog.id': { $exists: true, $in: includedInDataCatalogIdIn } } });
54
+ }
55
+ const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
51
56
  if (typeof idEq === 'string') {
52
- andConditions.push({
53
- _id: {
54
- $eq: idEq
55
- }
57
+ matchStages.push({
58
+ $match: { 'offers.id': { $eq: idEq } }
56
59
  });
57
60
  }
58
- const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
61
+ const idIn = (_h = params.id) === null || _h === void 0 ? void 0 : _h.$in;
59
62
  if (Array.isArray(idIn)) {
60
- andConditions.push({
61
- _id: {
62
- $in: idIn
63
- }
63
+ matchStages.push({
64
+ $match: { 'offers.id': { $in: idIn } }
64
65
  });
65
66
  }
66
- const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
67
+ const identifierEq = (_j = params.identifier) === null || _j === void 0 ? void 0 : _j.$eq;
67
68
  if (typeof identifierEq === 'string') {
68
- andConditions.push({
69
- identifier: {
70
- $exists: true,
71
- $eq: identifierEq
69
+ matchStages.push({
70
+ $match: {
71
+ 'offers.identifier': { $exists: true, $eq: identifierEq }
72
72
  }
73
73
  });
74
74
  }
75
- const identifierIn = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$in;
75
+ const identifierIn = (_k = params.identifier) === null || _k === void 0 ? void 0 : _k.$in;
76
76
  if (Array.isArray(identifierIn)) {
77
- andConditions.push({
78
- identifier: {
79
- $exists: true,
80
- $in: identifierIn
77
+ matchStages.push({
78
+ $match: {
79
+ 'offers.identifier': { $exists: true, $in: identifierIn }
81
80
  }
82
81
  });
83
82
  }
84
- const identifierRegex = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$regex;
83
+ const identifierRegex = (_l = params.identifier) === null || _l === void 0 ? void 0 : _l.$regex;
85
84
  if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
86
- andConditions.push({
87
- identifier: {
88
- $exists: true,
89
- $regex: new RegExp(identifierRegex)
85
+ matchStages.push({
86
+ $match: {
87
+ 'offers.identifier': { $exists: true, $regex: new RegExp(identifierRegex) }
90
88
  }
91
89
  });
92
90
  }
93
- const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
91
+ const nameRegex = (_m = params.name) === null || _m === void 0 ? void 0 : _m.$regex;
94
92
  if (typeof nameRegex === 'string' && nameRegex.length > 0) {
95
93
  const nameRegexExp = new RegExp(nameRegex);
96
- andConditions.push({
97
- $or: [
98
- {
99
- 'name.ja': {
100
- $exists: true,
101
- $regex: nameRegexExp
102
- }
103
- },
104
- {
105
- 'name.en': {
106
- $exists: true,
107
- $regex: nameRegexExp
108
- }
109
- },
110
- {
111
- 'alternateName.ja': {
112
- $exists: true,
113
- $regex: nameRegexExp
114
- }
115
- },
116
- {
117
- 'alternateName.en': {
118
- $exists: true,
119
- $regex: nameRegexExp
120
- }
121
- }
122
- ]
94
+ matchStages.push({
95
+ $match: {
96
+ $or: [
97
+ { 'offers.name.ja': { $exists: true, $regex: nameRegexExp } },
98
+ { 'offers.name.en': { $exists: true, $regex: nameRegexExp } },
99
+ { 'offers.alternateName.ja': { $exists: true, $regex: nameRegexExp } },
100
+ { 'offers.alternateName.en': { $exists: true, $regex: nameRegexExp } }
101
+ ]
102
+ }
123
103
  });
124
104
  }
125
- const itemOfferedTypeOfEq = (_k = (_j = params.itemOffered) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$eq;
105
+ const itemOfferedTypeOfEq = (_p = (_o = params.itemOffered) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
126
106
  if (typeof itemOfferedTypeOfEq === 'string') {
127
- andConditions.push({
128
- 'itemOffered.typeOf': {
129
- $exists: true,
130
- $eq: itemOfferedTypeOfEq
107
+ matchStages.push({
108
+ $match: {
109
+ 'offers.itemOffered.typeOf': { $exists: true, $eq: itemOfferedTypeOfEq }
131
110
  }
132
111
  });
133
112
  }
134
- const categoryCodeValueIn = (_m = (_l = params.category) === null || _l === void 0 ? void 0 : _l.codeValue) === null || _m === void 0 ? void 0 : _m.$in;
113
+ const categoryCodeValueIn = (_r = (_q = params.category) === null || _q === void 0 ? void 0 : _q.codeValue) === null || _r === void 0 ? void 0 : _r.$in;
135
114
  if (Array.isArray(categoryCodeValueIn)) {
136
- andConditions.push({
137
- 'category.codeValue': {
138
- $exists: true,
139
- $in: categoryCodeValueIn
115
+ matchStages.push({
116
+ $match: {
117
+ 'offers.category.codeValue': { $exists: true, $in: categoryCodeValueIn }
140
118
  }
141
119
  });
142
120
  }
143
- const eligibleMembershipTypeCodeValueEq = (_p = (_o = params.eligibleMembershipType) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$eq;
121
+ const eligibleMembershipTypeCodeValueEq = (_t = (_s = params.eligibleMembershipType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
144
122
  if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
145
- andConditions.push({
146
- 'eligibleMembershipType.codeValue': {
147
- $exists: true,
148
- $eq: eligibleMembershipTypeCodeValueEq
123
+ matchStages.push({
124
+ $match: {
125
+ 'offers.eligibleMembershipType.codeValue': {
126
+ $exists: true,
127
+ $eq: eligibleMembershipTypeCodeValueEq
128
+ }
149
129
  }
150
130
  });
151
131
  }
152
- const eligibleMonetaryAmountCurrencyEq = (_r = (_q = params.eligibleMonetaryAmount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
132
+ const eligibleMonetaryAmountCurrencyEq = (_v = (_u = params.eligibleMonetaryAmount) === null || _u === void 0 ? void 0 : _u.currency) === null || _v === void 0 ? void 0 : _v.$eq;
153
133
  if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
154
- andConditions.push({
155
- 'eligibleMonetaryAmount.currency': {
156
- $exists: true,
157
- $eq: eligibleMonetaryAmountCurrencyEq
134
+ matchStages.push({
135
+ $match: {
136
+ 'offers.eligibleMonetaryAmount.currency': {
137
+ $exists: true,
138
+ $eq: eligibleMonetaryAmountCurrencyEq
139
+ }
158
140
  }
159
141
  });
160
142
  }
161
- const eligibleSeatingTypeCodeValueEq = (_t = (_s = params.eligibleSeatingType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
143
+ const eligibleSeatingTypeCodeValueEq = (_x = (_w = params.eligibleSeatingType) === null || _w === void 0 ? void 0 : _w.codeValue) === null || _x === void 0 ? void 0 : _x.$eq;
162
144
  if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
163
- andConditions.push({
164
- 'eligibleSeatingType.codeValue': {
165
- $exists: true,
166
- $eq: eligibleSeatingTypeCodeValueEq
145
+ matchStages.push({
146
+ $match: {
147
+ 'offers.eligibleSeatingType.codeValue': {
148
+ $exists: true,
149
+ $eq: eligibleSeatingTypeCodeValueEq
150
+ }
167
151
  }
168
152
  });
169
153
  }
170
- const appliesToMovieTicketServiceTypeExist = (_w = (_v = (_u = params.priceSpecification) === null || _u === void 0 ? void 0 : _u.appliesToMovieTicket) === null || _v === void 0 ? void 0 : _v.serviceType) === null || _w === void 0 ? void 0 : _w.$exists;
154
+ const appliesToMovieTicketServiceTypeExist = (_0 = (_z = (_y = params.priceSpecification) === null || _y === void 0 ? void 0 : _y.appliesToMovieTicket) === null || _z === void 0 ? void 0 : _z.serviceType) === null || _0 === void 0 ? void 0 : _0.$exists;
171
155
  if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
172
- andConditions.push({
173
- 'priceSpecification.appliesToMovieTicket.serviceType': {
174
- $exists: appliesToMovieTicketServiceTypeExist
156
+ matchStages.push({
157
+ $match: {
158
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
159
+ $exists: appliesToMovieTicketServiceTypeExist
160
+ }
175
161
  }
176
162
  });
177
163
  }
178
- const appliesToMovieTicketServiceTypeEq = (_z = (_y = (_x = params.priceSpecification) === null || _x === void 0 ? void 0 : _x.appliesToMovieTicket) === null || _y === void 0 ? void 0 : _y.serviceType) === null || _z === void 0 ? void 0 : _z.$eq;
164
+ const appliesToMovieTicketServiceTypeEq = (_3 = (_2 = (_1 = params.priceSpecification) === null || _1 === void 0 ? void 0 : _1.appliesToMovieTicket) === null || _2 === void 0 ? void 0 : _2.serviceType) === null || _3 === void 0 ? void 0 : _3.$eq;
179
165
  if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
180
- andConditions.push({
181
- 'priceSpecification.appliesToMovieTicket.serviceType': {
182
- $exists: true,
183
- $eq: appliesToMovieTicketServiceTypeEq
166
+ matchStages.push({
167
+ $match: {
168
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
169
+ $exists: true,
170
+ $eq: appliesToMovieTicketServiceTypeEq
171
+ }
184
172
  }
185
173
  });
186
174
  }
187
- const appliesToMovieTicketServiceOutputTypeOfEq = (_3 = (_2 = (_1 = (_0 = params.priceSpecification) === null || _0 === void 0 ? void 0 : _0.appliesToMovieTicket) === null || _1 === void 0 ? void 0 : _1.serviceOutput) === null || _2 === void 0 ? void 0 : _2.typeOf) === null || _3 === void 0 ? void 0 : _3.$eq;
175
+ const appliesToMovieTicketServiceOutputTypeOfEq = (_7 = (_6 = (_5 = (_4 = params.priceSpecification) === null || _4 === void 0 ? void 0 : _4.appliesToMovieTicket) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.typeOf) === null || _7 === void 0 ? void 0 : _7.$eq;
188
176
  if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
189
- andConditions.push({
190
- 'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
191
- $exists: true,
192
- $eq: appliesToMovieTicketServiceOutputTypeOfEq
177
+ matchStages.push({
178
+ $match: {
179
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
180
+ $exists: true,
181
+ $eq: appliesToMovieTicketServiceOutputTypeOfEq
182
+ }
193
183
  }
194
184
  });
195
185
  }
196
- const appliesToMovieTicketServiceOutputTypeOfNin = (_7 = (_6 = (_5 = (_4 = params.priceSpecification) === null || _4 === void 0 ? void 0 : _4.appliesToMovieTicket) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.typeOf) === null || _7 === void 0 ? void 0 : _7.$nin;
186
+ const appliesToMovieTicketServiceOutputTypeOfNin = (_11 = (_10 = (_9 = (_8 = params.priceSpecification) === null || _8 === void 0 ? void 0 : _8.appliesToMovieTicket) === null || _9 === void 0 ? void 0 : _9.serviceOutput) === null || _10 === void 0 ? void 0 : _10.typeOf) === null || _11 === void 0 ? void 0 : _11.$nin;
197
187
  if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
198
- andConditions.push({
199
- 'priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
200
- $nin: appliesToMovieTicketServiceOutputTypeOfNin
188
+ matchStages.push({
189
+ $match: {
190
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
191
+ $nin: appliesToMovieTicketServiceOutputTypeOfNin
192
+ }
201
193
  }
202
194
  });
203
195
  }
204
196
  if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
205
- const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
197
+ const priceSpecificationPriceGte = (_12 = params.priceSpecification.price) === null || _12 === void 0 ? void 0 : _12.$gte;
206
198
  if (typeof priceSpecificationPriceGte === 'number') {
207
- andConditions.push({
208
- 'priceSpecification.price': {
209
- $exists: true,
210
- $gte: priceSpecificationPriceGte
199
+ matchStages.push({
200
+ $match: {
201
+ 'offers.priceSpecification.price': {
202
+ $exists: true,
203
+ $gte: priceSpecificationPriceGte
204
+ }
211
205
  }
212
206
  });
213
207
  }
214
- const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
208
+ const priceSpecificationPriceLte = (_13 = params.priceSpecification.price) === null || _13 === void 0 ? void 0 : _13.$lte;
215
209
  if (typeof priceSpecificationPriceLte === 'number') {
216
- andConditions.push({
217
- 'priceSpecification.price': {
218
- $exists: true,
219
- $lte: priceSpecificationPriceLte
210
+ matchStages.push({
211
+ $match: {
212
+ 'offers.priceSpecification.price': {
213
+ $exists: true,
214
+ $lte: priceSpecificationPriceLte
215
+ }
220
216
  }
221
217
  });
222
218
  }
223
- const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
219
+ const accountsReceivableGte = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.accountsReceivable) === null || _15 === void 0 ? void 0 : _15.$gte;
224
220
  if (typeof accountsReceivableGte === 'number') {
225
- andConditions.push({
226
- 'priceSpecification.accounting.accountsReceivable': {
227
- $exists: true,
228
- $gte: accountsReceivableGte
221
+ matchStages.push({
222
+ $match: {
223
+ 'offers.priceSpecification.accounting.accountsReceivable': {
224
+ $exists: true,
225
+ $gte: accountsReceivableGte
226
+ }
229
227
  }
230
228
  });
231
229
  }
232
- const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
230
+ const accountsReceivableLte = (_17 = (_16 = params.priceSpecification.accounting) === null || _16 === void 0 ? void 0 : _16.accountsReceivable) === null || _17 === void 0 ? void 0 : _17.$lte;
233
231
  if (typeof accountsReceivableLte === 'number') {
234
- andConditions.push({
235
- 'priceSpecification.accounting.accountsReceivable': {
236
- $exists: true,
237
- $lte: accountsReceivableLte
232
+ matchStages.push({
233
+ $match: {
234
+ 'offers.priceSpecification.accounting.accountsReceivable': {
235
+ $exists: true,
236
+ $lte: accountsReceivableLte
237
+ }
238
238
  }
239
239
  });
240
240
  }
241
- const accountingCodeValueEq = (_16 = (_15 = (_14 = params.priceSpecification.accounting) === null || _14 === void 0 ? void 0 : _14.operatingRevenue) === null || _15 === void 0 ? void 0 : _15.codeValue) === null || _16 === void 0 ? void 0 : _16.$eq;
241
+ const accountingCodeValueEq = (_20 = (_19 = (_18 = params.priceSpecification.accounting) === null || _18 === void 0 ? void 0 : _18.operatingRevenue) === null || _19 === void 0 ? void 0 : _19.codeValue) === null || _20 === void 0 ? void 0 : _20.$eq;
242
242
  if (typeof accountingCodeValueEq === 'string') {
243
- andConditions.push({
244
- 'priceSpecification.accounting.operatingRevenue.codeValue': {
245
- $exists: true,
246
- $eq: accountingCodeValueEq
243
+ matchStages.push({
244
+ $match: {
245
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
246
+ $exists: true,
247
+ $eq: accountingCodeValueEq
248
+ }
247
249
  }
248
250
  });
249
251
  }
250
- const accountingCodeValueIn = (_19 = (_18 = (_17 = params.priceSpecification.accounting) === null || _17 === void 0 ? void 0 : _17.operatingRevenue) === null || _18 === void 0 ? void 0 : _18.codeValue) === null || _19 === void 0 ? void 0 : _19.$in;
252
+ const accountingCodeValueIn = (_23 = (_22 = (_21 = params.priceSpecification.accounting) === null || _21 === void 0 ? void 0 : _21.operatingRevenue) === null || _22 === void 0 ? void 0 : _22.codeValue) === null || _23 === void 0 ? void 0 : _23.$in;
251
253
  if (Array.isArray(accountingCodeValueIn)) {
252
- andConditions.push({
253
- 'priceSpecification.accounting.operatingRevenue.codeValue': {
254
- $exists: true,
255
- $in: accountingCodeValueIn
254
+ matchStages.push({
255
+ $match: {
256
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
257
+ $exists: true,
258
+ $in: accountingCodeValueIn
259
+ }
256
260
  }
257
261
  });
258
262
  }
259
- const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
263
+ const referenceQuantityValueEq = (_25 = (_24 = params.priceSpecification.referenceQuantity) === null || _24 === void 0 ? void 0 : _24.value) === null || _25 === void 0 ? void 0 : _25.$eq;
260
264
  if (typeof referenceQuantityValueEq === 'number') {
261
- andConditions.push({
262
- 'priceSpecification.referenceQuantity.value': {
263
- $exists: true,
264
- $eq: referenceQuantityValueEq
265
+ matchStages.push({
266
+ $match: {
267
+ 'offers.priceSpecification.referenceQuantity.value': {
268
+ $exists: true,
269
+ $eq: referenceQuantityValueEq
270
+ }
265
271
  }
266
272
  });
267
273
  }
268
274
  }
269
- const availabilityEq = (_22 = params.availability) === null || _22 === void 0 ? void 0 : _22.$eq;
275
+ const availabilityEq = (_26 = params.availability) === null || _26 === void 0 ? void 0 : _26.$eq;
270
276
  if (typeof availabilityEq === 'string') {
271
- andConditions.push({ availability: { $eq: availabilityEq } });
277
+ matchStages.push({
278
+ $match: {
279
+ 'offers.availability': { $eq: availabilityEq }
280
+ }
281
+ });
272
282
  }
273
- const availableAtOrFromIdEq = (_24 = (_23 = params.availableAtOrFrom) === null || _23 === void 0 ? void 0 : _23.id) === null || _24 === void 0 ? void 0 : _24.$eq;
283
+ const availableAtOrFromIdEq = (_28 = (_27 = params.availableAtOrFrom) === null || _27 === void 0 ? void 0 : _27.id) === null || _28 === void 0 ? void 0 : _28.$eq;
274
284
  if (typeof availableAtOrFromIdEq === 'string') {
275
- andConditions.push({
276
- 'availableAtOrFrom.id': {
277
- $exists: true,
278
- $eq: availableAtOrFromIdEq
285
+ matchStages.push({
286
+ $match: {
287
+ 'offers.availableAtOrFrom.id': {
288
+ $exists: true,
289
+ $eq: availableAtOrFromIdEq
290
+ }
279
291
  }
280
292
  });
281
293
  }
282
- const availableAtOrFromIdIn = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$in;
294
+ const availableAtOrFromIdIn = (_30 = (_29 = params.availableAtOrFrom) === null || _29 === void 0 ? void 0 : _29.id) === null || _30 === void 0 ? void 0 : _30.$in;
283
295
  if (Array.isArray(availableAtOrFromIdIn)) {
284
- andConditions.push({
285
- 'availableAtOrFrom.id': {
286
- $exists: true,
287
- $in: availableAtOrFromIdIn
296
+ matchStages.push({
297
+ $match: {
298
+ 'offers.availableAtOrFrom.id': {
299
+ $exists: true,
300
+ $in: availableAtOrFromIdIn
301
+ }
288
302
  }
289
303
  });
290
304
  }
291
- 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;
305
+ const addOnItemOfferedIdEq = (_33 = (_32 = (_31 = params.addOn) === null || _31 === void 0 ? void 0 : _31.itemOffered) === null || _32 === void 0 ? void 0 : _32.id) === null || _33 === void 0 ? void 0 : _33.$eq;
292
306
  if (typeof addOnItemOfferedIdEq === 'string') {
293
- andConditions.push({
294
- 'addOn.itemOffered.id': {
295
- $exists: true,
296
- $eq: addOnItemOfferedIdEq
307
+ matchStages.push({
308
+ $match: {
309
+ 'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
310
+ }
311
+ });
312
+ }
313
+ const addOnItemOfferedIdIn = (_36 = (_35 = (_34 = params.addOn) === null || _34 === void 0 ? void 0 : _34.itemOffered) === null || _35 === void 0 ? void 0 : _35.id) === null || _36 === void 0 ? void 0 : _36.$in;
314
+ if (Array.isArray(addOnItemOfferedIdIn)) {
315
+ matchStages.push({
316
+ $match: {
317
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
297
318
  }
298
319
  });
299
320
  }
300
- const hasMerchantReturnPolicyIdEq = (_31 = (_30 = params.hasMerchantReturnPolicy) === null || _30 === void 0 ? void 0 : _30.id) === null || _31 === void 0 ? void 0 : _31.$eq;
321
+ const hasMerchantReturnPolicyIdEq = (_38 = (_37 = params.hasMerchantReturnPolicy) === null || _37 === void 0 ? void 0 : _37.id) === null || _38 === void 0 ? void 0 : _38.$eq;
301
322
  if (typeof hasMerchantReturnPolicyIdEq === 'string') {
302
- andConditions.push({
303
- 'hasMerchantReturnPolicy.id': {
304
- $exists: true,
305
- $eq: hasMerchantReturnPolicyIdEq
323
+ matchStages.push({
324
+ $match: {
325
+ 'offers.hasMerchantReturnPolicy.id': {
326
+ $exists: true,
327
+ $eq: hasMerchantReturnPolicyIdEq
328
+ }
306
329
  }
307
330
  });
308
331
  }
309
- const additionalPropertyAll = (_32 = params.additionalProperty) === null || _32 === void 0 ? void 0 : _32.$all;
332
+ const additionalPropertyAll = (_39 = params.additionalProperty) === null || _39 === void 0 ? void 0 : _39.$all;
310
333
  if (Array.isArray(additionalPropertyAll)) {
311
- andConditions.push({
312
- additionalProperty: {
313
- $exists: true,
314
- $all: additionalPropertyAll
334
+ matchStages.push({
335
+ $match: {
336
+ 'offers.additionalProperty': {
337
+ $exists: true,
338
+ $all: additionalPropertyAll
339
+ }
315
340
  }
316
341
  });
317
342
  }
318
- const additionalPropertyElemMatch = (_33 = params.additionalProperty) === null || _33 === void 0 ? void 0 : _33.$elemMatch;
343
+ const additionalPropertyElemMatch = (_40 = params.additionalProperty) === null || _40 === void 0 ? void 0 : _40.$elemMatch;
319
344
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
320
- andConditions.push({
321
- additionalProperty: {
322
- $exists: true,
323
- $elemMatch: additionalPropertyElemMatch
345
+ matchStages.push({
346
+ $match: {
347
+ 'offers.additionalProperty': {
348
+ $exists: true,
349
+ $elemMatch: additionalPropertyElemMatch
350
+ }
324
351
  }
325
352
  });
326
353
  }
327
354
  if (params.onlyValid === true) {
328
355
  const now = new Date();
329
- andConditions.push({
330
- $or: [
331
- { validFrom: { $exists: false } },
332
- { validFrom: { $exists: true, $lte: now } }
333
- ]
356
+ matchStages.push({
357
+ $match: {
358
+ $or: [
359
+ { 'offers.validFrom': { $exists: false } },
360
+ { 'offers.validFrom': { $exists: true, $lte: now } }
361
+ ]
362
+ }
334
363
  }, {
335
- $or: [
336
- { validThrough: { $exists: false } },
337
- { validThrough: { $exists: true, $gte: now } }
338
- ]
364
+ $match: {
365
+ $or: [
366
+ { 'offers.validThrough': { $exists: false } },
367
+ { 'offers.validThrough': { $exists: true, $gte: now } }
368
+ ]
369
+ }
370
+ });
371
+ }
372
+ return matchStages;
373
+ }
374
+ static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
375
+ let projectStage = {
376
+ _id: 0,
377
+ offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
378
+ parentOffer: {
379
+ id: '$_id'
380
+ },
381
+ typeOf: '$offers.typeOf',
382
+ project: '$project',
383
+ id: '$offers.id',
384
+ identifier: '$offers.identifier',
385
+ name: '$offers.name',
386
+ description: '$offers.description',
387
+ category: '$offers.category',
388
+ color: '$offers.color',
389
+ additionalProperty: '$offers.additionalProperty',
390
+ advanceBookingRequirement: '$offers.advanceBookingRequirement',
391
+ alternateName: '$offers.alternateName',
392
+ addOn: '$offers.addOn',
393
+ availability: '$offers.availability',
394
+ availableAtOrFrom: '$offers.availableAtOrFrom',
395
+ hasMerchantReturnPolicy: '$offers.hasMerchantReturnPolicy',
396
+ itemOffered: '$offers.itemOffered',
397
+ priceCurrency: '$offers.priceCurrency',
398
+ priceSpecification: '$offers.priceSpecification',
399
+ eligibleCustomerType: '$offers.eligibleCustomerType',
400
+ eligibleDuration: '$offers.eligibleDuration',
401
+ eligibleMembershipType: '$offers.eligibleMembershipType',
402
+ eligibleMonetaryAmount: '$offers.eligibleMonetaryAmount',
403
+ eligibleQuantity: '$offers.eligibleQuantity',
404
+ eligibleRegion: '$offers.eligibleRegion',
405
+ eligibleSeatingType: '$offers.eligibleSeatingType',
406
+ eligibleSubReservation: '$offers.eligibleSubReservation',
407
+ settings: '$offers.settings',
408
+ validFrom: '$offers.validFrom',
409
+ validThrough: '$offers.validThrough',
410
+ validRateLimit: '$offers.validRateLimit'
411
+ };
412
+ const positiveProjectionFields = Object.keys(params)
413
+ .filter((key) => params[key] !== 0);
414
+ const negativeProjectionFields = Object.keys(params)
415
+ .filter((key) => params[key] === 0);
416
+ if (positiveProjectionFields.length > 0) {
417
+ projectStage = {
418
+ _id: 0,
419
+ offerIndex: `$${OFFERS_ARRAY_INDEX_NAME}`,
420
+ parentOffer: {
421
+ id: '$_id'
422
+ }
423
+ };
424
+ positiveProjectionFields.forEach((field) => {
425
+ projectStage[field] = `$offers.${field}`;
426
+ });
427
+ }
428
+ else if (negativeProjectionFields.length > 0) {
429
+ negativeProjectionFields.forEach((field) => {
430
+ if (typeof projectStage[field] === 'string') {
431
+ // tslint:disable-next-line:no-dynamic-delete
432
+ delete projectStage[field];
433
+ }
339
434
  });
340
435
  }
341
- return andConditions;
436
+ return projectStage;
437
+ }
438
+ /**
439
+ * カタログIDで単価オファーを全て検索する
440
+ * 必ずカタログデータから単価オファーIDを参照する
441
+ */
442
+ searchAllByOfferCatalogId(params) {
443
+ return __awaiter(this, void 0, void 0, function* () {
444
+ const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
445
+ id: params.subOfferCatalog.id
446
+ });
447
+ let offers = [];
448
+ if (sortedOfferIds.length > 0) {
449
+ const searchOffersConditions = {
450
+ parentOffer: { id: { $in: sortedOfferIds } }
451
+ };
452
+ offers = yield this.search(searchOffersConditions, params.projection);
453
+ }
454
+ return { offers };
455
+ });
342
456
  }
343
457
  /**
344
- * カタログに含まれるオファーを検索する
345
- * カタログに登録されたオファーの順序は保証される
458
+ * 単価オファーIDとカタログIDで単価オファーを検索する
459
+ * 必ずカタログデータから単価オファーIDを参照する
346
460
  */
347
- findOffersByOfferCatalogId(params) {
461
+ searchByIdsAndOfferCatalogId(params) {
348
462
  var _a;
349
463
  return __awaiter(this, void 0, void 0, function* () {
350
- // aggregateで再実装(2023-01-26~)
351
- const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
352
- if (Array.isArray(params.ids)) {
353
- matchStages.push({
354
- $match: { 'itemListElement.id': { $exists: true, $in: params.ids } }
355
- });
464
+ const unitPriceOfferIds = params.ids;
465
+ let aggregateOfferIds; // 集計オファーIDでフィルターする場合
466
+ if (Array.isArray(unitPriceOfferIds)) {
467
+ // 解釈を集計オファーIDに変更する必要がある(2023-09-11~)
468
+ // 単価オファーIDリスト→集計オファーIDに変換→カタログ条件にセット
469
+ const searchDistinctAggregateOfferIdsResult = yield this.aggregateOfferModel.distinct('_id', { 'offers.id': { $in: unitPriceOfferIds } })
470
+ .exec();
471
+ aggregateOfferIds = searchDistinctAggregateOfferIdsResult;
356
472
  }
357
- const aggregate = this.offerCatalogModel.aggregate([
358
- { $unwind: '$itemListElement' },
359
- ...matchStages,
360
- {
361
- $project: {
362
- _id: 0,
363
- id: '$itemListElement.id'
364
- }
365
- }
366
- ]);
367
- const itemListElements = yield aggregate.exec();
368
- const sortedOfferIds = (Array.isArray(itemListElements))
369
- ? itemListElements.map((element) => element.id)
370
- : [];
473
+ const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog(Object.assign({ id: params.subOfferCatalog.id }, (Array.isArray(aggregateOfferIds)) ? { itemListElementIds: aggregateOfferIds } : undefined));
371
474
  let offers = [];
372
475
  if (sortedOfferIds.length > 0) {
373
- const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ id: { $in: sortedOfferIds } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
476
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({
477
+ // aggregateOffer.idで検索する(2023-09-09~)
478
+ parentOffer: { id: { $in: sortedOfferIds } } }, (Array.isArray(unitPriceOfferIds)) ? { id: { $in: unitPriceOfferIds } } : undefined), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
374
479
  ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
375
480
  : undefined), { priceSpecification: {
376
481
  appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
@@ -385,116 +490,264 @@ class MongoRepository {
385
490
  }
386
491
  : undefined)
387
492
  }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
388
- ? { sort: { _id: factory.sortType.Ascending } }
493
+ // 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
494
+ ? { sort: { identifier: factory.sortType.Ascending } }
495
+ : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
496
+ offers = yield this.search(searchOffersConditions, params.projection);
497
+ }
498
+ return { offers };
499
+ });
500
+ }
501
+ /**
502
+ * カタログに含まれるオファーを検索する(カタログ内ソートは保証しない)
503
+ * カタログ内ソートインデックスはsortedOfferIdsで判断する
504
+ */
505
+ searchByOfferCatalogIdWithSortIndex(params) {
506
+ var _a;
507
+ return __awaiter(this, void 0, void 0, function* () {
508
+ const sortedOfferIds = yield this.searchAggregateOfferIdsBySubOfferCatalog({
509
+ id: params.subOfferCatalog.id
510
+ });
511
+ let offers = [];
512
+ if (sortedOfferIds.length > 0) {
513
+ const searchOffersConditions = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.useIncludeInDataCatalog)
514
+ ? { includedInDataCatalog: { id: { $in: [params.subOfferCatalog.id] } } }
515
+ : { parentOffer: { id: { $in: sortedOfferIds } } }), (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
516
+ ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
517
+ : undefined), { priceSpecification: {
518
+ appliesToMovieTicket: Object.assign(Object.assign({}, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
519
+ ? {
520
+ serviceOutput: {
521
+ typeOf: { $nin: params.unacceptedPaymentMethod }
522
+ }
523
+ }
524
+ : undefined), (params.excludeAppliesToMovieTicket)
525
+ ? {
526
+ serviceType: { $exists: false }
527
+ }
528
+ : undefined)
529
+ }, onlyValid: params.onlyValid === true }), (typeof params.limit === 'number' && typeof params.page === 'number')
530
+ // 明示的なソート指定を調整(決して重複しない属性が相応)(2023-09-07~)
531
+ ? { sort: { identifier: factory.sortType.Ascending } }
389
532
  : undefined), (typeof params.limit === 'number') ? { limit: params.limit } : undefined), (typeof params.page === 'number') ? { page: params.page } : undefined);
390
533
  offers = yield this.search(searchOffersConditions, params.projection);
391
- if (params.sort) {
392
- // sorting
393
- offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
394
- }
395
534
  }
396
535
  return { offers, sortedOfferIds };
397
536
  });
398
537
  }
399
- findById(params) {
538
+ /**
539
+ * カタログに記載されたオファーにおいて利用可能な決済方法区分を検索する
540
+ */
541
+ searchAvaialbleAppliesToMovieTicketByOfferCatalogId(params) {
542
+ var _a;
543
+ return __awaiter(this, void 0, void 0, function* () {
544
+ 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')
545
+ ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
546
+ : undefined), { priceSpecification: {
547
+ appliesToMovieTicket: Object.assign({
548
+ // 基本は適用決済カード区分有のみ検索
549
+ serviceType: { $exists: (!params.excludeAppliesToMovieTicket === true) } }, (Array.isArray(params.unacceptedPaymentMethod) && params.unacceptedPaymentMethod.length > 0)
550
+ ? { serviceOutput: { typeOf: { $nin: params.unacceptedPaymentMethod } } }
551
+ : undefined)
552
+ }, onlyValid: params.onlyValid === true });
553
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(searchOffersConditions);
554
+ const aggregate = this.aggregateOfferModel.aggregate([
555
+ { $unwind: { path: '$offers' } },
556
+ { $unwind: { path: '$offers.priceSpecification.appliesToMovieTicket' } },
557
+ ...matchStages,
558
+ {
559
+ $group: {
560
+ _id: '$offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf',
561
+ appliesToMovieTicket: { $first: '$offers.priceSpecification.appliesToMovieTicket' }
562
+ }
563
+ },
564
+ { $sort: { _id: factory.sortType.Ascending } },
565
+ {
566
+ $project: {
567
+ _id: 0,
568
+ serviceOutput: { typeOf: '$_id' }
569
+ }
570
+ }
571
+ ]);
572
+ if (typeof params.limit === 'number' && params.limit > 0) {
573
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
574
+ aggregate.limit(params.limit * page)
575
+ .skip(params.limit * (page - 1));
576
+ }
577
+ return aggregate.exec();
578
+ });
579
+ }
580
+ findAggregateOfferById(params) {
400
581
  return __awaiter(this, void 0, void 0, function* () {
401
- const doc = yield this.offerModel.findOne({ _id: params.id }, {
582
+ const doc = yield this.aggregateOfferModel.findOne({
583
+ _id: { $eq: params.id },
584
+ 'project.id': { $eq: params.project.id }
585
+ }, {
402
586
  __v: 0,
403
587
  createdAt: 0,
404
588
  updatedAt: 0
405
589
  })
406
590
  .exec();
407
591
  if (doc === null) {
408
- throw new factory.errors.NotFound(this.offerModel.modelName);
592
+ throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
409
593
  }
410
594
  return doc.toObject();
411
595
  });
412
596
  }
413
597
  count(params) {
414
598
  return __awaiter(this, void 0, void 0, function* () {
415
- const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
416
- return this.offerModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
417
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
599
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
600
+ const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
601
+ {
602
+ $unwind: { path: '$offers' }
603
+ },
604
+ ...matchStages,
605
+ {
606
+ $count: 'offerCount'
607
+ }
608
+ ])
418
609
  .exec();
610
+ return offerCount;
419
611
  });
420
612
  }
421
613
  search(params, projection) {
422
- var _a;
614
+ var _a, _b;
423
615
  return __awaiter(this, void 0, void 0, function* () {
424
- const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
425
- const positiveProjectionExists = (projection !== undefined && projection !== null)
426
- ? Object.values(projection)
427
- .some((value) => value !== 0)
428
- : false;
429
- const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
430
- ? projection
431
- : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
616
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
617
+ const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
618
+ const sortByPrice = (_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price'];
619
+ const sortByIdentifier = (_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier;
620
+ const aggregate = this.aggregateOfferModel.aggregate([
621
+ {
622
+ $unwind: {
623
+ path: '$offers',
624
+ includeArrayIndex: OFFERS_ARRAY_INDEX_NAME
625
+ }
626
+ },
627
+ ...matchStages,
628
+ ...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
629
+ ? [
630
+ {
631
+ $sort: Object.assign(Object.assign({}, (typeof sortByPrice === 'number')
632
+ ? { 'offers.priceSpecification.price': sortByPrice }
633
+ : undefined), (typeof sortByIdentifier === 'number')
634
+ ? { 'offers.identifier': sortByIdentifier }
635
+ : undefined)
636
+ }
637
+ ]
638
+ : [],
639
+ { $project: projectStage }
640
+ ]);
641
+ // tslint:disable-next-line:no-single-line-block-comment
642
+ /* istanbul ignore else */
432
643
  if (typeof params.limit === 'number' && params.limit > 0) {
433
644
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
434
- query.limit(params.limit)
645
+ aggregate.limit(params.limit * page)
435
646
  .skip(params.limit * (page - 1));
436
647
  }
437
- // tslint:disable-next-line:no-single-line-block-comment
438
- /* istanbul ignore else */
439
- if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price']) !== undefined) {
440
- query.sort({ 'priceSpecification.price': params.sort['priceSpecification.price'] });
441
- }
442
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
443
- .exec()
444
- .then((docs) => docs.map((doc) => doc.toObject()));
648
+ return aggregate.exec();
445
649
  });
446
650
  }
447
651
  save(params) {
448
652
  return __awaiter(this, void 0, void 0, function* () {
449
653
  let doc;
654
+ const { $unset } = params, paramsWithoutUnset = __rest(params, ["$unset"]);
655
+ let savedUnitPriceOffer;
450
656
  if (params.id === '') {
451
657
  const id = uniqid();
452
- doc = yield this.offerModel.create(Object.assign(Object.assign({}, params), { _id: id }));
658
+ savedUnitPriceOffer = Object.assign(Object.assign({}, paramsWithoutUnset), { id });
659
+ const aggregateOffer = {
660
+ typeOf: factory.offerType.AggregateOffer,
661
+ project: params.project,
662
+ offers: [savedUnitPriceOffer]
663
+ };
664
+ doc = yield this.aggregateOfferModel.create(Object.assign(Object.assign({}, aggregateOffer), { _id: id }));
453
665
  }
454
666
  else {
455
- // 上書き禁止属性を除外(2022-08-24~)
456
- const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
457
- doc = yield this.offerModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
667
+ const unitPriceOffers = yield this.search({
668
+ limit: 1,
669
+ page: 1,
670
+ project: { id: { $eq: params.project.id } },
671
+ id: { $eq: params.id }
672
+ }, { id: 1, identifier: 1, project: 1, typeOf: 1 });
673
+ const originalUnitPriceOffer = unitPriceOffers.shift();
674
+ if (originalUnitPriceOffer === undefined) {
675
+ throw new factory.errors.NotFound(factory.offerType.Offer);
676
+ }
677
+ // 上書き禁止属性を除外
678
+ const { id, identifier, project, typeOf } = paramsWithoutUnset, updateFields = __rest(paramsWithoutUnset, ["id", "identifier", "project", "typeOf"]);
679
+ savedUnitPriceOffer = Object.assign(Object.assign({}, updateFields), { id: originalUnitPriceOffer.id, identifier: originalUnitPriceOffer.identifier, project: originalUnitPriceOffer.project, typeOf: originalUnitPriceOffer.typeOf });
680
+ doc = yield this.aggregateOfferModel.findOneAndUpdate({ 'offers.id': params.id }, {
681
+ $set: {
682
+ 'offers.$[offer]': savedUnitPriceOffer
683
+ }
684
+ }, {
685
+ upsert: false,
686
+ new: true,
687
+ arrayFilters: [
688
+ { 'offer.id': { $eq: params.id } }
689
+ ]
690
+ })
458
691
  .exec();
459
692
  }
460
693
  if (doc === null) {
461
- throw new factory.errors.NotFound(this.offerModel.modelName);
694
+ throw new factory.errors.NotFound(this.aggregateOfferModel.modelName);
462
695
  }
463
- return doc.toObject();
696
+ return savedUnitPriceOffer;
464
697
  });
465
698
  }
699
+ /**
700
+ * sskts専用オファー保管
701
+ */
702
+ // tslint:disable-next-line:max-func-body-length
466
703
  saveManyByIdentifier(params) {
467
704
  return __awaiter(this, void 0, void 0, function* () {
468
- const bulkWriteOps = [];
705
+ const insertBulkWriteOps = [];
706
+ const updateBulkWriteOps = [];
469
707
  if (Array.isArray(params)) {
470
708
  params.forEach((p) => {
471
- const id = uniqid();
472
- const $set = Object.assign({}, p.attributes);
473
- if (typeof $set.id === 'string') {
474
- delete $set.id;
475
- }
476
- bulkWriteOps.push({
709
+ const newOfferId = uniqid();
710
+ const unitPriceOffer = Object.assign(Object.assign({}, p.attributes), { id: newOfferId });
711
+ const aggregateOffer = {
712
+ project: p.attributes.project,
713
+ typeOf: factory.offerType.AggregateOffer,
714
+ offers: [unitPriceOffer]
715
+ };
716
+ insertBulkWriteOps.push({
477
717
  updateOne: {
478
718
  filter: {
479
- 'project.id': {
480
- $eq: p.attributes.project.id
481
- },
482
- identifier: {
483
- $exists: true,
484
- $eq: p.attributes.identifier
485
- }
719
+ 'project.id': { $eq: p.attributes.project.id },
720
+ 'offers.identifier': { $exists: true, $eq: p.attributes.identifier }
486
721
  },
487
722
  update: {
488
- $set: $set,
489
- $setOnInsert: { _id: id }
723
+ $setOnInsert: Object.assign(Object.assign({}, aggregateOffer), { _id: newOfferId })
490
724
  },
491
- upsert: (p.upsert !== undefined) ? p.upsert : false
725
+ upsert: true
726
+ }
727
+ });
728
+ const { id } = unitPriceOffer, $set = __rest(unitPriceOffer, ["id"]);
729
+ updateBulkWriteOps.push({
730
+ updateOne: {
731
+ filter: {
732
+ 'project.id': { $eq: unitPriceOffer.project.id },
733
+ 'offers.identifier': { $exists: true, $eq: unitPriceOffer.identifier }
734
+ },
735
+ update: {
736
+ // 特定の属性のみ更新する(IDを上書きできないので)
737
+ $set: Object.assign(Object.assign({ 'offers.0.name': $set.name, 'offers.0.description': $set.description, 'offers.0.alternateName': $set.alternateName, 'offers.0.priceSpecification': $set.priceSpecification, 'offers.0.additionalProperty': $set.additionalProperty }, (Array.isArray($set.eligibleMembershipType))
738
+ ? { 'offers.0.eligibleMembershipType': $set.eligibleMembershipType }
739
+ : undefined), (Array.isArray($set.eligibleMonetaryAmount))
740
+ ? { 'offers.0.eligibleMonetaryAmount': $set.eligibleMonetaryAmount }
741
+ : undefined)
742
+ },
743
+ upsert: false
492
744
  }
493
745
  });
494
746
  });
495
747
  }
496
- if (bulkWriteOps.length > 0) {
497
- yield this.offerModel.bulkWrite(bulkWriteOps, { ordered: false });
748
+ if (insertBulkWriteOps.length > 0) {
749
+ yield this.aggregateOfferModel.bulkWrite(insertBulkWriteOps, { ordered: false });
750
+ yield this.aggregateOfferModel.bulkWrite(updateBulkWriteOps, { ordered: false });
498
751
  }
499
752
  });
500
753
  }
@@ -506,42 +759,61 @@ class MongoRepository {
506
759
  if (params.addOn.itemOffered.id.$in.length === 0) {
507
760
  return;
508
761
  }
509
- return this.offerModel.updateMany({
762
+ const conditions = {
510
763
  'project.id': { $eq: params.project.id },
511
- 'addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
512
- }, {
764
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in }
765
+ };
766
+ const updatingOffers = yield this.search({
767
+ project: { id: { $eq: params.project.id } },
768
+ addOn: { itemOffered: { id: { $in: params.addOn.itemOffered.id.$in } } }
769
+ }, { id: 1 });
770
+ const result = yield this.aggregateOfferModel.updateMany(conditions, {
513
771
  $pull: {
514
- addOn: {
772
+ 'offers.$[offer].addOn': {
515
773
  'itemOffered.id': { $in: params.addOn.itemOffered.id.$in }
516
774
  }
517
775
  }
776
+ }, {
777
+ arrayFilters: [
778
+ { 'offer.addOn.itemOffered.id': { $exists: true, $in: params.addOn.itemOffered.id.$in } }
779
+ ]
518
780
  })
519
781
  .exec();
782
+ if (updatingOffers.length > 0) {
783
+ // no op
784
+ }
785
+ return result;
520
786
  });
521
787
  }
522
788
  deleteById(params) {
523
789
  return __awaiter(this, void 0, void 0, function* () {
524
- yield this.offerModel.findOneAndRemove({ _id: params.id })
790
+ yield this.aggregateOfferModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
525
791
  .exec();
526
792
  });
527
793
  }
528
- deleteByProject(params) {
529
- return __awaiter(this, void 0, void 0, function* () {
530
- yield this.offerModel.deleteMany({
531
- 'project.id': { $eq: params.project.id }
532
- })
533
- .exec();
534
- });
535
- }
536
- getCursor(conditions, projection) {
537
- return this.offerModel.find(conditions, projection)
538
- .sort({ 'priceSpecification.price': factory.sortType.Descending })
539
- .cursor();
540
- }
541
- unsetUnnecessaryFields(params) {
794
+ /**
795
+ * サブカタログから集計オファーIDリストを検索する
796
+ */
797
+ searchAggregateOfferIdsBySubOfferCatalog(params) {
542
798
  return __awaiter(this, void 0, void 0, function* () {
543
- return this.offerModel.updateMany(params.filter, { $unset: params.$unset })
799
+ const matchStages = [{ $match: { _id: { $eq: params.id } } }];
800
+ if (Array.isArray(params.itemListElementIds)) {
801
+ matchStages.push({ $match: { 'itemListElement.id': { $exists: true, $in: params.itemListElementIds } } });
802
+ }
803
+ const itemListElements = yield this.offerCatalogModel.aggregate([
804
+ { $unwind: '$itemListElement' },
805
+ ...matchStages,
806
+ {
807
+ $project: {
808
+ _id: 0,
809
+ id: '$itemListElement.id'
810
+ }
811
+ }
812
+ ])
544
813
  .exec();
814
+ return (Array.isArray(itemListElements))
815
+ ? itemListElements.map((element) => element.id)
816
+ : [];
545
817
  });
546
818
  }
547
819
  }