@chevre/domain 21.8.0-alpha.6 → 21.8.0-alpha.60

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 (129) hide show
  1. package/example/src/chevre/countOffers.ts +32 -0
  2. package/example/src/chevre/findItemListElementByCatalogId.ts +23 -0
  3. package/example/src/chevre/importOffersFromCOA.ts +7 -1
  4. package/example/src/chevre/migrateAggregateOffers.ts +89 -0
  5. package/example/src/chevre/migrateOrderPaymentMethodIdentifier.ts +81 -0
  6. package/example/src/chevre/migratePayTransactionPaymentMethodId.ts +72 -0
  7. package/example/src/chevre/migratePayTransactionPaymentMethodIdentifier.ts +78 -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/searchAggregateOffers.ts +48 -0
  12. package/example/src/chevre/searchEventTicketOffers.ts +3 -1
  13. package/example/src/chevre/searchEvents.ts +9 -7
  14. package/example/src/chevre/searchOffersByCatalog.ts +9 -5
  15. package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
  16. package/example/src/chevre/searchOrders.ts +9 -7
  17. package/example/src/chevre/sync2aggregateOffer.ts +27 -0
  18. package/example/src/chevre/syncAggregateOffer.ts +25 -0
  19. package/lib/chevre/emailMessageBuilder.js +6 -5
  20. package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
  21. package/lib/chevre/repo/aggregateOffer.js +534 -0
  22. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  23. package/lib/chevre/repo/assetTransaction.js +54 -2
  24. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
  25. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +177 -0
  26. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
  27. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
  28. package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
  29. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +24 -33
  30. package/lib/chevre/repo/mongoose/schemas/offer.js +4 -3
  31. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  32. package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
  33. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
  34. package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
  35. package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
  36. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  37. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  38. package/lib/chevre/repo/offer.d.ts +82 -47
  39. package/lib/chevre/repo/offer.js +1279 -289
  40. package/lib/chevre/repo/offerCatalog.d.ts +6 -0
  41. package/lib/chevre/repo/offerCatalog.js +13 -0
  42. package/lib/chevre/repo/order.d.ts +15 -0
  43. package/lib/chevre/repo/order.js +58 -26
  44. package/lib/chevre/repo/task.d.ts +7 -1
  45. package/lib/chevre/repo/task.js +100 -0
  46. package/lib/chevre/repository.d.ts +3 -0
  47. package/lib/chevre/repository.js +5 -1
  48. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +2 -1
  49. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -1
  50. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  51. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  52. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  53. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  54. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  55. package/lib/chevre/service/assetTransaction/registerService.js +2 -1
  56. package/lib/chevre/service/assetTransaction/reserve.js +111 -35
  57. package/lib/chevre/service/delivery.js +17 -0
  58. package/lib/chevre/service/offer/event/authorize.js +39 -35
  59. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  60. package/lib/chevre/service/offer/event/factory.js +8 -8
  61. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  62. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -0
  63. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +6 -3
  64. package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
  65. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  66. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
  67. package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
  68. package/lib/chevre/service/offer/factory.d.ts +12 -4
  69. package/lib/chevre/service/offer/factory.js +9 -11
  70. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +8 -1
  71. package/lib/chevre/service/offer/product/searchProductOffers.js +10 -3
  72. package/lib/chevre/service/offer/product.d.ts +1 -0
  73. package/lib/chevre/service/offer/product.js +3 -2
  74. package/lib/chevre/service/offer.d.ts +1 -0
  75. package/lib/chevre/service/offer.js +7 -1
  76. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  77. package/lib/chevre/service/order/confirmPayTransaction.js +29 -40
  78. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  79. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  80. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  81. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  82. package/lib/chevre/service/order/onOrderStatusChanged.js +81 -54
  83. package/lib/chevre/service/order/payOrder.d.ts +2 -10
  84. package/lib/chevre/service/order/payOrder.js +4 -45
  85. package/lib/chevre/service/order/placeOrder.js +11 -13
  86. package/lib/chevre/service/order.d.ts +3 -1
  87. package/lib/chevre/service/order.js +6 -2
  88. package/lib/chevre/service/payment/any/factory.js +33 -8
  89. package/lib/chevre/service/payment/any.js +30 -21
  90. package/lib/chevre/service/payment/creditCard.js +12 -12
  91. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  92. package/lib/chevre/service/payment/movieTicket.js +10 -11
  93. package/lib/chevre/service/payment/paymentCard.js +9 -12
  94. package/lib/chevre/service/project.js +1 -1
  95. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  96. package/lib/chevre/service/reserve/checkInReservation.js +3 -2
  97. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  98. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
  99. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
  100. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
  101. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  102. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  103. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
  104. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  105. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  106. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  107. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  108. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
  109. package/lib/chevre/service/task/onOrderPaymentCompleted.d.ts +6 -0
  110. package/lib/chevre/service/task/onOrderPaymentCompleted.js +35 -0
  111. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  112. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
  113. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
  114. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +60 -0
  115. package/lib/chevre/service/task/onResourceUpdated.js +12 -0
  116. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  117. package/lib/chevre/service/task/syncAggregateOffer.d.ts +7 -0
  118. package/lib/chevre/service/task/syncAggregateOffer.js +23 -0
  119. package/lib/chevre/service/transaction/placeOrderInProgress/result.js +32 -16
  120. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateMovieTicket.js +13 -11
  121. package/lib/chevre/service/transaction/placeOrderInProgress/validation.js +53 -17
  122. package/lib/chevre/service/transaction/placeOrderInProgress.js +4 -1
  123. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +7 -6
  124. package/lib/chevre/service/transaction/returnOrder.js +5 -1
  125. package/lib/chevre/settings.d.ts +5 -3
  126. package/lib/chevre/settings.js +6 -6
  127. package/package.json +3 -3
  128. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  129. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
