@chevre/domain 20.2.0-alpha.4 → 20.2.0-alpha.41

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 (118) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +37 -0
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +112 -0
  3. package/example/src/chevre/attendIfNotAttended.ts +22 -0
  4. package/example/src/chevre/findScreeningRoomsByBranchCode.ts +27 -0
  5. package/example/src/chevre/importEventsFromCOA.ts +8 -1
  6. package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
  7. package/example/src/chevre/migrateProjectSubscription.ts +51 -0
  8. package/example/src/chevre/processReserve.ts +2 -0
  9. package/example/src/chevre/searchEventIds.ts +24 -0
  10. package/example/src/chevre/searchEventTicketOffers.ts +4 -4
  11. package/example/src/chevre/searchEvents.ts +20 -41
  12. package/example/src/chevre/searchOffersByCatalog.ts +27 -0
  13. package/example/src/chevre/updateTransaction.ts +38 -0
  14. package/lib/chevre/factory/event.d.ts +2 -0
  15. package/lib/chevre/factory/event.js +2 -0
  16. package/lib/chevre/repo/action.d.ts +67 -0
  17. package/lib/chevre/repo/action.js +209 -0
  18. package/lib/chevre/repo/aggregation.d.ts +37 -0
  19. package/lib/chevre/repo/aggregation.js +67 -0
  20. package/lib/chevre/repo/assetTransaction.d.ts +32 -0
  21. package/lib/chevre/repo/assetTransaction.js +148 -0
  22. package/lib/chevre/repo/event.d.ts +62 -16
  23. package/lib/chevre/repo/event.js +458 -156
  24. package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
  25. package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
  26. package/lib/chevre/repo/mongoose/model/event.js +4 -3
  27. package/lib/chevre/repo/mongoose/model/offer.js +2 -1
  28. package/lib/chevre/repo/mongoose/model/project.js +7 -1
  29. package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
  30. package/lib/chevre/repo/offer.d.ts +10 -0
  31. package/lib/chevre/repo/offer.js +47 -16
  32. package/lib/chevre/repo/order.d.ts +2 -0
  33. package/lib/chevre/repo/order.js +29 -7
  34. package/lib/chevre/repo/place.d.ts +26 -1
  35. package/lib/chevre/repo/place.js +216 -12
  36. package/lib/chevre/repo/product.d.ts +1 -0
  37. package/lib/chevre/repo/product.js +5 -0
  38. package/lib/chevre/repo/project.d.ts +4 -1
  39. package/lib/chevre/repo/project.js +9 -10
  40. package/lib/chevre/repo/reservation.d.ts +3 -7
  41. package/lib/chevre/repo/reservation.js +134 -75
  42. package/lib/chevre/repo/task.d.ts +31 -3
  43. package/lib/chevre/repo/task.js +141 -27
  44. package/lib/chevre/repo/transaction.d.ts +45 -5
  45. package/lib/chevre/repo/transaction.js +187 -29
  46. package/lib/chevre/repo/trip.js +33 -27
  47. package/lib/chevre/repository.d.ts +3 -0
  48. package/lib/chevre/repository.js +5 -1
  49. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +1 -1
  50. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +86 -59
  51. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +5 -8
  52. package/lib/chevre/service/aggregation/system.d.ts +93 -0
  53. package/lib/chevre/service/aggregation/system.js +377 -0
  54. package/lib/chevre/service/aggregation.d.ts +2 -0
  55. package/lib/chevre/service/aggregation.js +3 -1
  56. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
  57. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +2 -4
  58. package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
  59. package/lib/chevre/service/assetTransaction/pay.js +65 -32
  60. package/lib/chevre/service/assetTransaction/registerService.js +4 -1
  61. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
  62. package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
  63. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +16 -0
  64. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +84 -0
  65. package/lib/chevre/service/assetTransaction/reserve.d.ts +38 -6
  66. package/lib/chevre/service/assetTransaction/reserve.js +119 -94
  67. package/lib/chevre/service/delivery/factory.d.ts +1 -1
  68. package/lib/chevre/service/delivery/factory.js +1 -0
  69. package/lib/chevre/service/event.d.ts +2 -4
  70. package/lib/chevre/service/event.js +35 -14
  71. package/lib/chevre/service/offer/event/authorize.d.ts +4 -7
  72. package/lib/chevre/service/offer/event/authorize.js +26 -87
  73. package/lib/chevre/service/offer/event/cancel.js +0 -1
  74. package/lib/chevre/service/offer/event/factory.d.ts +3 -2
  75. package/lib/chevre/service/offer/event/factory.js +25 -5
  76. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +13 -7
  77. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +81 -45
  78. package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
  79. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  80. package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
  81. package/lib/chevre/service/offer/factory.js +10 -3
  82. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -0
  83. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  84. package/lib/chevre/service/offer/product.d.ts +1 -0
  85. package/lib/chevre/service/offer/product.js +6 -2
  86. package/lib/chevre/service/offer.d.ts +5 -1
  87. package/lib/chevre/service/offer.js +67 -46
  88. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +2 -1
  89. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
  90. package/lib/chevre/service/order/placeOrder.js +16 -0
  91. package/lib/chevre/service/order/returnOrder.js +1 -1
  92. package/lib/chevre/service/order/sendOrder.js +4 -2
  93. package/lib/chevre/service/payment/any.d.ts +5 -0
  94. package/lib/chevre/service/payment/any.js +1 -1
  95. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  96. package/lib/chevre/service/payment/movieTicket.js +8 -2
  97. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  98. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
  99. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
  100. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  101. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +32 -35
  102. package/lib/chevre/service/reserve/useReservation.d.ts +0 -3
  103. package/lib/chevre/service/reserve/useReservation.js +43 -25
  104. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  105. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  106. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  107. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  108. package/lib/chevre/service/task/returnPayTransaction.js +5 -1
  109. package/lib/chevre/service/task.js +6 -9
  110. package/lib/chevre/service/transaction/orderProgramMembership.js +2 -1
  111. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +42 -27
  112. package/lib/chevre/service/transaction/placeOrderInProgress.js +7 -7
  113. package/lib/chevre/service/transaction/returnOrder.js +3 -3
  114. package/lib/chevre/settings.d.ts +2 -0
  115. package/lib/chevre/settings.js +20 -12
  116. package/package.json +3 -3
  117. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  118. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
