@chevre/domain 20.2.0-alpha.3 → 20.2.0-alpha.30

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 (84) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +37 -0
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +104 -0
  3. package/example/src/chevre/importEventsFromCOA.ts +8 -1
  4. package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
  5. package/example/src/chevre/migrateProjectSubscription.ts +51 -0
  6. package/example/src/chevre/searchEventIds.ts +24 -0
  7. package/example/src/chevre/searchEvents.ts +20 -40
  8. package/lib/chevre/factory/event.d.ts +2 -0
  9. package/lib/chevre/factory/event.js +2 -0
  10. package/lib/chevre/repo/action.d.ts +58 -0
  11. package/lib/chevre/repo/action.js +187 -0
  12. package/lib/chevre/repo/aggregation.d.ts +36 -0
  13. package/lib/chevre/repo/aggregation.js +66 -0
  14. package/lib/chevre/repo/assetTransaction.d.ts +32 -0
  15. package/lib/chevre/repo/assetTransaction.js +148 -0
  16. package/lib/chevre/repo/event.d.ts +47 -13
  17. package/lib/chevre/repo/event.js +386 -113
  18. package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
  19. package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
  20. package/lib/chevre/repo/mongoose/model/event.js +4 -3
  21. package/lib/chevre/repo/mongoose/model/project.js +7 -1
  22. package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
  23. package/lib/chevre/repo/place.d.ts +15 -1
  24. package/lib/chevre/repo/place.js +175 -10
  25. package/lib/chevre/repo/product.d.ts +1 -0
  26. package/lib/chevre/repo/product.js +5 -0
  27. package/lib/chevre/repo/project.d.ts +4 -1
  28. package/lib/chevre/repo/project.js +9 -10
  29. package/lib/chevre/repo/reservation.d.ts +0 -6
  30. package/lib/chevre/repo/reservation.js +106 -66
  31. package/lib/chevre/repo/task.d.ts +31 -3
  32. package/lib/chevre/repo/task.js +141 -27
  33. package/lib/chevre/repo/transaction.d.ts +35 -0
  34. package/lib/chevre/repo/transaction.js +163 -0
  35. package/lib/chevre/repo/trip.js +33 -27
  36. package/lib/chevre/repository.d.ts +3 -0
  37. package/lib/chevre/repository.js +5 -1
  38. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +1 -1
  39. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +40 -15
  40. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +3 -1
  41. package/lib/chevre/service/aggregation/system.d.ts +86 -0
  42. package/lib/chevre/service/aggregation/system.js +345 -0
  43. package/lib/chevre/service/aggregation.d.ts +2 -0
  44. package/lib/chevre/service/aggregation.js +3 -1
  45. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
  46. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +2 -4
  47. package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
  48. package/lib/chevre/service/assetTransaction/pay.js +65 -32
  49. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
  50. package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
  51. package/lib/chevre/service/assetTransaction/reserve.d.ts +7 -2
  52. package/lib/chevre/service/assetTransaction/reserve.js +43 -56
  53. package/lib/chevre/service/delivery/factory.js +1 -0
  54. package/lib/chevre/service/event.d.ts +2 -4
  55. package/lib/chevre/service/event.js +34 -13
  56. package/lib/chevre/service/offer/event/authorize.js +5 -1
  57. package/lib/chevre/service/offer/event/cancel.js +0 -1
  58. package/lib/chevre/service/offer/event/factory.d.ts +3 -2
  59. package/lib/chevre/service/offer/event/factory.js +25 -5
  60. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +2 -2
  61. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +124 -9
  62. package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
  63. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  64. package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
  65. package/lib/chevre/service/offer.js +36 -20
  66. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +2 -1
  67. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
  68. package/lib/chevre/service/order/placeOrder.js +16 -0
  69. package/lib/chevre/service/payment/any.d.ts +5 -0
  70. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  71. package/lib/chevre/service/payment/movieTicket.js +8 -2
  72. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  73. package/lib/chevre/service/reserve/useReservation.js +2 -1
  74. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  75. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  76. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  77. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  78. package/lib/chevre/service/task.js +6 -9
  79. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +42 -27
  80. package/lib/chevre/settings.d.ts +2 -0
  81. package/lib/chevre/settings.js +7 -2
  82. package/package.json +3 -3
  83. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  84. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
@@ -21,7 +21,7 @@ class MongoRepository {
21
21
  }