@@ -0,0 +1,534 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MongoRepository = void 0;
13
+ const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
14
+ /**
15
+ * 集計オファーリポジトリ
16
+ */
17
+ class MongoRepository {
18
+ constructor(connection) {
19
+ this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
20
+ }
21
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
22
+ static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
23
+ 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;
24
+ const matchStages = [];
25
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
26
+ if (typeof projectIdEq === 'string') {
27
+ matchStages.push({
28
+ $match: {
29
+ 'project.id': { $eq: projectIdEq }
30
+ }
31
+ });
32
+ }
33
+ const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
34
+ if (typeof idEq === 'string') {
35
+ matchStages.push({
36
+ $match: {
37
+ 'offers.id': { $eq: idEq }
38
+ }
39
+ });
40
+ }
41
+ const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
42
+ if (Array.isArray(idIn)) {
43
+ matchStages.push({
44
+ $match: {
45
+ 'offers.id': {
46
+ $in: idIn
47
+ }
48
+ }
49
+ });
50
+ }
51
+ const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
52
+ if (typeof identifierEq === 'string') {
53
+ matchStages.push({
54
+ $match: {
55
+ 'offers.identifier': {
56
+ $exists: true,
57
+ $eq: identifierEq
58
+ }
59
+ }
60
+ });
61
+ }
62
+ const identifierIn = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$in;
63
+ if (Array.isArray(identifierIn)) {
64
+ matchStages.push({
65
+ $match: {
66
+ 'offers.identifier': {
67
+ $exists: true,
68
+ $in: identifierIn
69
+ }
70
+ }
71
+ });
72
+ }
73
+ const identifierRegex = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$regex;
74
+ if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
75
+ matchStages.push({
76
+ $match: {
77
+ 'offers.identifier': {
78
+ $exists: true,
79
+ $regex: new RegExp(identifierRegex)
80
+ }
81
+ }
82
+ });
83
+ }
84
+ const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
85
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
86
+ const nameRegexExp = new RegExp(nameRegex);
87
+ matchStages.push({
88
+ $match: {
89
+ $or: [
90
+ {
91
+ 'offers.name.ja': {
92
+ $exists: true,
93
+ $regex: nameRegexExp
94
+ }
95
+ },
96
+ {
97
+ 'offers.name.en': {
98
+ $exists: true,
99
+ $regex: nameRegexExp
100
+ }
101
+ },
102
+ {
103
+ 'offers.alternateName.ja': {
104
+ $exists: true,
105
+ $regex: nameRegexExp
106
+ }
107
+ },
108
+ {
109
+ 'offers.alternateName.en': {
110
+ $exists: true,
111
+ $regex: nameRegexExp
112
+ }
113
+ }
114
+ ]
115
+ }
116
+ });
117
+ }
118
+ const itemOfferedTypeOfEq = (_k = (_j = params.itemOffered) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$eq;
119
+ if (typeof itemOfferedTypeOfEq === 'string') {
120
+ matchStages.push({
121
+ $match: {
122
+ 'offers.itemOffered.typeOf': {
123
+ $exists: true,
124
+ $eq: itemOfferedTypeOfEq
125
+ }
126
+ }
127
+ });
128
+ }
129
+ const categoryCodeValueIn = (_m = (_l = params.category) === null || _l === void 0 ? void 0 : _l.codeValue) === null || _m === void 0 ? void 0 : _m.$in;
130
+ if (Array.isArray(categoryCodeValueIn)) {
131
+ matchStages.push({
132
+ $match: {
133
+ 'offers.category.codeValue': {
134
+ $exists: true,
135
+ $in: categoryCodeValueIn
136
+ }
137
+ }
138
+ });
139
+ }
140
+ const eligibleMembershipTypeCodeValueEq = (_p = (_o = params.eligibleMembershipType) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$eq;
141
+ if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
142
+ matchStages.push({
143
+ $match: {
144
+ 'offers.eligibleMembershipType.codeValue': {
145
+ $exists: true,
146
+ $eq: eligibleMembershipTypeCodeValueEq
147
+ }
148
+ }
149
+ });
150
+ }
151
+ const eligibleMonetaryAmountCurrencyEq = (_r = (_q = params.eligibleMonetaryAmount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
152
+ if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
153
+ matchStages.push({
154
+ $match: {
155
+ 'offers.eligibleMonetaryAmount.currency': {
156
+ $exists: true,
157
+ $eq: eligibleMonetaryAmountCurrencyEq
158
+ }
159
+ }
160
+ });
161
+ }
162
+ const eligibleSeatingTypeCodeValueEq = (_t = (_s = params.eligibleSeatingType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
163
+ if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
164
+ matchStages.push({
165
+ $match: {
166
+ 'offers.eligibleSeatingType.codeValue': {
167
+ $exists: true,
168
+ $eq: eligibleSeatingTypeCodeValueEq
169
+ }
170
+ }
171
+ });
172
+ }
173
+ 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;
174
+ if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
175
+ matchStages.push({
176
+ $match: {
177
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
178
+ $exists: appliesToMovieTicketServiceTypeExist
179
+ }
180
+ }
181
+ });
182
+ }
183
+ 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;
184
+ if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
185
+ matchStages.push({
186
+ $match: {
187
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
188
+ $exists: true,
189
+ $eq: appliesToMovieTicketServiceTypeEq
190
+ }
191
+ }
192
+ });
193
+ }
194
+ 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;
195
+ if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
196
+ matchStages.push({
197
+ $match: {
198
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
199
+ $exists: true,
200
+ $eq: appliesToMovieTicketServiceOutputTypeOfEq
201
+ }
202
+ }
203
+ });
204
+ }
205
+ 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;
206
+ if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
207
+ matchStages.push({
208
+ $match: {
209
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
210
+ $nin: appliesToMovieTicketServiceOutputTypeOfNin
211
+ }
212
+ }
213
+ });
214
+ }
215
+ if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
216
+ const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
217
+ if (typeof priceSpecificationPriceGte === 'number') {
218
+ matchStages.push({
219
+ $match: {
220
+ 'offers.priceSpecification.price': {
221
+ $exists: true,
222
+ $gte: priceSpecificationPriceGte
223
+ }
224
+ }
225
+ });
226
+ }
227
+ const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
228
+ if (typeof priceSpecificationPriceLte === 'number') {
229
+ matchStages.push({
230
+ $match: {
231
+ 'offers.priceSpecification.price': {
232
+ $exists: true,
233
+ $lte: priceSpecificationPriceLte
234
+ }
235
+ }
236
+ });
237
+ }
238
+ const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
239
+ if (typeof accountsReceivableGte === 'number') {
240
+ matchStages.push({
241
+ $match: {
242
+ 'offers.priceSpecification.accounting.accountsReceivable': {
243
+ $exists: true,
244
+ $gte: accountsReceivableGte
245
+ }
246
+ }
247
+ });
248
+ }
249
+ const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
250
+ if (typeof accountsReceivableLte === 'number') {
251
+ matchStages.push({
252
+ $match: {
253
+ 'offers.priceSpecification.accounting.accountsReceivable': {
254
+ $exists: true,
255
+ $lte: accountsReceivableLte
256
+ }
257
+ }
258
+ });
259
+ }
260
+ 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;
261
+ if (typeof accountingCodeValueEq === 'string') {
262
+ matchStages.push({
263
+ $match: {
264
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
265
+ $exists: true,
266
+ $eq: accountingCodeValueEq
267
+ }
268
+ }
269
+ });
270
+ }
271
+ 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;
272
+ if (Array.isArray(accountingCodeValueIn)) {
273
+ matchStages.push({
274
+ $match: {
275
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
276
+ $exists: true,
277
+ $in: accountingCodeValueIn
278
+ }
279
+ }
280
+ });
281
+ }
282
+ const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
283
+ if (typeof referenceQuantityValueEq === 'number') {
284
+ matchStages.push({
285
+ $match: {
286
+ 'offers.priceSpecification.referenceQuantity.value': {
287
+ $exists: true,
288
+ $eq: referenceQuantityValueEq
289
+ }
290
+ }
291
+ });
292
+ }
293
+ }
294
+ const availabilityEq = (_22 = params.availability) === null || _22 === void 0 ? void 0 : _22.$eq;
295
+ if (typeof availabilityEq === 'string') {
296
+ matchStages.push({
297
+ $match: {
298
+ 'offers.availability': { $eq: availabilityEq }
299
+ }
300
+ });
301
+ }
302
+ const availableAtOrFromIdEq = (_24 = (_23 = params.availableAtOrFrom) === null || _23 === void 0 ? void 0 : _23.id) === null || _24 === void 0 ? void 0 : _24.$eq;
303
+ if (typeof availableAtOrFromIdEq === 'string') {
304
+ matchStages.push({
305
+ $match: {
306
+ 'offers.availableAtOrFrom.id': {
307
+ $exists: true,
308
+ $eq: availableAtOrFromIdEq
309
+ }
310
+ }
311
+ });
312
+ }
313
+ const availableAtOrFromIdIn = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$in;
314
+ if (Array.isArray(availableAtOrFromIdIn)) {
315
+ matchStages.push({
316
+ $match: {
317
+ 'offers.availableAtOrFrom.id': {
318
+ $exists: true,
319
+ $in: availableAtOrFromIdIn
320
+ }
321
+ }
322
+ });
323
+ }
324
+ 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;
325
+ if (typeof addOnItemOfferedIdEq === 'string') {
326
+ matchStages.push({
327
+ $match: {
328
+ 'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
329
+ }
330
+ });
331
+ }
332
+ 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;
333
+ if (Array.isArray(addOnItemOfferedIdIn)) {
334
+ matchStages.push({
335
+ $match: {
336
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
337
+ }
338
+ });
339
+ }
340
+ const hasMerchantReturnPolicyIdEq = (_34 = (_33 = params.hasMerchantReturnPolicy) === null || _33 === void 0 ? void 0 : _33.id) === null || _34 === void 0 ? void 0 : _34.$eq;
341
+ if (typeof hasMerchantReturnPolicyIdEq === 'string') {
342
+ matchStages.push({
343
+ $match: {
344
+ 'offers.hasMerchantReturnPolicy.id': {
345
+ $exists: true,
346
+ $eq: hasMerchantReturnPolicyIdEq
347
+ }
348
+ }
349
+ });
350
+ }
351
+ const additionalPropertyAll = (_35 = params.additionalProperty) === null || _35 === void 0 ? void 0 : _35.$all;
352
+ if (Array.isArray(additionalPropertyAll)) {
353
+ matchStages.push({
354
+ $match: {
355
+ 'offers.additionalProperty': {
356
+ $exists: true,
357
+ $all: additionalPropertyAll
358
+ }
359
+ }
360
+ });
361
+ }
362
+ const additionalPropertyElemMatch = (_36 = params.additionalProperty) === null || _36 === void 0 ? void 0 : _36.$elemMatch;
363
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
364
+ matchStages.push({
365
+ $match: {
366
+ 'offers.additionalProperty': {
367
+ $exists: true,
368
+ $elemMatch: additionalPropertyElemMatch
369
+ }
370
+ }
371
+ });
372
+ }
373
+ if (params.onlyValid === true) {
374
+ const now = new Date();
375
+ matchStages.push({
376
+ $match: {
377
+ $or: [
378
+ { 'offers.validFrom': { $exists: false } },
379
+ { 'offers.validFrom': { $exists: true, $lte: now } }
380
+ ]
381
+ }
382
+ }, {
383
+ $match: {
384
+ $or: [
385
+ { 'offers.validThrough': { $exists: false } },
386
+ { 'offers.validThrough': { $exists: true, $gte: now } }
387
+ ]
388
+ }
389
+ });
390
+ }
391
+ return matchStages;
392
+ }
393
+ static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
394
+ let projectStage = {
395
+ _id: 0,
396
+ id: '$_id',
397
+ typeOf: '$typeOf',
398
+ project: '$project',
399
+ offers: [{ $first: '$offers' }],
400
+ highPrice: { $max: '$offers.priceSpecification.price' },
401
+ lowPrice: { $min: '$offers.priceSpecification.price' },
402
+ offerCount: { $size: '$offers' }
403
+ };
404
+ const positiveProjectionFields = Object.keys(params)
405
+ .filter((key) => params[key] !== 0);
406
+ const negativeProjectionFields = Object.keys(params)
407
+ .filter((key) => params[key] === 0);
408
+ if (positiveProjectionFields.length > 0) {
409
+ projectStage = {
410
+ _id: 0,
411
+ id: '$_id',
412
+ typeOf: '$typeOf',
413
+ project: '$project',
414
+ // offers: [{ $first: '$offers' }],
415
+ highPrice: { $max: '$offers.priceSpecification.price' },
416
+ lowPrice: { $min: '$offers.priceSpecification.price' },
417
+ offerCount: { $size: '$offers' }
418
+ };
419
+ const offersProjection = {};
420
+ positiveProjectionFields.forEach((field) => {
421
+ offersProjection[field] = { $first: `$offers.${field}` };
422
+ });
423
+ projectStage.offers = [offersProjection];
424
+ }
425
+ else if (negativeProjectionFields.length > 0) {
426
+ negativeProjectionFields.forEach((field) => {
427
+ if (typeof projectStage[field] === 'string') {
428
+ // tslint:disable-next-line:no-dynamic-delete
429
+ delete projectStage[field];
430
+ }
431
+ });
432
+ }
433
+ return projectStage;
434
+ }
435
+ count(params) {
436
+ return __awaiter(this, void 0, void 0, function* () {
437
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
438
+ const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
439
+ ...matchStages,
440
+ {
441
+ $count: 'offerCount'
442
+ }
443
+ ])
444
+ .exec();
445
+ return offerCount;
446
+ });
447
+ }
448
+ search(params, projection) {
449
+ var _a, _b;
450
+ return __awaiter(this, void 0, void 0, function* () {
451
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
452
+ const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
453
+ const sortByPrice = (_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price'];
454
+ const sortByIdentifier = (_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier;
455
+ const aggregate = this.aggregateOfferModel.aggregate([
456
+ ...matchStages,
457
+ ...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
458
+ ? [
459
+ {
460
+ $sort: Object.assign(Object.assign({}, (typeof sortByPrice === 'number')
461
+ ? { 'offers.priceSpecification.price': sortByPrice }
462
+ : undefined), (typeof sortByIdentifier === 'number')
463
+ ? { 'offers.identifier': sortByIdentifier }
464
+ : undefined)
465
+ }
466
+ ]
467
+ : [],
468
+ { $project: projectStage }
469
+ ]);
470
+ // tslint:disable-next-line:no-single-line-block-comment
471
+ /* istanbul ignore else */
472
+ if (typeof params.limit === 'number' && params.limit > 0) {
473
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
474
+ aggregate.limit(params.limit * page)
475
+ .skip(params.limit * (page - 1));
476
+ }
477
+ return aggregate.exec();
478
+ });
479
+ }
480
+ pushIncludedInDataCatalog(params) {
481
+ return __awaiter(this, void 0, void 0, function* () {
482
+ if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
483
+ return;
484
+ }
485
+ const pushIncludedInDataCatalogIds = params.$push.includedInDataCatalog.$each.map((element) => element.id);
486
+ if (pushIncludedInDataCatalogIds.length === 0) {
487
+ return;
488
+ }
489
+ const newIncludedInDataCatalogs = pushIncludedInDataCatalogIds.map((catalogId) => {
490
+ return {
491
+ id: catalogId,
492
+ typeOf: 'OfferCatalog'
493
+ };
494
+ });
495
+ yield this.aggregateOfferModel.updateMany({
496
+ 'project.id': { $eq: params.project.id },
497
+ _id: { $in: params.id.$in },
498
+ // includedInDataCatalogのユニークネスを保証する
499
+ 'includedInDataCatalog.id': { $nin: pushIncludedInDataCatalogIds }
500
+ },
501
+ // { $addToSet: { includedInDataCatalog: { $each: newIncludedInDataCatalogs } } }
502
+ {
503
+ $push: {
504
+ includedInDataCatalog: {
505
+ $each: newIncludedInDataCatalogs
506
+ // $slice: params.$push.includedInDataCatalog.$slice
507
+ }
508
+ }
509
+ })
510
+ .exec();
511
+ });
512
+ }
513
+ /**
514
+ * 含まれるカタログからカタログを除外する
515
+ */
516
+ pullIncludedInDataCatalog(params) {
517
+ var _a;
518
+ return __awaiter(this, void 0, void 0, function* () {
519
+ const idNin = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$nin;
520
+ return this.aggregateOfferModel.updateMany(Object.assign({ 'project.id': { $eq: params.project.id }, 'includedInDataCatalog.id': {
521
+ $exists: true,
522
+ $eq: params.$pull.includedInDataCatalog.$elemMatch.id.$eq
523
+ } }, (Array.isArray(idNin)) ? { _id: { $nin: idNin } } : undefined), {
524
+ $pull: {
525
+ includedInDataCatalog: {
526
+ id: { $eq: params.$pull.includedInDataCatalog.$elemMatch.id.$eq }
527
+ }
528
+ }
529
+ })
530
+ .exec();
531
+ });
532
+ }
533
+ }
534
+ exports.MongoRepository = MongoRepository;
@@ -78,7 +78,14 @@ export declare class MongoRepository {
78
78
  confirm<T extends factory.assetTransactionType>(params: {
79
79
  typeOf: T;
80
80
  id: string;
81
- object?: Pick<factory.assetTransaction.reserve.IObject, 'underName'>;
81
+ object?: Pick<factory.assetTransaction.reserve.IObject, 'underName'> & {
82
+ /**
83
+ * 決済取引における決済方法区分指定
84
+ */
85
+ paymentMethod?: {
86
+ identifier?: string;
87
+ };
88
+ };
82
89
  result: factory.assetTransaction.IResult<T>;
83
90
  potentialActions: factory.assetTransaction.IPotentialActions<T>;
84
91
  }): Promise<void>;
@@ -182,6 +189,14 @@ export declare class MongoRepository {
182
189
  id: string;
183
190
  update: any;
184
191
  }): Promise<factory.assetTransaction.ITransaction<T>>;
