@chevre/domain 20.2.0-alpha.8 → 20.2.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 (140) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +37 -0
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +116 -0
  3. package/example/src/chevre/attendIfNotAttended.ts +22 -0
  4. package/example/src/chevre/createManyEventsIfNotExist.ts +209 -0
  5. package/example/src/chevre/findByOrderNumberAndReservationId.ts +20 -0
  6. package/example/src/chevre/findScreeningRoomsByBranchCode.ts +27 -0
  7. package/example/src/chevre/importEventsFromCOA.ts +8 -1
  8. package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
  9. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +1 -1
  10. package/example/src/chevre/migrateProjectSubscription.ts +51 -0
  11. package/example/src/chevre/ownershipInfosCsv2peopleJson.ts +2 -2
  12. package/example/src/chevre/processReserve.ts +2 -0
  13. package/example/src/chevre/searchEventIds.ts +24 -0
  14. package/example/src/chevre/searchEventTicketOffers.ts +5 -4
  15. package/example/src/chevre/searchEvents.ts +20 -41
  16. package/example/src/chevre/searchOffersByCatalog.ts +27 -0
  17. package/example/src/chevre/updateTransaction.ts +38 -0
  18. package/lib/chevre/factory/event.d.ts +2 -0
  19. package/lib/chevre/factory/event.js +2 -0
  20. package/lib/chevre/repo/action.d.ts +77 -1
  21. package/lib/chevre/repo/action.js +249 -6
  22. package/lib/chevre/repo/aggregation.d.ts +38 -0
  23. package/lib/chevre/repo/aggregation.js +68 -0
  24. package/lib/chevre/repo/assetTransaction.d.ts +32 -0
  25. package/lib/chevre/repo/assetTransaction.js +148 -0
  26. package/lib/chevre/repo/code.d.ts +13 -16
  27. package/lib/chevre/repo/code.js +33 -19
  28. package/lib/chevre/repo/creativeWork.js +13 -12
  29. package/lib/chevre/repo/event.d.ts +64 -17
  30. package/lib/chevre/repo/event.js +456 -156
  31. package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
  32. package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
  33. package/lib/chevre/repo/mongoose/model/event.js +4 -3
  34. package/lib/chevre/repo/mongoose/model/offer.js +2 -1
  35. package/lib/chevre/repo/mongoose/model/project.js +7 -1
  36. package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
  37. package/lib/chevre/repo/offer.d.ts +10 -0
  38. package/lib/chevre/repo/offer.js +47 -16
  39. package/lib/chevre/repo/order.d.ts +6 -0
  40. package/lib/chevre/repo/order.js +53 -7
  41. package/lib/chevre/repo/place.d.ts +26 -1
  42. package/lib/chevre/repo/place.js +216 -12
  43. package/lib/chevre/repo/product.d.ts +1 -0
  44. package/lib/chevre/repo/product.js +5 -0
  45. package/lib/chevre/repo/project.d.ts +7 -1
  46. package/lib/chevre/repo/project.js +15 -6
  47. package/lib/chevre/repo/reservation.d.ts +7 -8
  48. package/lib/chevre/repo/reservation.js +181 -76
  49. package/lib/chevre/repo/task.d.ts +31 -4
  50. package/lib/chevre/repo/task.js +146 -33
  51. package/lib/chevre/repo/transaction.d.ts +57 -5
  52. package/lib/chevre/repo/transaction.js +228 -34
  53. package/lib/chevre/repo/trip.js +33 -27
  54. package/lib/chevre/repository.d.ts +3 -0
  55. package/lib/chevre/repository.js +5 -1
  56. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +86 -68
  57. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +5 -8
  58. package/lib/chevre/service/aggregation/system.d.ts +100 -0
  59. package/lib/chevre/service/aggregation/system.js +409 -0
  60. package/lib/chevre/service/aggregation.d.ts +2 -0
  61. package/lib/chevre/service/aggregation.js +3 -1
  62. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
  63. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +2 -4
  64. package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
  65. package/lib/chevre/service/assetTransaction/pay.js +65 -32
  66. package/lib/chevre/service/assetTransaction/registerService.js +4 -1
  67. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
  68. package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
  69. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +16 -0
  70. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +84 -0
  71. package/lib/chevre/service/assetTransaction/reserve.d.ts +38 -6
  72. package/lib/chevre/service/assetTransaction/reserve.js +120 -94
  73. package/lib/chevre/service/assetTransaction.d.ts +1 -1
  74. package/lib/chevre/service/code.d.ts +2 -3
  75. package/lib/chevre/service/delivery/factory.d.ts +1 -1
  76. package/lib/chevre/service/delivery/product/factory.js +9 -3
  77. package/lib/chevre/service/event.d.ts +2 -4
  78. package/lib/chevre/service/event.js +35 -14
  79. package/lib/chevre/service/offer/event/authorize.d.ts +4 -7
  80. package/lib/chevre/service/offer/event/authorize.js +33 -87
  81. package/lib/chevre/service/offer/event/cancel.js +0 -1
  82. package/lib/chevre/service/offer/event/factory.d.ts +3 -2
  83. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +14 -7
  84. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +95 -53
  85. package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
  86. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  87. package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
  88. package/lib/chevre/service/offer/factory.js +10 -3
  89. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -0
  90. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  91. package/lib/chevre/service/offer/product.d.ts +1 -0
  92. package/lib/chevre/service/offer/product.js +7 -2
  93. package/lib/chevre/service/offer.d.ts +13 -2
  94. package/lib/chevre/service/offer.js +68 -46
  95. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +25 -27
  96. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
  97. package/lib/chevre/service/order/placeOrder.js +16 -0
  98. package/lib/chevre/service/order/returnOrder.js +6 -4
  99. package/lib/chevre/service/order/sendOrder.js +4 -2
  100. package/lib/chevre/service/payment/any.d.ts +9 -0
  101. package/lib/chevre/service/payment/any.js +16 -1
  102. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  103. package/lib/chevre/service/payment/movieTicket.js +8 -2
  104. package/lib/chevre/service/product.js +5 -3
  105. package/lib/chevre/service/report/telemetry.js +1 -1
  106. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  107. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  108. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
  109. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
  110. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  111. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +32 -35
  112. package/lib/chevre/service/reserve/useReservation.d.ts +0 -3
  113. package/lib/chevre/service/reserve/useReservation.js +58 -32
  114. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  115. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  116. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  117. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  118. package/lib/chevre/service/task/returnPayTransaction.js +10 -4
  119. package/lib/chevre/service/task.js +6 -9
  120. package/lib/chevre/service/transaction/moneyTransfer.js +9 -1
  121. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +1 -1
  122. package/lib/chevre/service/transaction/orderProgramMembership.js +6 -6
  123. package/lib/chevre/service/transaction/placeOrder.js +5 -3
  124. package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +1 -1
  125. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +0 -2
  126. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +2 -11
  127. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +1 -1
  128. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +3 -8
  129. package/lib/chevre/service/transaction/placeOrderInProgress.js +92 -107
  130. package/lib/chevre/service/transaction/returnOrder.js +8 -6
  131. package/lib/chevre/settings.d.ts +2 -0
  132. package/lib/chevre/settings.js +20 -12
  133. package/package.json +3 -3
  134. package/CHANGELOG.md +0 -2030
  135. package/example/.gitignore +0 -1
  136. package/example/src/chevre/.gitignore +0 -1
  137. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  138. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
  139. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.d.ts +0 -6
  140. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.js +0 -65
