@chevre/domain 21.8.0-alpha.9 → 21.8.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 (131) 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/searchEventTicketOffers.ts +5 -1
  14. package/example/src/chevre/searchEvents.ts +9 -7
  15. package/example/src/chevre/searchOfferCatalogs.ts +7 -3
  16. package/example/src/chevre/searchOffers.ts +5 -2
  17. package/example/src/chevre/searchOffersByCatalog.ts +15 -9
  18. package/example/src/chevre/searchOffersFromAggregateOffer.ts +168 -0
  19. package/example/src/chevre/searchOrders.ts +9 -7
  20. package/example/src/chevre/syncCatalogs2aggregateOffers.ts +85 -0
  21. package/lib/chevre/emailMessageBuilder.js +6 -5
  22. package/lib/chevre/repo/aggregateOffer.d.ts +62 -0
  23. package/lib/chevre/repo/aggregateOffer.js +562 -0
  24. package/lib/chevre/repo/assetTransaction.d.ts +16 -1
  25. package/lib/chevre/repo/assetTransaction.js +54 -2
  26. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.d.ts +74 -0
  27. package/lib/chevre/repo/mongoose/schemas/aggregateOffer.js +189 -0
  28. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +3 -3
  29. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +3 -3
  30. package/lib/chevre/repo/mongoose/schemas/event.d.ts +3 -3
  31. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +3 -0
  32. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +10 -1
  33. package/lib/chevre/repo/mongoose/schemas/order.d.ts +3 -0
  34. package/lib/chevre/repo/mongoose/schemas/order.js +7 -0
  35. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +9 -9
  36. package/lib/chevre/repo/mongoose/schemas/product.d.ts +3 -3
  37. package/lib/chevre/repo/mongoose/schemas/project.d.ts +3 -3
  38. package/lib/chevre/repo/mongoose/schemas/task.d.ts +3 -0
  39. package/lib/chevre/repo/mongoose/schemas/task.js +8 -0
  40. package/lib/chevre/repo/offer.d.ts +87 -51
  41. package/lib/chevre/repo/offer.js +513 -283
  42. package/lib/chevre/repo/offerCatalog.d.ts +32 -3
  43. package/lib/chevre/repo/offerCatalog.js +97 -10
  44. package/lib/chevre/repo/order.d.ts +15 -0
  45. package/lib/chevre/repo/order.js +58 -26
  46. package/lib/chevre/repo/task.d.ts +6 -2
  47. package/lib/chevre/repo/task.js +58 -4
  48. package/lib/chevre/repository.d.ts +3 -0
  49. package/lib/chevre/repository.js +5 -1
  50. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +3 -41
  51. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.d.ts +2 -0
  52. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +2 -40
  53. package/lib/chevre/service/aggregation/event/findEventOffers.d.ts +16 -0
  54. package/lib/chevre/service/aggregation/event/findEventOffers.js +58 -0
  55. package/lib/chevre/service/assetTransaction/pay/account/validation.js +2 -2
  56. package/lib/chevre/service/assetTransaction/pay/factory.js +26 -18
  57. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +3 -3
  58. package/lib/chevre/service/assetTransaction/pay.js +65 -46
  59. package/lib/chevre/service/assetTransaction/refund/factory.js +8 -2
  60. package/lib/chevre/service/assetTransaction/registerService.js +2 -1
  61. package/lib/chevre/service/assetTransaction/reserve.js +111 -35
  62. package/lib/chevre/service/offer/event/authorize.js +39 -35
  63. package/lib/chevre/service/offer/event/factory.d.ts +1 -1
  64. package/lib/chevre/service/offer/event/factory.js +8 -8
  65. package/lib/chevre/service/offer/event/importFromCOA.d.ts +2 -0
  66. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +3 -0
  67. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +48 -17
  68. package/lib/chevre/service/offer/event/voidTransaction.js +57 -36
  69. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  70. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +7 -11
  71. package/lib/chevre/service/offer/eventServiceByCOA.js +55 -27
  72. package/lib/chevre/service/offer/factory.d.ts +12 -4
  73. package/lib/chevre/service/offer/factory.js +9 -11
  74. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +10 -1
  75. package/lib/chevre/service/offer/product/searchProductOffers.js +51 -12
  76. package/lib/chevre/service/offer/product.d.ts +2 -0
  77. package/lib/chevre/service/offer/product.js +3 -2
  78. package/lib/chevre/service/offer.d.ts +1 -0
  79. package/lib/chevre/service/offer.js +7 -1
  80. package/lib/chevre/service/order/confirmPayTransaction.d.ts +0 -2
  81. package/lib/chevre/service/order/confirmPayTransaction.js +20 -46
  82. package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +27 -0
  83. package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +226 -0
  84. package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +8 -6
  85. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +80 -57
  86. package/lib/chevre/service/order/onOrderStatusChanged.js +49 -9
  87. package/lib/chevre/service/order/payOrder.js +4 -45
  88. package/lib/chevre/service/order/placeOrder.js +11 -24
  89. package/lib/chevre/service/order.d.ts +3 -1
  90. package/lib/chevre/service/order.js +6 -2
  91. package/lib/chevre/service/payment/any/factory.js +33 -8
  92. package/lib/chevre/service/payment/any.js +30 -21
  93. package/lib/chevre/service/payment/creditCard.js +12 -12
  94. package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
  95. package/lib/chevre/service/payment/movieTicket.js +10 -11
  96. package/lib/chevre/service/payment/paymentCard.js +9 -12
  97. package/lib/chevre/service/project.js +1 -1
  98. package/lib/chevre/service/reserve/checkInReservation.d.ts +8 -0
  99. package/lib/chevre/service/reserve/checkInReservation.js +3 -2
  100. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +3 -0
  101. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +4 -5
  102. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.d.ts +8 -0
  103. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +16 -11
  104. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  105. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.d.ts +3 -0
  106. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +3 -5
  107. package/lib/chevre/service/task/aggregateUseActionsOnEvent.js +2 -0
  108. package/lib/chevre/service/task/confirmPayTransaction.js +1 -3
  109. package/lib/chevre/service/task/importOffersFromCOA.js +3 -0
  110. package/lib/chevre/service/task/onAssetTransactionStatusChanged.d.ts +6 -0
  111. package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +37 -0
  112. package/lib/chevre/service/task/onAuthorizationCreated.js +5 -1
  113. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
  114. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -0
  115. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.d.ts +17 -0
  116. package/lib/chevre/service/task/onResourceUpdated/syncOfferCatalog.js +78 -0
  117. package/lib/chevre/service/task/onResourceUpdated.js +12 -0
  118. package/lib/chevre/service/task/returnPayTransaction.js +8 -3
  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 +3 -3
  126. package/lib/chevre/settings.js +4 -12
  127. package/package.json +3 -3
  128. package/example/src/chevre/migrateAuthorizePaymentActionResult.ts +0 -83
  129. package/example/src/chevre/migrateEventOrganizer.ts +0 -154
  130. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +0 -149
  131. package/lib/chevre/repo/mongoose/schemas/offer.js +0 -210