192
+ migratePaymentMethodIdentifier(params: {
193
+ transactionNumber: string;
194
+ object: {
195
+ paymentMethod: {
196
+ identifier: string;
197
+ };
198
+ };
199
+ }): Promise<any>;
185
200
  findByIdAndDelete(params: {
186
201
  id: string;
187
202
  }): Promise<void>;
@@ -344,14 +344,16 @@ class MongoRepository {
344
344
  * 取引を確定する
345
345
  */
346
346
  confirm(params) {
347
- var _a, _b;
347
+ var _a, _b, _c, _d;
348
348
  return __awaiter(this, void 0, void 0, function* () {
349
349
  const doc = yield this.transactionModel.findOneAndUpdate({
350
350
  _id: { $eq: params.id },
351
351
  typeOf: { $eq: params.typeOf },
352
352
  status: { $eq: factory.transactionStatusType.InProgress }
353
- }, Object.assign({ status: factory.transactionStatusType.Confirmed, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
353
+ }, Object.assign(Object.assign({ status: factory.transactionStatusType.Confirmed, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }, (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.underName) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string')
354
354
  ? { 'object.underName': params.object.underName }
355
+ : undefined), (typeof ((_d = (_c = params.object) === null || _c === void 0 ? void 0 : _c.paymentMethod) === null || _d === void 0 ? void 0 : _d.identifier) === 'string')
356
+ ? { 'object.paymentMethod.identifier': params.object.paymentMethod.identifier }
355
357
  : undefined), {
356
358
  new: true,
357
359
  projection: { _id: 1 }
@@ -704,6 +706,55 @@ class MongoRepository {
704
706
  });
705
707
  });
706
708
  }
709
+ migratePaymentMethodIdentifier(params) {
710
+ return __awaiter(this, void 0, void 0, function* () {
711
+ return this.transactionModel.findOneAndUpdate({
712
+ typeOf: { $eq: factory.assetTransactionType.Pay },
713
+ transactionNumber: { $exists: true, $eq: params.transactionNumber }
714
+ }, { 'object.paymentMethod.identifier': params.object.paymentMethod.identifier }, {
715
+ new: true,
716
+ projection: { _id: 1 }
717
+ })
718
+ .exec()
719
+ .then((doc) => {
720
+ if (doc === null) {
721
+ throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
722
+ }
723
+ return doc.toObject();
724
+ });
725
+ });
726
+ }
727
+ // public async migratePaymentMethodIdentifierMany() {
728
+ // // return this.transactionModel.updateMany(
729
+ // // {
730
+ // // typeOf: { $eq: factory.assetTransactionType.Pay }
731
+ // // // 'object.paymentMethod.identifier': { $exists: false }
732
+ // // },
733
+ // // { $set: { 'object.paymentMethod.identifier': '$object.paymentMethod.typeOf' } }
734
+ // // )
735
+ // // .exec();
736
+ // return this.transactionModel.aggregate([
737
+ // {
738
+ // $match: {
739
+ // typeOf: { $eq: factory.assetTransactionType.Pay }
740
+ // }
741
+ // },
742
+ // {
743
+ // $project: {
744
+ // paymentMethodIdentifier: '$object.paymentMethod.typeOf'
745
+ // }
746
+ // },
747
+ // {
748
+ // $unset: ['object.paymentMethod.identifier']
749
+ // }
750
+ // // {
751
+ // // $set: {
752
+ // // 'object.paymentMethod.identifier': '$paymentMethodIdentifier'
753
+ // // }
754
+ // // }
755
+ // ])
756
+ // .exec();
757
+ // }
707
758
  findByIdAndDelete(params) {
708
759
  return __awaiter(this, void 0, void 0, function* () {
709
760
  yield this.transactionModel.findByIdAndDelete(params.id)
@@ -713,6 +764,7 @@ class MongoRepository {
713
764
  getCursor(conditions, projection) {
714
765
  return this.transactionModel.find(conditions, projection)
715
766
  .sort({ startDate: factory.sortType.Ascending })
767
+ // .sort({ startDate: factory.sortType.Descending })
716
768
  .cursor();
717
769
  }
718
770
  aggregateAssetTransaction(params) {