@@ -274,8 +274,8 @@ class MongoRepository {
274
274
  findById(params) {
275
275
  return __awaiter(this, void 0, void 0, function* () {
276
276
  const doc = yield this.transactionModel.findOne({
277
- _id: params.id,
278
- typeOf: params.typeOf
277
+ _id: { $eq: params.id },
278
+ typeOf: { $eq: params.typeOf }
279
279
  })
280
280
  .exec();
281
281
  if (doc === null) {
@@ -290,9 +290,9 @@ class MongoRepository {
290
290
  findInProgressById(params) {
291
291
  return __awaiter(this, void 0, void 0, function* () {
292
292
  const doc = yield this.transactionModel.findOne({
293
- _id: params.id,
294
- typeOf: params.typeOf,
295
- status: factory.transactionStatusType.InProgress
293
+ _id: { $eq: params.id },
294
+ typeOf: { $eq: params.typeOf },
295
+ status: { $eq: factory.transactionStatusType.InProgress }
296
296
  })
297
297
  .exec();
298
298
  if (doc === null) {
@@ -301,6 +301,42 @@ class MongoRepository {
301
301
  return doc.toObject();
302
302
  });
303
303
  }
304
+ /**
305
+ * 取引の注文番号を検索する
306
+ */
307
+ findInProgressOrderNumberById(params) {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ const doc = yield this.transactionModel.findOne({
310
+ _id: { $eq: params.id },
311
+ typeOf: { $eq: factory.transactionType.PlaceOrder },
312
+ status: { $eq: factory.transactionStatusType.InProgress }
313
+ }, { 'object.orderNumber': 1 })
314
+ .exec();
315
+ if (doc === null) {
316
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
317
+ }
318
+ const transaction = doc.toObject();
319
+ return transaction.object.orderNumber;
320
+ });
321
+ }
322
+ /**
323
+ * 取引の確認番号を検索する
324
+ */
325
+ findInProgressConfirmationNumberById(params) {
326
+ return __awaiter(this, void 0, void 0, function* () {
327
+ const doc = yield this.transactionModel.findOne({
328
+ _id: { $eq: params.id },
329
+ typeOf: { $eq: factory.transactionType.PlaceOrder },
330
+ status: { $eq: factory.transactionStatusType.InProgress }
331
+ }, { 'object.confirmationNumber': 1 })
332
+ .exec();
333
+ if (doc === null) {
334
+ throw new factory.errors.NotFound(this.transactionModel.modelName);
335
+ }
336
+ const transaction = doc.toObject();
337
+ return transaction.object.confirmationNumber;
338
+ });
339
+ }
304
340
  /**
305
341
  * 取引進行者プロフィールを更新
306
342
  */
@@ -313,6 +349,8 @@ class MongoRepository {
313
349
  status: factory.transactionStatusType.InProgress
314
350
  }, {
315
351
  $set: Object.assign(Object.assign({ 'agent.id': params.agent.id }, (typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined), (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { 'object.customer': params.object.customer } : undefined)
352
+ }, {
353
+ projection: { _id: 1 }
316
354
  })
317
355
  .exec();
318
356
  if (doc === null) {
@@ -333,6 +371,8 @@ class MongoRepository {
333
371
  $set: {
334
372
  expires: params.expires
335
373
  }
374
+ }, {
375
+ projection: { _id: 1 }
336
376
  })
337
377
  .exec();
338
378
  if (doc === null) {
@@ -353,6 +393,8 @@ class MongoRepository {
353
393
  status: factory.transactionStatusType.InProgress
354
394
  }, {
355
395
  $set: Object.assign({}, (typeof ((_a = params.object) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? { 'object.name': params.object.name } : undefined)
396
+ }, {
397
+ projection: { _id: 1 }
356
398
  })
357
399
  .exec();
358
400
  if (doc === null) {
@@ -375,7 +417,10 @@ class MongoRepository {
375
417
  'object.authorizeActions': params.authorizeActions,
376
418
  result: params.result,
377
419
  potentialActions: params.potentialActions // resultを更新
378
- }, { new: true })
420
+ }, {
421
+ new: true,
422
+ projection: { _id: 1 }
423
+ })
379
424
  .exec();
380
425
  // NotFoundであれば取引状態確認
381
426
  if (doc === null) {
@@ -384,7 +429,7 @@ class MongoRepository {
384
429
  /* istanbul ignore next */
385
430
  if (transaction.status === factory.transactionStatusType.Confirmed) {
386
431
  // すでに確定済の場合
387
- return transaction;
432
+ return;
388
433
  // tslint:disable-next-line:no-single-line-block-comment
389
434
  /* istanbul ignore next */
390
435
  }
@@ -402,7 +447,7 @@ class MongoRepository {
402
447
  throw new factory.errors.NotFound(this.transactionModel.modelName);
403
448
  }
404
449
  }
405
- return doc.toObject();
450
+ // return doc.toObject();
406
451
  });
407
452
  }
408
453
  /**
@@ -485,7 +530,10 @@ class MongoRepository {
485
530
  }, {
486
531
  status: factory.transactionStatusType.Canceled,
487
532
  endDate: endDate
488
- }, { new: true })
533
+ }, {
534
+ new: true,
535
+ projection: { _id: 1 }
536
+ })
489
537
  .exec();
490
538
  // NotFoundであれば取引状態確認
491
539
  if (doc === null) {
@@ -494,7 +542,7 @@ class MongoRepository {
494
542
  /* istanbul ignore next */
495
543
  if (transaction.status === factory.transactionStatusType.Canceled) {
496
544
  // すでに中止済の場合
497
- return transaction;
545
+ return;
498
546
  }
499
547
  else if (transaction.status === factory.transactionStatusType.Expired) {
500
548
  throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
@@ -506,7 +554,7 @@ class MongoRepository {
506
554
  throw new factory.errors.NotFound(this.transactionModel.modelName);
507
555
  }
508
556
  }
509
- return doc.toObject();
557
+ // return doc.toObject();
510
558
  });
511
559
  }
512
560
  count(params) {
@@ -542,43 +590,26 @@ class MongoRepository {
542
590
  .then((docs) => docs.map((doc) => doc.toObject()));
543
591
  });
544
592
  }
545
- // public stream<T extends factory.transactionType>(
546
- // params: factory.transaction.ISearchConditions<T>
547
- // ): QueryCursor<Document> {
548
- // const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
549
- // const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
550
- // .select({ __v: 0, createdAt: 0, updatedAt: 0 });
551
- // // tslint:disable-next-line:no-single-line-block-comment
552
- // /* istanbul ignore else */
553
- // if (params.limit !== undefined && params.page !== undefined) {
554
- // query.limit(params.limit)
555
- // .skip(params.limit * (params.page - 1));
556
- // }
557
- // // tslint:disable-next-line:no-single-line-block-comment
558
- // /* istanbul ignore else */
559
- // if (params.sort !== undefined) {
560
- // query.sort(params.sort);
561
- // }
562
- // return query.cursor();
563
- // }
564
593
  /**
565
594
  * 特定の取引を更新する(汎用)
566
595
  */
567
596
  findByIdAndUpdate(params) {
568
597
  return __awaiter(this, void 0, void 0, function* () {
569
- return this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, { new: true })
598
+ yield this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, {
599
+ // new: true,
600
+ projection: { _id: 1 }
601
+ })
570
602
  .exec()
571
603
  .then((doc) => {
572
604
  if (doc === null) {
573
605
  throw new factory.errors.ArgumentNull(this.transactionModel.modelName);
574
606
  }
575
- return doc.toObject();
576
607
  });
577
608
  });