@@ -20,11 +20,26 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.MongoRepository = void 0;
23
+ exports.MongoRepository = exports.PROJECTION_MINIMIZED_EVENT = void 0;
24
24
  const uniqid = require("uniqid");
25
25
  const factory = require("../factory");
26
26
  const event_1 = require("./mongoose/model/event");
27
- const USE_DEPRECATED_EVENT_SEARCH_CONDITIONS = process.env.USE_DEPRECATED_EVENT_SEARCH_CONDITIONS === '1';
27
+ exports.PROJECTION_MINIMIZED_EVENT = {
28
+ project: 1,
29
+ _id: 1,
30
+ typeOf: 1,
31
+ additionalProperty: 1,
32
+ name: 1,
33
+ doorTime: 1,
34
+ endDate: 1,
35
+ eventStatus: 1,
36
+ location: 1,
37
+ startDate: 1,
38
+ superEvent: 1,
39
+ offers: 1,
40
+ coaInfo: 1,
41
+ identifier: 1
42
+ };
28
43
  /**
29
44
  * イベントリポジトリ
30
45
  */
@@ -34,7 +49,7 @@ class MongoRepository {
34
49
  }
35
50
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
36
51
  static CREATE_MONGO_CONDITIONS(conditions) {
37
- 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;
52
+ 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;
38
53
  const andConditions = [{ typeOf: { $eq: conditions.typeOf } }];
39
54
  const projectIdEq = (_b = (_a = conditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
40
55
  if (typeof projectIdEq === 'string') {
@@ -131,8 +146,96 @@ class MongoRepository {
131
146
  let params;
132
147
  switch (conditions.typeOf) {
133
148
  case factory.eventType.Event:
134
- // no op
135
- // params = conditions;
149
+ params = conditions;
150
+ // tslint:disable-next-line:no-single-line-block-comment
151
+ /* istanbul ignore else */
152
+ if (params.offers !== undefined) {
153
+ const itemOfferedIdIn4event = (_k = (_j = params.offers.itemOffered) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$in;
154
+ if (Array.isArray(itemOfferedIdIn4event)) {
155
+ andConditions.push({
156
+ 'offers.itemOffered.id': {
157
+ $exists: true,
158
+ $in: itemOfferedIdIn4event
159
+ }
160
+ });
161
+ }
162
+ // tslint:disable-next-line:no-single-line-block-comment
163
+ /* istanbul ignore else */
164
+ if (params.offers.itemOffered !== undefined) {
165
+ // tslint:disable-next-line:no-single-line-block-comment
166
+ /* istanbul ignore else */
167
+ if (params.offers.itemOffered.serviceOutput !== undefined) {
168
+ // tslint:disable-next-line:no-single-line-block-comment
169
+ /* istanbul ignore else */
170
+ if (params.offers.itemOffered.serviceOutput.reservedTicket !== undefined) {
171
+ // tslint:disable-next-line:no-single-line-block-comment
172
+ /* istanbul ignore else */
173
+ if (params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat !== undefined) {
174
+ // tslint:disable-next-line:no-single-line-block-comment
175
+ /* istanbul ignore else */
176
+ if (Array.isArray(params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs)) {
177
+ andConditions.push({
178
+ 'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
179
+ $exists: true,
180
+ $in: params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs
181
+ }
182
+ });
183
+ }
184
+ }
185
+ }
186
+ }
187
+ // tslint:disable-next-line:no-single-line-block-comment
188
+ /* istanbul ignore else */
189
+ if (params.offers.itemOffered.serviceType !== undefined) {
190
+ // tslint:disable-next-line:no-single-line-block-comment
191
+ /* istanbul ignore else */
192
+ if (Array.isArray(params.offers.itemOffered.serviceType.ids)) {
193
+ andConditions.push({
194
+ 'offers.itemOffered.serviceType.id': {
195
+ $exists: true,
196
+ $in: params.offers.itemOffered.serviceType.ids
197
+ }
198
+ });
199
+ }
200
+ }
201
+ }
202
+ }
203
+ const sellerMakesOfferElemMatch4event = (_o = (_m = (_l = params.offers) === null || _l === void 0 ? void 0 : _l.seller) === null || _m === void 0 ? void 0 : _m.makesOffer) === null || _o === void 0 ? void 0 : _o.$elemMatch;
204
+ if (typeof ((_p = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _p === void 0 ? void 0 : _p.$eq) === 'string') {
205
+ andConditions.push({
206
+ 'offers.seller.makesOffer': {
207
+ $exists: true,
208
+ $elemMatch: sellerMakesOfferElemMatch4event
209
+ }
210
+ });
211
+ }
212
+ const reservationForIdentifierEq = (_u = (_t = (_s = (_r = (_q = params.offers) === null || _q === void 0 ? void 0 : _q.itemOffered) === null || _r === void 0 ? void 0 : _r.serviceOutput) === null || _s === void 0 ? void 0 : _s.reservationFor) === null || _t === void 0 ? void 0 : _t.identifier) === null || _u === void 0 ? void 0 : _u.$eq;
213
+ if (typeof reservationForIdentifierEq === 'string') {
214
+ andConditions.push({
215
+ 'offers.itemOffered.serviceOutput.reservationFor.identifier': {
216
+ $exists: true,
217
+ $eq: reservationForIdentifierEq
218
+ }
219
+ });
220
+ }
221
+ const reservationForArrivalBusStopBranchCodeEq = (_0 = (_z = (_y = (_x = (_w = (_v = params.offers) === null || _v === void 0 ? void 0 : _v.itemOffered) === null || _w === void 0 ? void 0 : _w.serviceOutput) === null || _x === void 0 ? void 0 : _x.reservationFor) === null || _y === void 0 ? void 0 : _y.arrivalBusStop) === null || _z === void 0 ? void 0 : _z.branchCode) === null || _0 === void 0 ? void 0 : _0.$eq;
222
+ if (typeof reservationForArrivalBusStopBranchCodeEq === 'string') {
223
+ andConditions.push({
224
+ 'offers.itemOffered.serviceOutput.reservationFor.arrivalBusStop.branchCode': {
225
+ $exists: true,
226
+ $eq: reservationForArrivalBusStopBranchCodeEq
227
+ }
228
+ });
229
+ }
230
+ const reservationForDepartureBusStopBranchCodeEq = (_6 = (_5 = (_4 = (_3 = (_2 = (_1 = params.offers) === null || _1 === void 0 ? void 0 : _1.itemOffered) === null || _2 === void 0 ? void 0 : _2.serviceOutput) === null || _3 === void 0 ? void 0 : _3.reservationFor) === null || _4 === void 0 ? void 0 : _4.departureBusStop) === null || _5 === void 0 ? void 0 : _5.branchCode) === null || _6 === void 0 ? void 0 : _6.$eq;
231
+ if (typeof reservationForDepartureBusStopBranchCodeEq === 'string') {
232
+ andConditions.push({
233
+ 'offers.itemOffered.serviceOutput.reservationFor.departureBusStop.branchCode': {
234
+ $exists: true,
235
+ $eq: reservationForDepartureBusStopBranchCodeEq
236
+ }
237
+ });
238
+ }
136
239
  break;
137
240
  case factory.eventType.ScreeningEvent:
138
241
  params = conditions;
@@ -158,7 +261,7 @@ class MongoRepository {
158
261
  }
159
262
  // tslint:disable-next-line:no-single-line-block-comment
160
263
  /* istanbul ignore else */
161
- const superEventLocationIdEq = (_l = (_k = (_j = params.superEvent) === null || _j === void 0 ? void 0 : _j.location) === null || _k === void 0 ? void 0 : _k.id) === null || _l === void 0 ? void 0 : _l.$eq;
264
+ const superEventLocationIdEq = (_9 = (_8 = (_7 = params.superEvent) === null || _7 === void 0 ? void 0 : _7.location) === null || _8 === void 0 ? void 0 : _8.id) === null || _9 === void 0 ? void 0 : _9.$eq;
162
265
  if (typeof superEventLocationIdEq === 'string') {
163
266
  andConditions.push({
164
267
  'superEvent.location.id': {
@@ -201,103 +304,35 @@ class MongoRepository {
201
304
  });
202
305
  }
203
306
  }
204
- // tslint:disable-next-line:no-single-line-block-comment
205
- /* istanbul ignore else */
206
- if (params.offers !== undefined) {
207
- if (USE_DEPRECATED_EVENT_SEARCH_CONDITIONS) {
208
- // tslint:disable-next-line:no-single-line-block-comment
209
- /* istanbul ignore else */
210
- if (params.offers.availableFrom instanceof Date) {
211
- andConditions.push({
212
- 'offers.availabilityEnds': {
213
- $exists: true,
214
- $gte: params.offers.availableFrom
215
- }
216
- });
217
- }
218
- // tslint:disable-next-line:no-single-line-block-comment
219
- /* istanbul ignore else */
220
- if (params.offers.availableThrough instanceof Date) {
221
- andConditions.push({
222
- 'offers.availabilityStarts': {
223
- $exists: true,
224
- $lte: params.offers.availableThrough
225
- }
226
- });
227
- }
228
- // tslint:disable-next-line:no-single-line-block-comment
229
- /* istanbul ignore else */
230
- if (params.offers.validFrom instanceof Date) {
231
- andConditions.push({
232
- 'offers.validThrough': {
233
- $exists: true,
234
- $gte: params.offers.validFrom
235
- }
236
- });
237
- }
238
- // tslint:disable-next-line:no-single-line-block-comment
239
- /* istanbul ignore else */
240
- if (params.offers.validThrough instanceof Date) {
241
- andConditions.push({
242
- 'offers.validFrom': {
243
- $exists: true,
244
- $lte: params.offers.validThrough
245
- }
246
- });
307
+ const itemOfferedIdIn = (_12 = (_11 = (_10 = params.offers) === null || _10 === void 0 ? void 0 : _10.itemOffered) === null || _11 === void 0 ? void 0 : _11.id) === null || _12 === void 0 ? void 0 : _12.$in;
308
+ if (Array.isArray(itemOfferedIdIn)) {
309
+ andConditions.push({
310
+ 'offers.itemOffered.id': {
311
+ $exists: true,
312
+ $in: itemOfferedIdIn
247
313
  }
248
- }
249
- const itemOfferedIdIn = (_o = (_m = params.offers.itemOffered) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$in;
250
- if (Array.isArray(itemOfferedIdIn)) {
251
- andConditions.push({
252
- 'offers.itemOffered.id': {
253
- $exists: true,
254
- $in: itemOfferedIdIn
255
- }
256
- });
257
- }
258
- // tslint:disable-next-line:no-single-line-block-comment
259
- /* istanbul ignore else */
260
- if (params.offers.itemOffered !== undefined) {
261
- // tslint:disable-next-line:no-single-line-block-comment
262
- /* istanbul ignore else */
263
- if (params.offers.itemOffered.serviceOutput !== undefined) {
264
- // tslint:disable-next-line:no-single-line-block-comment
265
- /* istanbul ignore else */
266
- if (params.offers.itemOffered.serviceOutput.reservedTicket !== undefined) {
267
- // tslint:disable-next-line:no-single-line-block-comment
268
- /* istanbul ignore else */
269
- if (params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat !== undefined) {
270
- // tslint:disable-next-line:no-single-line-block-comment
271
- /* istanbul ignore else */
272
- if (Array.isArray(params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs)) {
273
- andConditions.push({
274
- 'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
275
- $exists: true,
276
- $in: params.offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOfs
277
- }
278
- });
279
- }
280
- }
281
- }
314
+ });
315
+ }
316
+ const itemOfferedTicketedSeatTypeOfIn = (_17 = (_16 = (_15 = (_14 = (_13 = params.offers) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.serviceOutput) === null || _15 === void 0 ? void 0 : _15.reservedTicket) === null || _16 === void 0 ? void 0 : _16.ticketedSeat) === null || _17 === void 0 ? void 0 : _17.typeOfs;
317
+ if (Array.isArray(itemOfferedTicketedSeatTypeOfIn)) {
318
+ andConditions.push({
319
+ 'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
320
+ $exists: true,
321
+ $in: itemOfferedTicketedSeatTypeOfIn
282
322
  }
283
- // tslint:disable-next-line:no-single-line-block-comment
284
- /* istanbul ignore else */
285
- if (params.offers.itemOffered.serviceType !== undefined) {
286
- // tslint:disable-next-line:no-single-line-block-comment
287
- /* istanbul ignore else */
288
- if (Array.isArray(params.offers.itemOffered.serviceType.ids)) {
289
- andConditions.push({
290
- 'offers.itemOffered.serviceType.id': {
291
- $exists: true,
292
- $in: params.offers.itemOffered.serviceType.ids
293
- }
294
- });
295
- }
323
+ });
324
+ }
325
+ const itemOfferedServiceTypeIdIn = (_20 = (_19 = (_18 = params.offers) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceType) === null || _20 === void 0 ? void 0 : _20.ids;
326
+ if (Array.isArray(itemOfferedServiceTypeIdIn)) {
327
+ andConditions.push({
328
+ 'offers.itemOffered.serviceType.id': {
329
+ $exists: true,
330
+ $in: itemOfferedServiceTypeIdIn
296
331
  }
297
- }
332
+ });
298
333
  }
299
- const sellerMakesOfferElemMatch = (_r = (_q = (_p = params.offers) === null || _p === void 0 ? void 0 : _p.seller) === null || _q === void 0 ? void 0 : _q.makesOffer) === null || _r === void 0 ? void 0 : _r.$elemMatch;
300
- if (typeof ((_s = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _s === void 0 ? void 0 : _s.$eq) === 'string') {
334
+ const sellerMakesOfferElemMatch = (_23 = (_22 = (_21 = params.offers) === null || _21 === void 0 ? void 0 : _21.seller) === null || _22 === void 0 ? void 0 : _22.makesOffer) === null || _23 === void 0 ? void 0 : _23.$elemMatch;
335
+ if (typeof ((_24 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _24 === void 0 ? void 0 : _24.$eq) === 'string') {
301
336
  andConditions.push({
302
337
  'offers.seller.makesOffer': {
303
338
  $exists: true,
@@ -334,7 +369,7 @@ class MongoRepository {
334
369
  ]
335
370
  });
336
371
  }
337
- const locationIdEq = (_u = (_t = params.location) === null || _t === void 0 ? void 0 : _t.id) === null || _u === void 0 ? void 0 : _u.$eq;
372
+ const locationIdEq = (_26 = (_25 = params.location) === null || _25 === void 0 ? void 0 : _25.id) === null || _26 === void 0 ? void 0 : _26.$eq;
338
373
  // tslint:disable-next-line:no-single-line-block-comment
339
374
  /* istanbul ignore else */
340
375
  if (typeof locationIdEq === 'string') {
@@ -356,7 +391,7 @@ class MongoRepository {
356
391
  });
357
392
  }
358
393
  }
359
- const workPerformedIdentifierIn = (_v = params.workPerformed) === null || _v === void 0 ? void 0 : _v.identifiers;
394
+ const workPerformedIdentifierIn = (_27 = params.workPerformed) === null || _27 === void 0 ? void 0 : _27.identifiers;
360
395
  // tslint:disable-next-line:no-single-line-block-comment
361
396
  /* istanbul ignore else */
362
397
  if (Array.isArray(workPerformedIdentifierIn)) {
@@ -367,7 +402,7 @@ class MongoRepository {
367
402
  }
368
403
  });
369
404
  }
370
- const videoFormatTypeOfEq = (_x = (_w = params.videoFormat) === null || _w === void 0 ? void 0 : _w.typeOf) === null || _x === void 0 ? void 0 : _x.$eq;
405
+ const videoFormatTypeOfEq = (_29 = (_28 = params.videoFormat) === null || _28 === void 0 ? void 0 : _28.typeOf) === null || _29 === void 0 ? void 0 : _29.$eq;
371
406
  if (typeof videoFormatTypeOfEq === 'string') {
372
407
  andConditions.push({
373
408
  'videoFormat.typeOf': {
@@ -376,7 +411,7 @@ class MongoRepository {
376
411
  }
377
412
  });
378
413
  }
379
- const videoFormatTypeOfIn = (_z = (_y = params.videoFormat) === null || _y === void 0 ? void 0 : _y.typeOf) === null || _z === void 0 ? void 0 : _z.$in;
414
+ const videoFormatTypeOfIn = (_31 = (_30 = params.videoFormat) === null || _30 === void 0 ? void 0 : _30.typeOf) === null || _31 === void 0 ? void 0 : _31.$in;
380
415
  if (Array.isArray(videoFormatTypeOfIn)) {
381
416
  andConditions.push({
382
417
  'videoFormat.typeOf': {
@@ -385,7 +420,7 @@ class MongoRepository {
385
420
  }
386
421
  });
387
422
  }
388
- const soundFormatTypeOfEq = (_1 = (_0 = params.soundFormat) === null || _0 === void 0 ? void 0 : _0.typeOf) === null || _1 === void 0 ? void 0 : _1.$eq;
423
+ const soundFormatTypeOfEq = (_33 = (_32 = params.soundFormat) === null || _32 === void 0 ? void 0 : _32.typeOf) === null || _33 === void 0 ? void 0 : _33.$eq;
389
424
  if (typeof soundFormatTypeOfEq === 'string') {
390
425
  andConditions.push({
391
426
  'soundFormat.typeOf': {
@@ -394,7 +429,7 @@ class MongoRepository {
394
429
  }
395
430
  });
396
431
  }
397
- const soundFormatTypeOfIn = (_3 = (_2 = params.soundFormat) === null || _2 === void 0 ? void 0 : _2.typeOf) === null || _3 === void 0 ? void 0 : _3.$in;
432
+ const soundFormatTypeOfIn = (_35 = (_34 = params.soundFormat) === null || _34 === void 0 ? void 0 : _34.typeOf) === null || _35 === void 0 ? void 0 : _35.$in;
398
433
  if (Array.isArray(soundFormatTypeOfIn)) {
399
434
  andConditions.push({
400
435
  'soundFormat.typeOf': {
@@ -413,12 +448,53 @@ class MongoRepository {
413
448
  */
414
449
  createMany(params) {
415
450
  return __awaiter(this, void 0, void 0, function* () {
416
- const docs = yield this.eventModel.insertMany(params.map((p) => {
451
+ const docs = yield this.eventModel.insertMany(params.attributes.map((p) => {
417
452
  return Object.assign({ _id: uniqid() }, p);
418
453
  }));
454
+ if (params.expectsNoContent) {
455
+ return;
456
+ }
419
457
  return docs.map((doc) => doc.toObject());
420
458
  });
421
459
  }
460
+ /**
461
+ * 特定の追加特性をキーにして、なければ作成する(複数対応)
462
+ */
463
+ createIfNotExistMany(params) {
464
+ return __awaiter(this, void 0, void 0, function* () {
465
+ const bulkWriteOps = [];
466
+ if (Array.isArray(params)) {
467
+ params.forEach((creatingEventParams) => {
468
+ var _a;
469
+ if (creatingEventParams.attributes.typeOf === factory.eventType.ScreeningEvent) {
470
+ const additionalPropertyValue = (_a = creatingEventParams.attributes.additionalProperty) === null || _a === void 0 ? void 0 : _a.find((property) => property.name === creatingEventParams.filter.name);
471
+ if (typeof additionalPropertyValue !== 'string') {
472
+ throw new factory.errors.NotFound('additionalProperty.value');
473
+ }
474
+ bulkWriteOps.push({
475
+ updateOne: {
476
+ filter: {
477
+ typeOf: creatingEventParams.attributes.typeOf,
478
+ // 追加特性をキーに更新
479
+ additionalProperty: {
480
+ $exists: true,
481
+ $all: [{ name: creatingEventParams.filter.name, value: additionalPropertyValue }]
482
+ }
483
+ },
484
+ update: {
485
+ $setOnInsert: Object.assign({ _id: uniqid() }, creatingEventParams.attributes)
486
+ },
487
+ upsert: true
488
+ }
489
+ });
490
+ }
491
+ });
492
+ }
493
+ if (bulkWriteOps.length > 0) {
494
+ yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
495
+ }
496
+ });
497
+ }
422
498
  /**
423
499
  * イベント部分更新
424
500
  */
@@ -472,52 +548,40 @@ class MongoRepository {
472
548
  const bulkWriteOps = [];
473
549
  if (Array.isArray(params)) {
474
550
  params.forEach((p) => {
475
- if (p.id === undefined) {
476
- const id = uniqid();
551
+ const upsert = p.upsert === true;
552
+ if (p.attributes.typeOf === factory.eventType.ScreeningEvent) {
553
+ // 上書き禁止属性を除外(2022-08-24~)
554
+ const _a = p.attributes, { identifier, project, typeOf, remainingAttendeeCapacity } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "remainingAttendeeCapacity"]);
477
555
  bulkWriteOps.push({
478
- insertOne: {
479
- document: Object.assign(Object.assign({}, p.attributes), { _id: id })
556
+ updateOne: {
557
+ filter: {
558
+ _id: p.id,
559
+ typeOf: p.attributes.typeOf
560
+ },
561
+ // upsertの場合、createがありうるので属性を除外しない
562
+ update: Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: p.attributes.typeOf, project: p.attributes.project }, (typeof p.attributes.identifier === 'string')
563
+ ? { identifier: p.attributes.identifier } : undefined), (typeof p.attributes.remainingAttendeeCapacity === 'number')
564
+ ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
565
+ : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
566
+ upsert
480
567
  }
481
568
  });
482
569
  }
483
- else {
484
- const upsert = p.upsert === true;
485
- if (p.attributes.typeOf === factory.eventType.ScreeningEvent) {
486
- // 上書き禁止属性を除外(2022-08-24~)
487
- const _a = p.attributes, { identifier, project, typeOf, remainingAttendeeCapacity } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "remainingAttendeeCapacity"]);
488
- bulkWriteOps.push({
489
- updateOne: {
490
- filter: {
491
- _id: p.id,
492
- typeOf: p.attributes.typeOf
493
- },
494
- // upsertの場合、createがありうるので属性を除外しない
495
- update: Object.assign({ $setOnInsert: Object.assign(Object.assign(Object.assign({ typeOf: p.attributes.typeOf }, (p.attributes.project !== undefined)
496
- ? { project: p.attributes.project } : undefined), (p.attributes.identifier !== undefined)
497
- ? { identifier: p.attributes.identifier } : undefined), (typeof p.attributes.remainingAttendeeCapacity === 'number')
498
- ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
499
- : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
500
- upsert
501
- }
502
- });
503
- }
504
- else if (p.attributes.typeOf === factory.eventType.ScreeningEventSeries) {
505
- // 上書き禁止属性を除外(2022-08-24~)
506
- const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
507
- bulkWriteOps.push({
508
- updateOne: {
509
- filter: {
510
- _id: p.id,
511
- typeOf: p.attributes.typeOf
512
- },
513
- // upsertの場合、createがありうるので属性を除外しない
514
- update: Object.assign({ $setOnInsert: Object.assign(Object.assign({ typeOf: p.attributes.typeOf }, (p.attributes.project !== undefined)
515
- ? { project: p.attributes.project } : undefined), (p.attributes.identifier !== undefined)
516
- ? { identifier: p.attributes.identifier } : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
517
- upsert
518
- }
519
- });
520
- }
570
+ else if (p.attributes.typeOf === factory.eventType.ScreeningEventSeries) {
571
+ // 上書き禁止属性を除外(2022-08-24~)
572
+ const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
573
+ bulkWriteOps.push({
574
+ updateOne: {
575
+ filter: {
576
+ _id: p.id,
577
+ typeOf: p.attributes.typeOf
578
+ },
579
+ // upsertの場合、createがありうるので属性を除外しない
580
+ update: Object.assign({ $setOnInsert: Object.assign({ typeOf: p.attributes.typeOf, project: p.attributes.project }, (typeof p.attributes.identifier === 'string')
581
+ ? { identifier: p.attributes.identifier } : undefined), $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
582
+ upsert
583
+ }
584
+ });
521
585
  }
522
586
  });
523
587
  }
@@ -530,7 +594,7 @@ class MongoRepository {
530
594
  return __awaiter(this, void 0, void 0, function* () {
531
595
  let doc;
532
596
  const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
533
- const id = (params.useOldEventId) ? params.oldEventId : uniqid();
597
+ const id = uniqid();
534
598
  doc = yield this.eventModel.findOneAndUpdate({
535
599
  typeOf: params.attributes.typeOf,
536
600
  // 追加特性をキーに更新
@@ -569,7 +633,15 @@ class MongoRepository {
569
633
  search(params, projection) {
570
634
  return __awaiter(this, void 0, void 0, function* () {
571
635
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
572
- const query = this.eventModel.find({ $and: conditions }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
636
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
637
+ ? Object.keys(projection)
638
+ .some((key) => projection[key] !== 0)
639
+ : false;
640
+ const query = this.eventModel.find({ $and: conditions },
641
+ // :1対応(2023-01-25~)
642
+ (positiveProjectionExists)
643
+ ? projection
644
+ : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
573
645
  if (typeof params.limit === 'number') {
574
646
  const page = (typeof params.page === 'number') ? params.page : 1;
575
647
  query.limit(params.limit)
@@ -593,11 +665,35 @@ class MongoRepository {
593
665
  .then((docs) => docs.map((doc) => doc.toObject()));
594
666
  });
595
667
  }
668
+ searchIds(params) {
669
+ return __awaiter(this, void 0, void 0, function* () {
670
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
671
+ const query = this.eventModel.distinct('_id', { $and: conditions });
672
+ return query.setOptions({ maxTimeMS: 10000 })
673
+ .exec();
674
+ });
675
+ }
596
676
  findById(params, projection) {
597
677
  return __awaiter(this, void 0, void 0, function* () {
598
- const doc = yield this.eventModel.findOne({
599
- _id: params.id
600
- }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
678
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
679
+ ? Object.keys(projection)
680
+ .some((key) => projection[key] !== 0)
681
+ : false;
682
+ const doc = yield this.eventModel.findOne({ _id: params.id },
683
+ // :1対応(2023-01-25~)
684
+ (positiveProjectionExists)
685
+ ? projection
686
+ : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
687
+ .exec();
688
+ if (doc === null) {
689
+ throw new factory.errors.NotFound(this.eventModel.modelName);
690
+ }
691
+ return doc.toObject();
692
+ });
693
+ }
694
+ findMinimizedIndividualEventById(params) {
695
+ return __awaiter(this, void 0, void 0, function* () {
696
+ const doc = yield this.eventModel.findOne({ _id: params.id }, exports.PROJECTION_MINIMIZED_EVENT)
601
697
  .exec();
602
698
  if (doc === null) {
603
699
  throw new factory.errors.NotFound(this.eventModel.modelName);
@@ -610,9 +706,7 @@ class MongoRepository {
610
706
  */
611
707
  cancel(params) {
612
708
  return __awaiter(this, void 0, void 0, function* () {
613
- yield this.eventModel.findOneAndUpdate({
614
- _id: params.id
615
- }, { eventStatus: factory.eventStatusType.EventCancelled }, { new: true })
709
+ yield this.eventModel.findOneAndUpdate({ _id: params.id }, { eventStatus: factory.eventStatusType.EventCancelled })
616
710
  .exec();
617
711
  });
618
712
  }
@@ -668,5 +762,213 @@ class MongoRepository {
668
762
  .exec();
669
763
  });
670
764
  }
765
+ aggregateEvent(params) {
766
+ return __awaiter(this, void 0, void 0, function* () {
767
+ const statuses = yield Promise.all([
768
+ factory.eventStatusType.EventScheduled,
769
+ factory.eventStatusType.EventCancelled,
770
+ factory.eventStatusType.EventPostponed
771
+ ].map((eventStatus) => __awaiter(this, void 0, void 0, function* () {
772
+ var _a, _b;
773
+ const matchConditions = Object.assign({ startDate: {
774
+ $gte: params.startFrom,
775
+ $lte: params.startThrough
776
+ }, typeOf: { $eq: params.typeOf }, eventStatus: { $eq: eventStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
777
+ ? { 'project.id': { $ne: params.project.id.$ne } }
778
+ : undefined);
779
+ return this.agggregateByStatus({ matchConditions, status: eventStatus });
780
+ })));
781
+ return { statuses };
782
+ });
783
+ }
784
+ // tslint:disable-next-line:max-func-body-length
785
+ agggregateByStatus(params) {
786
+ return __awaiter(this, void 0, void 0, function* () {
787
+ const matchConditions = params.matchConditions;
788
+ const eventStatus = params.status;
789
+ const aggregations = yield this.eventModel.aggregate([
790
+ {
791
+ $match: matchConditions
792
+ },
793
+ {
794
+ $project: {
795
+ remainingCapacityRate: {
796
+ $cond: {
797
+ if: {
798
+ $and: [
799
+ { $isNumber: '$maximumAttendeeCapacity' },
800
+ { $isNumber: '$remainingAttendeeCapacity' }
801
+ ]
802
+ },
803
+ then: {
804
+ $cond: {
805
+ if: { $gt: ['$maximumAttendeeCapacity', 0] },
806
+ then: {
807
+ $multiply: [
808
+ { $divide: ['$remainingAttendeeCapacity', '$maximumAttendeeCapacity'] },
809
+ // tslint:disable-next-line:no-magic-numbers
810
+ 100
811
+ ]
812
+ },
813
+ else: 0
814
+ }
815
+ },
816
+ else: 0
817
+ }
818
+ },
819
+ eventStatus: '$eventStatus',
820
+ startDate: '$startDate',
821
+ endDate: '$endDate',
822
+ typeOf: '$typeOf',
823
+ maximumAttendeeCapacity: {
824
+ $cond: {
825
+ if: { $isNumber: '$maximumAttendeeCapacity' },
826
+ then: '$maximumAttendeeCapacity',
827
+ else: 0
828
+ }
829
+ },
830
+ remainingAttendeeCapacity: {
831
+ $cond: {
832
+ if: { $isNumber: '$remainingAttendeeCapacity' },
833
+ then: '$remainingAttendeeCapacity',
834
+ else: 0
835
+ }
836
+ },
837
+ reservationCount: {
838
+ $cond: {
839
+ if: { $isNumber: '$aggregateReservation.reservationCount' },
840
+ then: '$aggregateReservation.reservationCount',
841
+ else: 0
842
+ }
843
+ },
844
+ offerCount: {
845
+ $cond: {
846
+ if: { $isNumber: '$aggregateOffer.offerCount' },
847
+ then: '$aggregateOffer.offerCount',
848
+ else: 0
849
+ }
850
+ }
851
+ }
852
+ },
853
+ {
854
+ $group: {
855
+ _id: '$typeOf',
856
+ eventCount: { $sum: 1 },
857
+ reservationCount: { $sum: '$reservationCount' },
858
+ avgOfferCount: { $avg: '$offerCount' },
859
+ maximumAttendeeCapacity: { $sum: '$maximumAttendeeCapacity' },
860
+ remainingAttendeeCapacity: { $sum: '$remainingAttendeeCapacity' },
861
+ avgRemainingCapacityRate: { $avg: '$remainingCapacityRate' },
862
+ maxRemainingCapacityRate: { $max: '$remainingCapacityRate' },
863
+ minRemainingCapacityRate: { $min: '$remainingCapacityRate' }
864
+ }
865
+ },
866
+ {
867
+ $project: {
868
+ _id: 0,
869
+ eventCount: '$eventCount',
870
+ reservationCount: '$reservationCount',
871
+ avgOfferCount: '$avgOfferCount',
872
+ maximumAttendeeCapacity: '$maximumAttendeeCapacity',
873
+ remainingAttendeeCapacity: '$remainingAttendeeCapacity',
874
+ avgRemainingCapacityRate: '$avgRemainingCapacityRate',
875
+ maxRemainingCapacityRate: '$maxRemainingCapacityRate',
876
+ minRemainingCapacityRate: '$minRemainingCapacityRate'
877
+ }
878
+ }
879
+ ])
880
+ .exec();
881
+ // tslint:disable-next-line:no-magic-numbers
882
+ const percents = [50, 95, 99];
883
+ if (aggregations.length === 0) {
884
+ return {
885
+ status: eventStatus,
886
+ aggregation: {
887
+ eventCount: 0,
888
+ reservationCount: 0,
889
+ avgOfferCount: 0,
890
+ maximumAttendeeCapacity: 0,
891
+ remainingAttendeeCapacity: 0,
892
+ avgRemainingCapacityRate: 0,
893
+ maxRemainingCapacityRate: 0,
894
+ minRemainingCapacityRate: 0,
895
+ percentilesRemainingCapacityRate: percents.map((percent) => {
896
+ return {
897
+ name: String(percent),
898
+ value: 0
899
+ };
900
+ })
901
+ }
902
+ };
903
+ }
904
+ const ranks4percentile = percents.map((percentile) => {
905
+ return {
906
+ percentile,
907
+ // tslint:disable-next-line:no-magic-numbers
908
+ rank: Math.floor(aggregations[0].eventCount * percentile / 100)
909
+ };
910
+ });
911
+ const aggregations2 = yield this.eventModel.aggregate([
912
+ {
913
+ $match: matchConditions
914
+ },
915
+ {
916
+ $project: {
917
+ remainingCapacityRate: {
918
+ $cond: {
919
+ if: {
920
+ $and: [
921
+ { $isNumber: '$maximumAttendeeCapacity' },
922
+ { $isNumber: '$remainingAttendeeCapacity' }
923
+ ]
924
+ },
925
+ then: {
926
+ $cond: {
927
+ if: { $gt: ['$maximumAttendeeCapacity', 0] },
928
+ then: {
929
+ $multiply: [
930
+ { $divide: ['$remainingAttendeeCapacity', '$maximumAttendeeCapacity'] },
931
+ // tslint:disable-next-line:no-magic-numbers
932
+ 100
933
+ ]
934
+ },
935
+ else: 0
936
+ }
937
+ },
938
+ else: 0
939
+ }
940
+ },
941
+ eventStatus: '$eventStatus',
942
+ startDate: '$startDate',
943
+ endDate: '$endDate',
944
+ typeOf: '$typeOf'
945
+ }
946
+ },
947
+ { $sort: { remainingCapacityRate: 1 } },
948
+ {
949
+ $group: {
950
+ _id: '$typeOf',
951
+ remainingCapacityRates: { $push: '$remainingCapacityRate' }
952
+ }
953
+ },
954
+ {
955
+ $project: {
956
+ _id: 0,
957
+ percentilesRemainingCapacityRate: ranks4percentile.map((rank) => {
958
+ return {
959
+ name: String(rank.percentile),
960
+ value: { $arrayElemAt: ['$remainingCapacityRates', rank.rank] }
961
+ };
962
+ })
963
+ }
964
+ }
965
+ ])
966
+ .exec();
967
+ return {
968
+ status: eventStatus,
969
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
970
+ };
971
+ });
972
+ }
671
973
  }
672
974
  exports.MongoRepository = MongoRepository;