@@ -0,0 +1,562 @@
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 createDebug = require("debug");
14
+ const aggregateOffer_1 = require("./mongoose/schemas/aggregateOffer");
15
+ const debug = createDebug('chevre-domain:repo:aggregateOffer');
16
+ /**
17
+ * 集計オファーリポジトリ
18
+ */
19
+ class MongoRepository {
20
+ constructor(connection) {
21
+ this.aggregateOfferModel = connection.model(aggregateOffer_1.modelName, aggregateOffer_1.schema);
22
+ }
23
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
24
+ static CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params) {
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36;
26
+ const matchStages = [];
27
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
28
+ if (typeof projectIdEq === 'string') {
29
+ matchStages.push({
30
+ $match: {
31
+ 'project.id': { $eq: projectIdEq }
32
+ }
33
+ });
34
+ }
35
+ const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
36
+ if (typeof idEq === 'string') {
37
+ matchStages.push({
38
+ $match: {
39
+ 'offers.id': { $eq: idEq }
40
+ }
41
+ });
42
+ }
43
+ const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
44
+ if (Array.isArray(idIn)) {
45
+ matchStages.push({
46
+ $match: {
47
+ 'offers.id': {
48
+ $in: idIn
49
+ }
50
+ }
51
+ });
52
+ }
53
+ const identifierEq = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$eq;
54
+ if (typeof identifierEq === 'string') {
55
+ matchStages.push({
56
+ $match: {
57
+ 'offers.identifier': {
58
+ $exists: true,
59
+ $eq: identifierEq
60
+ }
61
+ }
62
+ });
63
+ }
64
+ const identifierIn = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$in;
65
+ if (Array.isArray(identifierIn)) {
66
+ matchStages.push({
67
+ $match: {
68
+ 'offers.identifier': {
69
+ $exists: true,
70
+ $in: identifierIn
71
+ }
72
+ }
73
+ });
74
+ }
75
+ const identifierRegex = (_g = params.identifier) === null || _g === void 0 ? void 0 : _g.$regex;
76
+ if (typeof identifierRegex === 'string' && identifierRegex.length > 0) {
77
+ matchStages.push({
78
+ $match: {
79
+ 'offers.identifier': {
80
+ $exists: true,
81
+ $regex: new RegExp(identifierRegex)
82
+ }
83
+ }
84
+ });
85
+ }
86
+ const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
87
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
88
+ const nameRegexExp = new RegExp(nameRegex);
89
+ matchStages.push({
90
+ $match: {
91
+ $or: [
92
+ {
93
+ 'offers.name.ja': {
94
+ $exists: true,
95
+ $regex: nameRegexExp
96
+ }
97
+ },
98
+ {
99
+ 'offers.name.en': {
100
+ $exists: true,
101
+ $regex: nameRegexExp
102
+ }
103
+ },
104
+ {
105
+ 'offers.alternateName.ja': {
106
+ $exists: true,
107
+ $regex: nameRegexExp
108
+ }
109
+ },
110
+ {
111
+ 'offers.alternateName.en': {
112
+ $exists: true,
113
+ $regex: nameRegexExp
114
+ }
115
+ }
116
+ ]
117
+ }
118
+ });
119
+ }
120
+ const itemOfferedTypeOfEq = (_k = (_j = params.itemOffered) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$eq;
121
+ if (typeof itemOfferedTypeOfEq === 'string') {
122
+ matchStages.push({
123
+ $match: {
124
+ 'offers.itemOffered.typeOf': {
125
+ $exists: true,
126
+ $eq: itemOfferedTypeOfEq
127
+ }
128
+ }
129
+ });
130
+ }
131
+ const categoryCodeValueIn = (_m = (_l = params.category) === null || _l === void 0 ? void 0 : _l.codeValue) === null || _m === void 0 ? void 0 : _m.$in;
132
+ if (Array.isArray(categoryCodeValueIn)) {
133
+ matchStages.push({
134
+ $match: {
135
+ 'offers.category.codeValue': {
136
+ $exists: true,
137
+ $in: categoryCodeValueIn
138
+ }
139
+ }
140
+ });
141
+ }
142
+ const eligibleMembershipTypeCodeValueEq = (_p = (_o = params.eligibleMembershipType) === null || _o === void 0 ? void 0 : _o.codeValue) === null || _p === void 0 ? void 0 : _p.$eq;
143
+ if (typeof eligibleMembershipTypeCodeValueEq === 'string') {
144
+ matchStages.push({
145
+ $match: {
146
+ 'offers.eligibleMembershipType.codeValue': {
147
+ $exists: true,
148
+ $eq: eligibleMembershipTypeCodeValueEq
149
+ }
150
+ }
151
+ });
152
+ }
153
+ const eligibleMonetaryAmountCurrencyEq = (_r = (_q = params.eligibleMonetaryAmount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
154
+ if (typeof eligibleMonetaryAmountCurrencyEq === 'string') {
155
+ matchStages.push({
156
+ $match: {
157
+ 'offers.eligibleMonetaryAmount.currency': {
158
+ $exists: true,
159
+ $eq: eligibleMonetaryAmountCurrencyEq
160
+ }
161
+ }
162
+ });
163
+ }
164
+ const eligibleSeatingTypeCodeValueEq = (_t = (_s = params.eligibleSeatingType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
165
+ if (typeof eligibleSeatingTypeCodeValueEq === 'string') {
166
+ matchStages.push({
167
+ $match: {
168
+ 'offers.eligibleSeatingType.codeValue': {
169
+ $exists: true,
170
+ $eq: eligibleSeatingTypeCodeValueEq
171
+ }
172
+ }
173
+ });
174
+ }
175
+ 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;
176
+ if (typeof appliesToMovieTicketServiceTypeExist === 'boolean') {
177
+ matchStages.push({
178
+ $match: {
179
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
180
+ $exists: appliesToMovieTicketServiceTypeExist
181
+ }
182
+ }
183
+ });
184
+ }
185
+ 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;
186
+ if (typeof appliesToMovieTicketServiceTypeEq === 'string') {
187
+ matchStages.push({
188
+ $match: {
189
+ 'offers.priceSpecification.appliesToMovieTicket.serviceType': {
190
+ $exists: true,
191
+ $eq: appliesToMovieTicketServiceTypeEq
192
+ }
193
+ }
194
+ });
195
+ }
196
+ 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;
197
+ if (typeof appliesToMovieTicketServiceOutputTypeOfEq === 'string') {
198
+ matchStages.push({
199
+ $match: {
200
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
201
+ $exists: true,
202
+ $eq: appliesToMovieTicketServiceOutputTypeOfEq
203
+ }
204
+ }
205
+ });
206
+ }
207
+ 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;
208
+ if (Array.isArray(appliesToMovieTicketServiceOutputTypeOfNin)) {
209
+ matchStages.push({
210
+ $match: {
211
+ 'offers.priceSpecification.appliesToMovieTicket.serviceOutput.typeOf': {
212
+ $nin: appliesToMovieTicketServiceOutputTypeOfNin
213
+ }
214
+ }
215
+ });
216
+ }
217
+ if (params.priceSpecification !== undefined && params.priceSpecification !== null) {
218
+ const priceSpecificationPriceGte = (_8 = params.priceSpecification.price) === null || _8 === void 0 ? void 0 : _8.$gte;
219
+ if (typeof priceSpecificationPriceGte === 'number') {
220
+ matchStages.push({
221
+ $match: {
222
+ 'offers.priceSpecification.price': {
223
+ $exists: true,
224
+ $gte: priceSpecificationPriceGte
225
+ }
226
+ }
227
+ });
228
+ }
229
+ const priceSpecificationPriceLte = (_9 = params.priceSpecification.price) === null || _9 === void 0 ? void 0 : _9.$lte;
230
+ if (typeof priceSpecificationPriceLte === 'number') {
231
+ matchStages.push({
232
+ $match: {
233
+ 'offers.priceSpecification.price': {
234
+ $exists: true,
235
+ $lte: priceSpecificationPriceLte
236
+ }
237
+ }
238
+ });
239
+ }
240
+ const accountsReceivableGte = (_11 = (_10 = params.priceSpecification.accounting) === null || _10 === void 0 ? void 0 : _10.accountsReceivable) === null || _11 === void 0 ? void 0 : _11.$gte;
241
+ if (typeof accountsReceivableGte === 'number') {
242
+ matchStages.push({
243
+ $match: {
244
+ 'offers.priceSpecification.accounting.accountsReceivable': {
245
+ $exists: true,
246
+ $gte: accountsReceivableGte
247
+ }
248
+ }
249
+ });
250
+ }
251
+ const accountsReceivableLte = (_13 = (_12 = params.priceSpecification.accounting) === null || _12 === void 0 ? void 0 : _12.accountsReceivable) === null || _13 === void 0 ? void 0 : _13.$lte;
252
+ if (typeof accountsReceivableLte === 'number') {
253
+ matchStages.push({
254
+ $match: {
255
+ 'offers.priceSpecification.accounting.accountsReceivable': {
256
+ $exists: true,
257
+ $lte: accountsReceivableLte
258
+ }
259
+ }
260
+ });
261
+ }
262
+ 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;
263
+ if (typeof accountingCodeValueEq === 'string') {
264
+ matchStages.push({
265
+ $match: {
266
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
267
+ $exists: true,
268
+ $eq: accountingCodeValueEq
269
+ }
270
+ }
271
+ });
272
+ }
273
+ 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;
274
+ if (Array.isArray(accountingCodeValueIn)) {
275
+ matchStages.push({
276
+ $match: {
277
+ 'offers.priceSpecification.accounting.operatingRevenue.codeValue': {
278
+ $exists: true,
279
+ $in: accountingCodeValueIn
280
+ }
281
+ }
282
+ });
283
+ }
284
+ const referenceQuantityValueEq = (_21 = (_20 = params.priceSpecification.referenceQuantity) === null || _20 === void 0 ? void 0 : _20.value) === null || _21 === void 0 ? void 0 : _21.$eq;
285
+ if (typeof referenceQuantityValueEq === 'number') {
286
+ matchStages.push({
287
+ $match: {
288
+ 'offers.priceSpecification.referenceQuantity.value': {
289
+ $exists: true,
290
+ $eq: referenceQuantityValueEq
291
+ }
292
+ }
293
+ });
294
+ }
295
+ }
296
+ const availabilityEq = (_22 = params.availability) === null || _22 === void 0 ? void 0 : _22.$eq;
297
+ if (typeof availabilityEq === 'string') {
298
+ matchStages.push({
299
+ $match: {
300
+ 'offers.availability': { $eq: availabilityEq }
301
+ }
302
+ });
303
+ }
304
+ const availableAtOrFromIdEq = (_24 = (_23 = params.availableAtOrFrom) === null || _23 === void 0 ? void 0 : _23.id) === null || _24 === void 0 ? void 0 : _24.$eq;
305
+ if (typeof availableAtOrFromIdEq === 'string') {
306
+ matchStages.push({
307
+ $match: {
308
+ 'offers.availableAtOrFrom.id': {
309
+ $exists: true,
310
+ $eq: availableAtOrFromIdEq
311
+ }
312
+ }
313
+ });
314
+ }
315
+ const availableAtOrFromIdIn = (_26 = (_25 = params.availableAtOrFrom) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$in;
316
+ if (Array.isArray(availableAtOrFromIdIn)) {
317
+ matchStages.push({
318
+ $match: {
319
+ 'offers.availableAtOrFrom.id': {
320
+ $exists: true,
321
+ $in: availableAtOrFromIdIn
322
+ }
323
+ }
324
+ });
325
+ }
326
+ 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;
327
+ if (typeof addOnItemOfferedIdEq === 'string') {
328
+ matchStages.push({
329
+ $match: {
330
+ 'offers.addOn.itemOffered.id': { $exists: true, $eq: addOnItemOfferedIdEq }
331
+ }
332
+ });
333
+ }
334
+ 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;
335
+ if (Array.isArray(addOnItemOfferedIdIn)) {
336
+ matchStages.push({
337
+ $match: {
338
+ 'offers.addOn.itemOffered.id': { $exists: true, $in: addOnItemOfferedIdIn }
339
+ }
340
+ });
341
+ }
342
+ const hasMerchantReturnPolicyIdEq = (_34 = (_33 = params.hasMerchantReturnPolicy) === null || _33 === void 0 ? void 0 : _33.id) === null || _34 === void 0 ? void 0 : _34.$eq;
343
+ if (typeof hasMerchantReturnPolicyIdEq === 'string') {
344
+ matchStages.push({
345
+ $match: {
346
+ 'offers.hasMerchantReturnPolicy.id': {
347
+ $exists: true,
348
+ $eq: hasMerchantReturnPolicyIdEq
349
+ }
350
+ }
351
+ });
352
+ }
353
+ const additionalPropertyAll = (_35 = params.additionalProperty) === null || _35 === void 0 ? void 0 : _35.$all;
354
+ if (Array.isArray(additionalPropertyAll)) {
355
+ matchStages.push({
356
+ $match: {
357
+ 'offers.additionalProperty': {
358
+ $exists: true,
359
+ $all: additionalPropertyAll
360
+ }
361
+ }
362
+ });
363
+ }
364
+ const additionalPropertyElemMatch = (_36 = params.additionalProperty) === null || _36 === void 0 ? void 0 : _36.$elemMatch;
365
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
366
+ matchStages.push({
367
+ $match: {
368
+ 'offers.additionalProperty': {
369
+ $exists: true,
370
+ $elemMatch: additionalPropertyElemMatch
371
+ }
372
+ }
373
+ });
374
+ }
375
+ if (params.onlyValid === true) {
376
+ const now = new Date();
377
+ matchStages.push({
378
+ $match: {
379
+ $or: [
380
+ { 'offers.validFrom': { $exists: false } },
381
+ { 'offers.validFrom': { $exists: true, $lte: now } }
382
+ ]
383
+ }
384
+ }, {
385
+ $match: {
386
+ $or: [
387
+ { 'offers.validThrough': { $exists: false } },
388
+ { 'offers.validThrough': { $exists: true, $gte: now } }
389
+ ]
390
+ }
391
+ });
392
+ }
393
+ return matchStages;
394
+ }
395
+ static CREATE_AGGREGATE_OFFERS_PROJECTION(params) {
396
+ let projectStage = {
397
+ _id: 0,
398
+ id: '$_id',
399
+ typeOf: '$typeOf',
400
+ project: '$project',
401
+ offers: [{ $first: '$offers' }],
402
+ highPrice: { $max: '$offers.priceSpecification.price' },
403
+ lowPrice: { $min: '$offers.priceSpecification.price' },
404
+ offerCount: { $size: '$offers' }
405
+ };
406
+ const positiveProjectionFields = Object.keys(params)
407
+ .filter((key) => params[key] !== 0);
408
+ const negativeProjectionFields = Object.keys(params)
409
+ .filter((key) => params[key] === 0);
410
+ if (positiveProjectionFields.length > 0) {
411
+ projectStage = {
412
+ _id: 0,
413
+ id: '$_id',
414
+ typeOf: '$typeOf',
415
+ project: '$project',
416
+ // offers: [{ $first: '$offers' }],
417
+ highPrice: { $max: '$offers.priceSpecification.price' },
418
+ lowPrice: { $min: '$offers.priceSpecification.price' },
419
+ offerCount: { $size: '$offers' }
420
+ };
421
+ const offersProjection = {};
422
+ positiveProjectionFields.forEach((field) => {
423
+ offersProjection[field] = { $first: `$offers.${field}` };
424
+ });
425
+ projectStage.offers = [offersProjection];
426
+ }
427
+ else if (negativeProjectionFields.length > 0) {
428
+ negativeProjectionFields.forEach((field) => {
429
+ if (typeof projectStage[field] === 'string') {
430
+ // tslint:disable-next-line:no-dynamic-delete
431
+ delete projectStage[field];
432
+ }
433
+ });
434
+ }
435
+ return projectStage;
436
+ }
437
+ count(params) {
438
+ return __awaiter(this, void 0, void 0, function* () {
439
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
440
+ const [{ offerCount }] = yield this.aggregateOfferModel.aggregate([
441
+ ...matchStages,
442
+ {
443
+ $count: 'offerCount'
444
+ }
445
+ ])
446
+ .exec();
447
+ return offerCount;
448
+ });
449
+ }
450
+ search(params, projection) {
451
+ var _a, _b;
452
+ return __awaiter(this, void 0, void 0, function* () {
453
+ const matchStages = MongoRepository.CREATE_AGGREGATE_OFFERS_MATCH_CONDITIONS(params);
454
+ const projectStage = MongoRepository.CREATE_AGGREGATE_OFFERS_PROJECTION(Object.assign({}, projection));
455
+ const sortByPrice = (_a = params.sort) === null || _a === void 0 ? void 0 : _a['priceSpecification.price'];
456
+ const sortByIdentifier = (_b = params.sort) === null || _b === void 0 ? void 0 : _b.identifier;
457
+ const aggregate = this.aggregateOfferModel.aggregate([
458
+ ...matchStages,
459
+ ...(typeof sortByPrice === 'number' || typeof sortByIdentifier === 'number')
460
+ ? [
461
+ {
462
+ $sort: Object.assign(Object.assign({}, (typeof sortByPrice === 'number')
463
+ ? { 'offers.priceSpecification.price': sortByPrice }
464
+ : undefined), (typeof sortByIdentifier === 'number')
465
+ ? { 'offers.identifier': sortByIdentifier }
466
+ : undefined)
467
+ }
468
+ ]
469
+ : [],
470
+ { $project: projectStage }
471
+ ]);
472
+ // tslint:disable-next-line:no-single-line-block-comment
473
+ /* istanbul ignore else */
474
+ if (typeof params.limit === 'number' && params.limit > 0) {
475
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
476
+ aggregate.limit(params.limit * page)
477
+ .skip(params.limit * (page - 1));
478
+ }
479
+ return aggregate.exec();
480
+ });
481
+ }
482
+ pushIncludedInDataCatalog(params) {
483
+ return __awaiter(this, void 0, void 0, function* () {
484
+ if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
485
+ return;
486
+ }
487
+ const pushIncludedInDataCatalogIds = params.$push.includedInDataCatalog.$each.map((element) => element.id);
488
+ if (pushIncludedInDataCatalogIds.length === 0) {
489
+ return;
490
+ }
491
+ const newIncludedInDataCatalogs = pushIncludedInDataCatalogIds.map((catalogId) => {
492
+ return {
493
+ id: catalogId,
494
+ typeOf: 'OfferCatalog'
495
+ };
496
+ });
497
+ let result = yield this.aggregateOfferModel.updateMany({
498
+ 'project.id': { $eq: params.project.id },
499
+ _id: { $in: params.id.$in },
500
+ // includedInDataCatalogのユニークネスを保証する
501
+ 'includedInDataCatalog.id': { $nin: pushIncludedInDataCatalogIds }
502
+ },
503
+ // { $addToSet: { includedInDataCatalog: { $each: newIncludedInDataCatalogs } } }
504
+ {
505
+ $push: {
506
+ includedInDataCatalog: {
507
+ $each: newIncludedInDataCatalogs
508
+ // $slice: params.$push.includedInDataCatalog.$slice
509
+ }
510
+ }
511
+ })
512
+ .exec();
513
+ debug('result', result);
514
+ // offersにもpush
515
+ result = yield this.aggregateOfferModel.updateMany({
516
+ 'project.id': { $eq: params.project.id },
517
+ _id: { $in: params.id.$in }
518
+ }, {
519
+ $push: {
520
+ 'offers.$[offer].includedInDataCatalog': {
521
+ $each: newIncludedInDataCatalogs
522
+ }
523
+ }
524
+ }, {
525
+ // includedInDataCatalogのユニークネスを保証する
526
+ arrayFilters: [
527
+ { 'offer.includedInDataCatalog.id': { $nin: pushIncludedInDataCatalogIds } }
528
+ ]
529
+ })
530
+ .exec();
531
+ debug('result', result);
532
+ });
533
+ }
534
+ /**
535
+ * 記載カタログからカタログを除外する
536
+ */
537
+ pullIncludedInDataCatalog(params) {
538
+ var _a;
539
+ return __awaiter(this, void 0, void 0, function* () {
540
+ const idNin = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$nin;
541
+ const pullingCatalogId = params.$pull.includedInDataCatalog.$elemMatch.id.$eq;
542
+ yield this.aggregateOfferModel.updateMany(Object.assign({ 'project.id': { $eq: params.project.id }, 'includedInDataCatalog.id': { $exists: true, $eq: pullingCatalogId } }, (Array.isArray(idNin)) ? { _id: { $nin: idNin } } : undefined), {
543
+ $pull: {
544
+ includedInDataCatalog: {
545
+ id: { $eq: pullingCatalogId }
546
+ }
547
+ }
548
+ })
549
+ .exec();
550
+ // 全offersからもpull
551
+ yield this.aggregateOfferModel.updateMany(Object.assign({ 'project.id': { $eq: params.project.id }, 'offers.includedInDataCatalog.id': { $exists: true, $eq: pullingCatalogId } }, (Array.isArray(idNin)) ? { _id: { $nin: idNin } } : undefined), {
552
+ $pull: {
553
+ 'offers.$[].includedInDataCatalog': {
554
+ id: { $eq: pullingCatalogId }
555
+ }
556
+ }
557
+ })
558
+ .exec();
559
+ });
560
+ }
561
+ }
562
+ 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) {