578
609
  }
579
610
  saveOrderNumberIfNotExist(params) {
580
611
  return __awaiter(this, void 0, void 0, function* () {
581
- yield this.transactionModel.findOneAndUpdate({
612
+ yield this.transactionModel.updateOne({
582
613
  _id: params.id,
583
614
  'object.orderNumber': { $exists: false }
584
615
  }, { 'object.orderNumber': params.orderNumber })
@@ -587,7 +618,7 @@ class MongoRepository {
587
618
  }
588
619
  saveConfirmationNumberIfNotExist(params) {
589
620
  return __awaiter(this, void 0, void 0, function* () {
590
- yield this.transactionModel.findOneAndUpdate({
621
+ yield this.transactionModel.updateOne({
591
622
  _id: params.id,
592
623
  'object.confirmationNumber': { $exists: false }
593
624
  }, { 'object.confirmationNumber': params.confirmationNumber })
@@ -600,5 +631,168 @@ class MongoRepository {
600
631
  .exec();
601
632
  });
602
633
  }
634
+ aggregatePlaceOrder(params) {
635
+ return __awaiter(this, void 0, void 0, function* () {
636
+ const statuses = yield Promise.all([
637
+ factory.transactionStatusType.Confirmed,
638
+ factory.transactionStatusType.Canceled,
639
+ factory.transactionStatusType.Expired
640
+ ].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
641
+ var _a, _b;
642
+ const matchConditions = Object.assign(Object.assign({ startDate: {
643
+ $gte: params.startFrom,
644
+ $lte: params.startThrough
645
+ }, typeOf: { $eq: params.typeOf }, status: { $eq: transactionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
646
+ ? { 'project.id': { $ne: params.project.id.$ne } }
647
+ : undefined), (typeof params.clientId === 'string')
648
+ // customerIdentifierAll.push();
649
+ ? {
650
+ 'agent.identifier': {
651
+ $exists: true,
652
+ $all: [{ name: 'clientId', value: params.clientId }]
653
+ }
654
+ }
655
+ : undefined);
656
+ return this.agggregateByStatus({ matchConditions, status: transactionStatus });
657
+ })));
658
+ return { statuses };
659
+ });
660
+ }
661
+ // tslint:disable-next-line:max-func-body-length
662
+ agggregateByStatus(params) {
663
+ return __awaiter(this, void 0, void 0, function* () {
664
+ const matchConditions = params.matchConditions;
665
+ const transactionStatus = params.status;
666
+ const aggregations = yield this.transactionModel.aggregate([
667
+ {
668
+ $match: matchConditions
669
+ },
670
+ {
671
+ $project: {
672
+ duration: { $subtract: ['$endDate', '$startDate'] },
673
+ status: '$status',
674
+ startDate: '$startDate',
675
+ endDate: '$endDate',
676
+ typeOf: '$typeOf'
677
+ }
678
+ },
679
+ {
680
+ $group: {
681
+ _id: '$typeOf',
682
+ transactionCount: { $sum: 1 },
683
+ maxDuration: { $max: '$duration' },
684
+ minDuration: { $min: '$duration' },
685
+ avgDuration: { $avg: '$duration' }
686
+ }
687
+ },
688
+ {
689
+ $project: {
690
+ _id: 0,
691
+ transactionCount: '$transactionCount',
692
+ avgDuration: '$avgDuration',
693
+ maxDuration: '$maxDuration',
694
+ minDuration: '$minDuration'
695
+ }
696
+ }
697
+ ])
698
+ .exec();
699
+ // tslint:disable-next-line:no-magic-numbers
700
+ const percents = [50, 95, 99];
701
+ if (aggregations.length === 0) {
702
+ return {
703
+ status: transactionStatus,
704
+ aggregation: {
705
+ transactionCount: 0,
706
+ avgDuration: 0,
707
+ maxDuration: 0,
708
+ minDuration: 0,
709
+ percentilesDuration: percents.map((percent) => {
710
+ return {
711
+ name: String(percent),
712
+ value: 0
713
+ };
714
+ }),
715
+ acceptedOfferCount: 0,
716
+ avgAcceptedOfferCount: 0,
717
+ totalPrice: 0,
718
+ maxPrice: 0,
719
+ minPrice: 0,
720
+ avgPrice: 0
721
+ }
722
+ };
723
+ }
724
+ const ranks4percentile = percents.map((percentile) => {
725
+ return {
726
+ percentile,
727
+ // tslint:disable-next-line:no-magic-numbers
728
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
729
+ };
730
+ });
731
+ const aggregations2 = yield this.transactionModel.aggregate([
732
+ {
733
+ $match: matchConditions
734
+ },
735
+ {
736
+ $project: {
737
+ duration: { $subtract: ['$endDate', '$startDate'] },
738
+ status: '$status',
739
+ startDate: '$startDate',
740
+ endDate: '$endDate',
741
+ typeOf: '$typeOf',
742
+ // result: '$result',
743
+ acceptedOffers: {
744
+ $cond: {
745
+ if: { $isArray: '$result.order.acceptedOffers' },
746
+ then: '$result.order.acceptedOffers',
747
+ else: []
748
+ }
749
+ },
750
+ price: {
751
+ $cond: {
752
+ if: { $isNumber: '$result.order.price' },
753
+ then: '$result.order.price',
754
+ else: 0
755
+ }
756
+ }
757
+ }
758
+ },
759
+ { $sort: { duration: 1 } },
760
+ {
761
+ $group: {
762
+ _id: '$typeOf',
763
+ durations: { $push: '$duration' },
764
+ acceptedOfferCount: { $sum: { $size: '$acceptedOffers' } },
765
+ avgAcceptedOfferCount: { $avg: { $size: '$acceptedOffers' } },
766
+ totalPrice: { $sum: '$price' },
767
+ maxPrice: { $max: '$price' },
768
+ minPrice: { $min: '$price' },
769
+ avgPrice: { $avg: '$price' }
770
+ }
771
+ },
772
+ {
773
+ $project: {
774
+ _id: 0,
775
+ percentilesDuration: ranks4percentile.map((rank) => {
776
+ return {
777
+ name: String(rank.percentile),
778
+ value: { $arrayElemAt: ['$durations', rank.rank] }
779
+ };
780
+ }),
781
+ acceptedOfferCount: '$acceptedOfferCount',
782
+ avgAcceptedOfferCount: '$avgAcceptedOfferCount',
783
+ totalPrice: '$totalPrice',
784
+ maxPrice: '$maxPrice',
785
+ minPrice: '$minPrice',
786
+ avgPrice: '$avgPrice'
787
+ }
788
+ }
789
+ ])
790
+ .exec();
791
+ return {
792
+ status: transactionStatus,
793
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
794
+ };
795
+ });
796
+ }
603
797
  }
604
798
  exports.MongoRepository = MongoRepository;
@@ -32,18 +32,46 @@ class MongoRepository {
32
32
  }
33
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
34
34
  static CREATE_MONGO_CONDITIONS(conditions) {
35
- var _a, _b, _c;
35
+ var _a, _b, _c, _d, _e, _f;
36
36
  const andConditions = [{ typeOf: { $eq: conditions.typeOf } }];
37
37
  const projectIdEq = (_b = (_a = conditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
38
38
  if (typeof projectIdEq === 'string') {
39
- andConditions.push({
40
- 'project.id': { $eq: projectIdEq }
41
- });
39
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
42
40
  }
43
41
  const idIn = (_c = conditions.id) === null || _c === void 0 ? void 0 : _c.$in;
44
42
  if (Array.isArray(idIn)) {
43
+ andConditions.push({ _id: { $in: idIn } });
44
+ }
45
+ const identifierEq = (_d = conditions.identifier) === null || _d === void 0 ? void 0 : _d.$eq;
46
+ if (typeof identifierEq === 'string') {
47
+ andConditions.push({ identifier: { $eq: identifierEq } });
48
+ }
49
+ const nameRegex = (_e = conditions.name) === null || _e === void 0 ? void 0 : _e.$regex;
50
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
51
+ andConditions.push({
52
+ $or: [
53
+ {
54
+ 'name.ja': {
55
+ $exists: true,
56
+ $regex: new RegExp(nameRegex)
57
+ }
58
+ },
59
+ {
60
+ 'name.en': {
61
+ $exists: true,
62
+ $regex: new RegExp(nameRegex)
63
+ }
64
+ }
65
+ ]
66
+ });
67
+ }
68
+ const additionalPropertyElemMatch = (_f = conditions.additionalProperty) === null || _f === void 0 ? void 0 : _f.$elemMatch;
69
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
45
70
  andConditions.push({
46
- _id: { $in: idIn }
71
+ additionalProperty: {
72
+ $exists: true,
73
+ $elemMatch: additionalPropertyElemMatch
74
+ }
47
75
  });
48
76
  }
49
77
  return andConditions;
@@ -119,28 +147,6 @@ class MongoRepository {
119
147
  if (p.attributes.typeOf === factory.tripType.BusTrip) {
120
148
  // 上書き禁止属性を除外
121
149
  const _a = p.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
122
- bulkWriteOps.push({
123
- updateOne: {
124
- filter: {
125
- _id: p.id,
126
- typeOf: p.attributes.typeOf
127
- },
128
- // upsertの場合、createがありうるので属性を除外しない
129
- update: Object.assign({ $setOnInsert: {
130
- typeOf: p.attributes.typeOf,
131
- project: p.attributes.project,
132
- identifier: p.attributes.identifier
133
- // ...(typeof p.attributes.remainingAttendeeCapacity === 'number')
134
- // ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
135
- // : undefined
136
- }, $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
137
- upsert
138
- }
139
- });
140
- }
141
- else if (p.attributes.typeOf === factory.tripType.BusTripSeries) {
142
- // 上書き禁止属性を除外
143
- const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
144
150
  bulkWriteOps.push({
145
151
  updateOne: {
146
152
  filter: {
@@ -7,6 +7,7 @@ import { MongoRepository as AccountTitleRepo } from './repo/accountTitle';
7
7
  import { MongoRepository as AccountTransactionRepo } from './repo/accountTransaction';
8
8
  import { MongoRepository as ActionRepo } from './repo/action';
9
9
  import { MongoRepository as AdditionalPropertyRepo } from './repo/additionalProperty';
10
+ import { MongoRepository as AggregationRepo } from './repo/aggregation';
10
11
  import { MongoRepository as AssetTransactionRepo } from './repo/assetTransaction';
11
12
  import { MongoRepository as CategoryCodeRepo } from './repo/categoryCode';
12
13
  import { MongoRepository as CodeRepo } from './repo/code';
@@ -69,6 +70,8 @@ export declare class Action extends ActionRepo {
69
70
  */
70
71
  export declare class AdditionalProperty extends AdditionalPropertyRepo {
71
72
  }
73
+ export declare class Aggregation extends AggregationRepo {
74
+ }
72
75
  export declare namespace action {
73
76
  class RegisterServiceInProgress extends RegisterServiceActionInProgress {
74
77
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rateLimit = exports.itemAvailability = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
3
+ exports.rateLimit = exports.itemAvailability = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.Aggregation = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
4
4
  // tslint:disable:max-classes-per-file completed-docs
5
5
  /**
6
6
  * リポジトリ
@@ -11,6 +11,7 @@ const accountTitle_1 = require("./repo/accountTitle");
11
11
  const accountTransaction_1 = require("./repo/accountTransaction");
12
12
  const action_1 = require("./repo/action");
13
13
  const additionalProperty_1 = require("./repo/additionalProperty");
14
+ const aggregation_1 = require("./repo/aggregation");
14
15
  const assetTransaction_1 = require("./repo/assetTransaction");
15
16
  const categoryCode_1 = require("./repo/categoryCode");
16
17
  const code_1 = require("./repo/code");
@@ -80,6 +81,9 @@ exports.Action = Action;
80
81
  class AdditionalProperty extends additionalProperty_1.MongoRepository {
81
82
  }
82
83
  exports.AdditionalProperty = AdditionalProperty;
84
+ class Aggregation extends aggregation_1.MongoRepository {
85
+ }
86
+ exports.Aggregation = Aggregation;
83
87
  var action;
84
88
  (function (action) {
85
89
  class RegisterServiceInProgress extends registerServiceInProgress_1.RedisRepository {