22
22
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
23
23
  static CREATE_MONGO_CONDITIONS(params) {
24
- 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;
24
+ 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;
25
25
  // MongoDB検索条件
26
26
  const andConditions = [
27
27
  { typeOf: params.typeOf }
@@ -233,9 +233,54 @@ class MongoRepository {
233
233
  }
234
234
  switch (params.typeOf) {
235
235
  case factory.reservationType.BusReservation:
236
- // no op
236
+ const reservationForTypeOfEq = (_h = params.reservationFor) === null || _h === void 0 ? void 0 : _h.typeOf;
237
+ if (typeof reservationForTypeOfEq === 'string') {
238
+ andConditions.push({
239
+ 'reservationFor.typeOf': {
240
+ $exists: true,
241
+ $eq: reservationForTypeOfEq
242
+ }
243
+ });
244
+ }
245
+ const reservationForIdEq = (_k = (_j = params.reservationFor) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$eq;
246
+ if (typeof reservationForIdEq === 'string') {
247
+ andConditions.push({
248
+ 'reservationFor.id': {
249
+ $exists: true,
250
+ $eq: reservationForIdEq
251
+ }
252
+ });
253
+ }
254
+ const reservationForIdIn = (_m = (_l = params.reservationFor) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$in;
255
+ if (Array.isArray(reservationForIdIn)) {
256
+ andConditions.push({
257
+ 'reservationFor.id': {
258
+ $exists: true,
259
+ $in: reservationForIdIn
260
+ }
261
+ });
262
+ }
237
263
  break;
238
264
  case factory.reservationType.EventReservation:
265
+ if (typeof ((_o = params.reservationFor) === null || _o === void 0 ? void 0 : _o.id) === 'string') {
266
+ andConditions.push({
267
+ 'reservationFor.id': {
268
+ $exists: true,
269
+ $eq: params.reservationFor.id
270
+ }
271
+ });
272
+ }
273
+ else {
274
+ const reservationForIdEq4eventReservation = (_q = (_p = params.reservationFor) === null || _p === void 0 ? void 0 : _p.id) === null || _q === void 0 ? void 0 : _q.$eq;
275
+ if (typeof reservationForIdEq4eventReservation === 'string') {
276
+ andConditions.push({
277
+ 'reservationFor.id': {
278
+ $exists: true,
279
+ $eq: reservationForIdEq4eventReservation
280
+ }
281
+ });
282
+ }
283
+ }
239
284
  // tslint:disable-next-line:no-single-line-block-comment
240
285
  /* istanbul ignore else */
241
286
  if (params.reservationFor !== undefined) {
@@ -251,16 +296,6 @@ class MongoRepository {
251
296
  }
252
297
  // tslint:disable-next-line:no-single-line-block-comment
253
298
  /* istanbul ignore else */
254
- if (params.reservationFor.id !== undefined) {
255
- andConditions.push({
256
- 'reservationFor.id': {
257
- $exists: true,
258
- $eq: params.reservationFor.id
259
- }
260
- });
261
- }
262
- // tslint:disable-next-line:no-single-line-block-comment
263
- /* istanbul ignore else */
264
299
  if (Array.isArray(params.reservationFor.ids)) {
265
300
  andConditions.push({
266
301
  'reservationFor.id': {
@@ -490,7 +525,7 @@ class MongoRepository {
490
525
  }
491
526
  // tslint:disable-next-line:no-single-line-block-comment
492
527
  /* istanbul ignore else */
493
- const ticketedSeatSeatingTypeIn = (_j = (_h = params.reservedTicket.ticketedSeat) === null || _h === void 0 ? void 0 : _h.seatingType) === null || _j === void 0 ? void 0 : _j.$in;
528
+ const ticketedSeatSeatingTypeIn = (_s = (_r = params.reservedTicket.ticketedSeat) === null || _r === void 0 ? void 0 : _r.seatingType) === null || _s === void 0 ? void 0 : _s.$in;
494
529
  if (Array.isArray(ticketedSeatSeatingTypeIn)) {
495
530
  andConditions.push({
496
531
  'reservedTicket.ticketedSeat.seatingType': {
@@ -501,7 +536,7 @@ class MongoRepository {
501
536
  }
502
537
  }
503
538
  }
504
- const brokerIdRegex = (_k = params.broker) === null || _k === void 0 ? void 0 : _k.id;
539
+ const brokerIdRegex = (_t = params.broker) === null || _t === void 0 ? void 0 : _t.id;
505
540
  if (typeof brokerIdRegex === 'string' && brokerIdRegex.length > 0) {
506
541
  andConditions.push({
507
542
  'broker.id': {
@@ -510,7 +545,7 @@ class MongoRepository {
510
545
  }
511
546
  });
512
547
  }
513
- const brokerIdentifierAll = (_m = (_l = params.broker) === null || _l === void 0 ? void 0 : _l.identifier) === null || _m === void 0 ? void 0 : _m.$all;
548
+ const brokerIdentifierAll = (_v = (_u = params.broker) === null || _u === void 0 ? void 0 : _u.identifier) === null || _v === void 0 ? void 0 : _v.$all;
514
549
  if (Array.isArray(brokerIdentifierAll)) {
515
550
  andConditions.push({
516
551
  'broker.identifier': {
@@ -519,7 +554,7 @@ class MongoRepository {
519
554
  }
520
555
  });
521
556
  }
522
- const brokerIdentifierIn = (_p = (_o = params.broker) === null || _o === void 0 ? void 0 : _o.identifier) === null || _p === void 0 ? void 0 : _p.$in;
557
+ const brokerIdentifierIn = (_x = (_w = params.broker) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$in;
523
558
  if (Array.isArray(brokerIdentifierIn)) {
524
559
  andConditions.push({
525
560
  'broker.identifier': {
@@ -528,7 +563,7 @@ class MongoRepository {
528
563
  }
529
564
  });
530
565
  }
531
- const brokerIdentifierNin = (_r = (_q = params.broker) === null || _q === void 0 ? void 0 : _q.identifier) === null || _r === void 0 ? void 0 : _r.$nin;
566
+ const brokerIdentifierNin = (_z = (_y = params.broker) === null || _y === void 0 ? void 0 : _y.identifier) === null || _z === void 0 ? void 0 : _z.$nin;
532
567
  if (Array.isArray(brokerIdentifierNin)) {
533
568
  andConditions.push({
534
569
  'broker.identifier': {
@@ -536,7 +571,7 @@ class MongoRepository {
536
571
  }
537
572
  });
538
573
  }
539
- const brokerIdentifierElemMatch = (_t = (_s = params.broker) === null || _s === void 0 ? void 0 : _s.identifier) === null || _t === void 0 ? void 0 : _t.$elemMatch;
574
+ const brokerIdentifierElemMatch = (_1 = (_0 = params.broker) === null || _0 === void 0 ? void 0 : _0.identifier) === null || _1 === void 0 ? void 0 : _1.$elemMatch;
540
575
  if (brokerIdentifierElemMatch !== undefined && brokerIdentifierElemMatch !== null) {
541
576
  andConditions.push({
542
577
  'broker.identifier': {
@@ -571,9 +606,9 @@ class MongoRepository {
571
606
  }
572
607
  }
573
608
  else {
574
- const emailRegex = (_u = params.underName.email) === null || _u === void 0 ? void 0 : _u.$regex;
609
+ const emailRegex = (_2 = params.underName.email) === null || _2 === void 0 ? void 0 : _2.$regex;
575
610
  if (typeof emailRegex === 'string' && emailRegex.length > 0) {
576
- const emailOptions = (_v = params.underName.email) === null || _v === void 0 ? void 0 : _v.$options;
611
+ const emailOptions = (_3 = params.underName.email) === null || _3 === void 0 ? void 0 : _3.$options;
577
612
  andConditions.push({
578
613
  'underName.email': Object.assign({ $exists: true, $regex: new RegExp(emailRegex) }, (typeof emailOptions === 'string') ? { $options: emailOptions } : undefined)
579
614
  });
@@ -592,9 +627,9 @@ class MongoRepository {
592
627
  }
593
628
  }
594
629
  else {
595
- const underNameNameRegex = (_w = params.underName.name) === null || _w === void 0 ? void 0 : _w.$regex;
630
+ const underNameNameRegex = (_4 = params.underName.name) === null || _4 === void 0 ? void 0 : _4.$regex;
596
631
  if (typeof underNameNameRegex === 'string' && underNameNameRegex.length > 0) {
597
- const underNameNameOptions = (_x = params.underName.name) === null || _x === void 0 ? void 0 : _x.$options;
632
+ const underNameNameOptions = (_5 = params.underName.name) === null || _5 === void 0 ? void 0 : _5.$options;
598
633
  andConditions.push({
599
634
  'underName.name': Object.assign({ $exists: true, $regex: new RegExp(underNameNameRegex) }, (typeof underNameNameOptions === 'string') ? { $options: underNameNameOptions } : undefined)
600
635
  });
@@ -623,9 +658,9 @@ class MongoRepository {
623
658
  }
624
659
  }
625
660
  else {
626
- const givenNameRegex = (_y = params.underName.givenName) === null || _y === void 0 ? void 0 : _y.$regex;
661
+ const givenNameRegex = (_6 = params.underName.givenName) === null || _6 === void 0 ? void 0 : _6.$regex;
627
662
  if (typeof givenNameRegex === 'string' && givenNameRegex.length > 0) {
628
- const givenNameOptions = (_z = params.underName.givenName) === null || _z === void 0 ? void 0 : _z.$options;
663
+ const givenNameOptions = (_7 = params.underName.givenName) === null || _7 === void 0 ? void 0 : _7.$options;
629
664
  andConditions.push({
630
665
  'underName.givenName': Object.assign({ $exists: true, $regex: new RegExp(givenNameRegex) }, (typeof givenNameOptions === 'string') ? { $options: givenNameOptions } : undefined)
631
666
  });
@@ -644,9 +679,9 @@ class MongoRepository {
644
679
  }
645
680
  }
646
681
  else {
647
- const familyNameRegex = (_0 = params.underName.familyName) === null || _0 === void 0 ? void 0 : _0.$regex;
682
+ const familyNameRegex = (_8 = params.underName.familyName) === null || _8 === void 0 ? void 0 : _8.$regex;
648
683
  if (typeof familyNameRegex === 'string' && familyNameRegex.length > 0) {
649
- const familyNameOptions = (_1 = params.underName.familyName) === null || _1 === void 0 ? void 0 : _1.$options;
684
+ const familyNameOptions = (_9 = params.underName.familyName) === null || _9 === void 0 ? void 0 : _9.$options;
650
685
  andConditions.push({
651
686
  'underName.familyName': Object.assign({ $exists: true, $regex: new RegExp(familyNameRegex) }, (typeof familyNameOptions === 'string') ? { $options: familyNameOptions } : undefined)
652
687
  });
@@ -747,7 +782,7 @@ class MongoRepository {
747
782
  });
748
783
  }
749
784
  }
750
- const programMembershipUsedIdentifierEq = (_3 = (_2 = params.programMembershipUsed) === null || _2 === void 0 ? void 0 : _2.identifier) === null || _3 === void 0 ? void 0 : _3.$eq;
785
+ const programMembershipUsedIdentifierEq = (_11 = (_10 = params.programMembershipUsed) === null || _10 === void 0 ? void 0 : _10.identifier) === null || _11 === void 0 ? void 0 : _11.$eq;
751
786
  if (typeof programMembershipUsedIdentifierEq === 'string') {
752
787
  andConditions.push({
753
788
  'programMembershipUsed.identifier': {
@@ -756,7 +791,7 @@ class MongoRepository {
756
791
  }
757
792
  });
758
793
  }
759
- const programMembershipUsedIssuedThroughServiceTypeCodeValueEq = (_7 = (_6 = (_5 = (_4 = params.programMembershipUsed) === null || _4 === void 0 ? void 0 : _4.issuedThrough) === null || _5 === void 0 ? void 0 : _5.serviceType) === null || _6 === void 0 ? void 0 : _6.codeValue) === null || _7 === void 0 ? void 0 : _7.$eq;
794
+ const programMembershipUsedIssuedThroughServiceTypeCodeValueEq = (_15 = (_14 = (_13 = (_12 = params.programMembershipUsed) === null || _12 === void 0 ? void 0 : _12.issuedThrough) === null || _13 === void 0 ? void 0 : _13.serviceType) === null || _14 === void 0 ? void 0 : _14.codeValue) === null || _15 === void 0 ? void 0 : _15.$eq;
760
795
  if (typeof programMembershipUsedIssuedThroughServiceTypeCodeValueEq === 'string') {
761
796
  andConditions.push({
762
797
  'programMembershipUsed.issuedThrough.serviceType.codeValue': {
@@ -765,7 +800,7 @@ class MongoRepository {
765
800
  }
766
801
  });
767
802
  }
768
- const appliesToMovieTicketIdentifierEq = (_11 = (_10 = (_9 = (_8 = params.price) === null || _8 === void 0 ? void 0 : _8.priceComponent) === null || _9 === void 0 ? void 0 : _9.appliesToMovieTicket) === null || _10 === void 0 ? void 0 : _10.identifier) === null || _11 === void 0 ? void 0 : _11.$eq;
803
+ const appliesToMovieTicketIdentifierEq = (_19 = (_18 = (_17 = (_16 = params.price) === null || _16 === void 0 ? void 0 : _16.priceComponent) === null || _17 === void 0 ? void 0 : _17.appliesToMovieTicket) === null || _18 === void 0 ? void 0 : _18.identifier) === null || _19 === void 0 ? void 0 : _19.$eq;
769
804
  if (typeof appliesToMovieTicketIdentifierEq === 'string') {
770
805
  andConditions.push({
771
806
  'price.priceComponent.appliesToMovieTicket.identifier': {
@@ -880,49 +915,54 @@ class MongoRepository {
880
915
  /**
881
916
  * 予約確定
882
917
  */
883
- confirm(params) {
884
- return __awaiter(this, void 0, void 0, function* () {
885
- const conditions = {
886
- _id: { $eq: String(params.id) },
887
- reservationStatus: { $eq: params.previousReservationStatus }
888
- };
889
- // 更新属性をwhitelist化(2022-06-13~)
890
- const update = Object.assign(Object.assign({
891
- // ...params,
892
- reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined), (params.reservedTicket !== undefined) ? { reservedTicket: params.reservedTicket } : undefined);
893
- // 以下値は更新しない(他処理で更新される可能性あり)
894
- // if (typeof update.checkedIn === 'boolean') {
895
- // delete update.checkedIn;
896
- // }
897
- // if (typeof update.attended === 'boolean') {
898
- // delete update.attended;
899
- // }
900
- const doc = yield this.reservationModel.findOneAndUpdate(conditions, update, { new: true })
901
- .select({ __v: 0, createdAt: 0, updatedAt: 0 })
902
- .exec();
903
- // NotFoundであれば状態確認
904
- if (doc === null) {
905
- const reservation = yield this.findById({ id: String(params.id) });
906
- if (reservation.reservationStatus === factory.reservationStatusType.ReservationConfirmed) {
907
- // すでに確定済の場合
908
- return reservation;
909
- }
910
- else {
911
- throw new factory.errors.Argument('id', `Reservation ${reservation.id} already changed -> ${reservation.reservationStatus}`);
912
- }
913
- }
914
- return doc.toObject();
915
- });
916
- }
918
+ // public async confirm<T extends factory.reservationType>(params: {
919
+ // id: string;
920
+ // previousReservationStatus: factory.reservationStatusType;
921
+ // underName?: factory.reservation.IUnderName<T>;
922
+ // }): Promise<factory.reservation.IReservation<T>> {
923
+ // const conditions = {
924
+ // _id: { $eq: String(params.id) },
925
+ // reservationStatus: { $eq: params.previousReservationStatus }
926
+ // };
927
+ // // 更新属性をwhitelist化(2022-06-13~)
928
+ // const update = {
929
+ // // previousReservationStatusを保管(2023-01-19~)
930
+ // previousReservationStatus: params.previousReservationStatus,
931
+ // reservationStatus: factory.reservationStatusType.ReservationConfirmed,
932
+ // modifiedTime: new Date(),
933
+ // ...(params.underName !== undefined) ? { underName: params.underName } : undefined
934
+ // };
935
+ // const doc = await this.reservationModel.findOneAndUpdate(
936
+ // conditions,
937
+ // update,
938
+ // { new: true }
939
+ // )
940
+ // .select({ __v: 0, createdAt: 0, updatedAt: 0 })
941
+ // .exec();
942
+ // // NotFoundであれば状態確認
943
+ // if (doc === null) {
944
+ // const reservation = await this.findById<T>({ id: String(params.id) });
945
+ // if (reservation.reservationStatus === factory.reservationStatusType.ReservationConfirmed) {
946
+ // // すでに確定済の場合
947
+ // return reservation;
948
+ // } else {
949
+ // throw new factory.errors.Argument(
950
+ // 'id',
951
+ // `Reservation ${reservation.id} already changed -> ${reservation.reservationStatus}`
952
+ // );
953
+ // }
954
+ // }
955
+ // return doc.toObject();
956
+ // }
917
957
  confirmByReservationNumber(params) {
918
958
  return __awaiter(this, void 0, void 0, function* () {
919
959
  const conditions = {
920
960
  reservationNumber: { $eq: String(params.reservationNumber) },
921
961
  reservationStatus: { $eq: params.previousReservationStatus }
922
962
  };
923
- const update = Object.assign({ reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined
924
- // ...(params.reservedTicket !== undefined) ? { reservedTicket: params.reservedTicket } : undefined
925
- );
963
+ const update = Object.assign({
964
+ // previousReservationStatusを保管(2023-01-19~)
965
+ previousReservationStatus: params.previousReservationStatus, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined);
926
966
  yield this.reservationModel.updateMany(conditions, update)
927
967
  .exec();
928
968
  });
@@ -1,12 +1,29 @@
1
1
  import { Connection, Model } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ interface IAggregationByStatus {
4
+ taskCount: number;
5
+ avgLatency: number;
6
+ maxLatency: number;
7
+ minLatency: number;
8
+ percentilesLatency: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.taskStatus;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ export interface IAggregateTask {
18
+ statuses: IStatus[];
19
+ }
3
20
  /**
4
21
  * タスクリポジトリ
5
22
  */
6
23
  export declare class MongoRepository {
7
24
  readonly taskModel: typeof Model;
8
25
  constructor(connection: Connection);
9
- static CREATE_MONGO_CONDITIONS<T extends factory.taskName>(params: factory.task.ISearchConditions<T>): any[];
26
+ static CREATE_MONGO_CONDITIONS(params: factory.task.ISearchConditions): any[];
10
27
  save(taskAttributes: factory.task.IAttributes<factory.taskName>): Promise<factory.task.ITask<factory.taskName>>;
11
28
  saveMany(taskAttributes: factory.task.IAttributes<factory.taskName>[]): Promise<any[]>;
12
29
  executeOneByName<T extends factory.taskName>(params: {
@@ -29,14 +46,25 @@ export declare class MongoRepository {
29
46
  name: T;
30
47
  id: string;
31
48
  }): Promise<factory.task.ITask<T>>;
32
- count<T extends factory.taskName>(params: factory.task.ISearchConditions<T>): Promise<number>;
49
+ count(params: factory.task.ISearchConditions): Promise<number>;
33
50
  /**
34
51
  * 検索する
35
52
  */
36
- search<T extends factory.taskName>(params: factory.task.ISearchConditions<T>, projection?: any): Promise<factory.task.ITask<T>[]>;
53
+ search(params: factory.task.ISearchConditions, projection?: any): Promise<factory.task.ITask<factory.taskName>[]>;
37
54
  deleteByProject(params: {
38
55
  project: {
39
56
  id: string;
40
57
  };
41
58
  }): Promise<void>;
59
+ aggregateTask(params: {
60
+ project?: {
61
+ id?: {
62
+ $ne?: string;
63
+ };
64
+ };
65
+ runsFrom: Date;
66
+ runsThrough: Date;
67
+ }): Promise<IAggregateTask>;
68
+ private agggregateByStatus;
42
69
  }
70
+ export {};
@@ -29,29 +29,24 @@ class MongoRepository {
29
29
  }
30
30
  // tslint:disable-next-line:max-func-body-length
31
31
  static CREATE_MONGO_CONDITIONS(params) {
32
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
33
- const andConditions = [{
34
- name: { $exists: true }
35
- }];
36
- // tslint:disable-next-line:no-single-line-block-comment
37
- /* istanbul ignore else */
38
- if (params.project !== undefined) {
39
- if (params.project.id !== undefined && params.project.id !== null) {
40
- if (typeof params.project.id.$eq === 'string') {
41
- andConditions.push({
42
- 'project.id': {
43
- $eq: params.project.id.$eq
44
- }
45
- });
46
- }
47
- }
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
33
+ const andConditions = [];
34
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
35
+ if (typeof projectIdEq === 'string') {
36
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
48
37
  }
49
- // tslint:disable-next-line:no-single-line-block-comment
50
- /* istanbul ignore else */
51
- if (params.name !== undefined) {
52
- andConditions.push({
53
- name: params.name
54
- });
38
+ if (typeof params.name === 'string') {
39
+ andConditions.push({ name: { $eq: params.name } });
40
+ }
41
+ else {
42
+ const nameIn = (_c = params.name) === null || _c === void 0 ? void 0 : _c.$in;
43
+ if (Array.isArray(nameIn)) {
44
+ andConditions.push({ name: { $in: nameIn } });
45
+ }
46
+ const nameNin = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$nin;
47
+ if (Array.isArray(nameNin)) {
48
+ andConditions.push({ name: { $nin: nameNin } });
49
+ }
55
50
  }
56
51
  // tslint:disable-next-line:no-single-line-block-comment
57
52
  /* istanbul ignore else */
@@ -94,7 +89,7 @@ class MongoRepository {
94
89
  }
95
90
  });
96
91
  }
97
- const dateAbortedGte = (_a = params.dateAborted) === null || _a === void 0 ? void 0 : _a.$gte;
92
+ const dateAbortedGte = (_e = params.dateAborted) === null || _e === void 0 ? void 0 : _e.$gte;
98
93
  if (dateAbortedGte instanceof Date) {
99
94
  andConditions.push({
100
95
  dateAborted: {
@@ -103,7 +98,7 @@ class MongoRepository {
103
98
  }
104
99
  });
105
100
  }
106
- const dateAbortedLte = (_b = params.dateAborted) === null || _b === void 0 ? void 0 : _b.$lte;
101
+ const dateAbortedLte = (_f = params.dateAborted) === null || _f === void 0 ? void 0 : _f.$lte;
107
102
  if (dateAbortedLte instanceof Date) {
108
103
  andConditions.push({
109
104
  dateAborted: {
@@ -112,7 +107,7 @@ class MongoRepository {
112
107
  }
113
108
  });
114
109
  }
115
- const objectTransactionNumberEq = (_e = (_d = (_c = params.data) === null || _c === void 0 ? void 0 : _c.object) === null || _d === void 0 ? void 0 : _d.transactionNumber) === null || _e === void 0 ? void 0 : _e.$eq;
110
+ const objectTransactionNumberEq = (_j = (_h = (_g = params.data) === null || _g === void 0 ? void 0 : _g.object) === null || _h === void 0 ? void 0 : _h.transactionNumber) === null || _j === void 0 ? void 0 : _j.$eq;
116
111
  if (typeof objectTransactionNumberEq === 'string') {
117
112
  andConditions.push({
118
113
  'data.object.transactionNumber': {
@@ -121,7 +116,7 @@ class MongoRepository {
121
116
  }
122
117
  });
123
118
  }
124
- const objectPurposeIdEq = (_h = (_g = (_f = params.data) === null || _f === void 0 ? void 0 : _f.purpose) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$eq;
119
+ const objectPurposeIdEq = (_m = (_l = (_k = params.data) === null || _k === void 0 ? void 0 : _k.purpose) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$eq;
125
120
  if (typeof objectPurposeIdEq === 'string') {
126
121
  andConditions.push({
127
122
  'data.purpose.id': {
@@ -130,7 +125,7 @@ class MongoRepository {
130
125
  }
131
126
  });
132
127
  }
133
- const objectPurposeOrderNumberEq = (_l = (_k = (_j = params.data) === null || _j === void 0 ? void 0 : _j.purpose) === null || _k === void 0 ? void 0 : _k.orderNumber) === null || _l === void 0 ? void 0 : _l.$eq;
128
+ const objectPurposeOrderNumberEq = (_q = (_p = (_o = params.data) === null || _o === void 0 ? void 0 : _o.purpose) === null || _p === void 0 ? void 0 : _p.orderNumber) === null || _q === void 0 ? void 0 : _q.$eq;
134
129
  if (typeof objectPurposeOrderNumberEq === 'string') {
135
130
  andConditions.push({
136
131
  'data.purpose.orderNumber': {
@@ -312,5 +307,124 @@ class MongoRepository {
312
307
  .exec();
313
308
  });
314
309
  }
310
+ aggregateTask(params) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ const statuses = yield Promise.all([
313
+ factory.taskStatus.Executed,
314
+ factory.taskStatus.Aborted
315
+ ].map((taskStatus) => __awaiter(this, void 0, void 0, function* () {
316
+ var _a, _b;
317
+ const matchConditions = Object.assign({ runsAt: {
318
+ $gte: params.runsFrom,
319
+ $lte: params.runsThrough
320
+ }, status: { $eq: taskStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
321
+ ? { 'project.id': { $ne: params.project.id.$ne } }
322
+ : undefined);
323
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
324
+ })));
325
+ return { statuses };
326
+ });
327
+ }
328
+ // tslint:disable-next-line:max-func-body-length
329
+ agggregateByStatus(params) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ const matchConditions = params.matchConditions;
332
+ const taskStatus = params.status;
333
+ const aggregations = yield this.taskModel.aggregate([
334
+ {
335
+ $match: matchConditions
336
+ },
337
+ {
338
+ $project: {
339
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
340
+ status: '$status',
341
+ runsAt: '$runsAt',
342
+ lastTriedAt: '$lastTriedAt'
343
+ }
344
+ },
345
+ {
346
+ $group: {
347
+ _id: '$status',
348
+ taskCount: { $sum: 1 },
349
+ maxLatency: { $max: '$latency' },
350
+ minLatency: { $min: '$latency' },
351
+ avgLatency: { $avg: '$latency' }
352
+ }
353
+ },
354
+ {
355
+ $project: {
356
+ _id: 0,
357
+ taskCount: '$taskCount',
358
+ avgLatency: '$avgLatency',
359
+ maxLatency: '$maxLatency',
360
+ minLatency: '$minLatency'
361
+ }
362
+ }
363
+ ])
364
+ .exec();
365
+ // tslint:disable-next-line:no-magic-numbers
366
+ const percents = [50, 95, 99];
367
+ if (aggregations.length === 0) {
368
+ return {
369
+ status: taskStatus,
370
+ aggregation: {
371
+ taskCount: 0,
372
+ avgLatency: 0,
373
+ maxLatency: 0,
374
+ minLatency: 0,
375
+ percentilesLatency: percents.map((percent) => {
376
+ return {
377
+ name: String(percent),
378
+ value: 0
379
+ };
380
+ })
381
+ }
382
+ };
383
+ }
384
+ const ranks4percentile = percents.map((percentile) => {
385
+ return {
386
+ percentile,
387
+ // tslint:disable-next-line:no-magic-numbers
388
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
389
+ };
390
+ });
391
+ const aggregations2 = yield this.taskModel.aggregate([
392
+ {
393
+ $match: matchConditions
394
+ },
395
+ {
396
+ $project: {
397
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
398
+ status: '$status',
399
+ runsAt: '$runsAt',
400
+ lastTriedAt: '$lastTriedAt'
401
+ }
402
+ },
403
+ { $sort: { latency: 1 } },
404
+ {
405
+ $group: {
406
+ _id: '$status',
407
+ latencies: { $push: '$latency' }
408
+ }
409
+ },
410
+ {
411
+ $project: {
412
+ _id: 0,
413
+ percentilesLatency: ranks4percentile.map((rank) => {
414
+ return {
415
+ name: String(rank.percentile),
416
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
417
+ };
418
+ })
419
+ }
420
+ }
421
+ ])
422
+ .exec();
423
+ return {
424
+ status: taskStatus,
425
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
426
+ };
427
+ });
428
+ }
315
429
  }
316
430
  exports.MongoRepository = MongoRepository;
@@ -2,6 +2,29 @@ import { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  import { modelName } from './mongoose/model/transaction';
4
4
  export { modelName };
5
+ interface IAggregationByStatus {
6
+ transactionCount: number;
7
+ avgDuration: number;
8
+ maxDuration: number;
9
+ minDuration: number;
10
+ percentilesDuration: {
11
+ name: string;
12
+ value: number;
13
+ }[];
14
+ acceptedOfferCount: number;
15
+ avgAcceptedOfferCount: number;
16
+ totalPrice: number;
17
+ maxPrice: number;
18
+ minPrice: number;
19
+ avgPrice: number;
20
+ }
21
+ interface IStatus {
22
+ status: factory.transactionStatusType;
23
+ aggregation: IAggregationByStatus;
24
+ }
25
+ export interface IAggregatePlaceOrder {
26
+ statuses: IStatus[];
27
+ }
5
28
  /**
6
29
  * 取引リポジトリ
7
30
  */
@@ -129,4 +152,16 @@ export declare class MongoRepository {
129
152
  findByIdAndDelete(params: {
130
153
  id: string;
131
154
  }): Promise<void>;
155
+ aggregatePlaceOrder(params: {
156
+ project?: {
157
+ id?: {
158
+ $ne?: string;
159
+ };
160
+ };
161
+ startFrom: Date;
162
+ startThrough: Date;
163
+ typeOf: factory.transactionType;
164
+ clientId?: string;
165
+ }): Promise<IAggregatePlaceOrder>;
166
+ private agggregateByStatus;
132
167
  }