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

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 (116) 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/findScreeningRoomsByBranchCode.ts +27 -0
  4. package/example/src/chevre/importEventsFromCOA.ts +8 -1
  5. package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
  6. package/example/src/chevre/migrateProjectSubscription.ts +51 -0
  7. package/example/src/chevre/processReserve.ts +2 -0
  8. package/example/src/chevre/searchEventIds.ts +24 -0
  9. package/example/src/chevre/searchEventTicketOffers.ts +4 -4
  10. package/example/src/chevre/searchEvents.ts +20 -41
  11. package/example/src/chevre/searchOffersByCatalog.ts +27 -0
  12. package/example/src/chevre/updateTransaction.ts +38 -0
  13. package/lib/chevre/factory/event.d.ts +2 -0
  14. package/lib/chevre/factory/event.js +2 -0
  15. package/lib/chevre/repo/action.d.ts +67 -0
  16. package/lib/chevre/repo/action.js +209 -0
  17. package/lib/chevre/repo/aggregation.d.ts +37 -0
  18. package/lib/chevre/repo/aggregation.js +67 -0
  19. package/lib/chevre/repo/assetTransaction.d.ts +32 -0
  20. package/lib/chevre/repo/assetTransaction.js +148 -0
  21. package/lib/chevre/repo/event.d.ts +62 -16
  22. package/lib/chevre/repo/event.js +458 -156
  23. package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
  24. package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
  25. package/lib/chevre/repo/mongoose/model/event.js +4 -3
  26. package/lib/chevre/repo/mongoose/model/offer.js +2 -1
  27. package/lib/chevre/repo/mongoose/model/project.js +7 -1
  28. package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
  29. package/lib/chevre/repo/offer.d.ts +10 -0
  30. package/lib/chevre/repo/offer.js +47 -16
  31. package/lib/chevre/repo/order.d.ts +2 -0
  32. package/lib/chevre/repo/order.js +29 -7
  33. package/lib/chevre/repo/place.d.ts +26 -1
  34. package/lib/chevre/repo/place.js +216 -12
  35. package/lib/chevre/repo/product.d.ts +1 -0
  36. package/lib/chevre/repo/product.js +5 -0
  37. package/lib/chevre/repo/project.d.ts +4 -1
  38. package/lib/chevre/repo/project.js +9 -10
  39. package/lib/chevre/repo/reservation.d.ts +0 -6
  40. package/lib/chevre/repo/reservation.js +106 -66
  41. package/lib/chevre/repo/task.d.ts +31 -3
  42. package/lib/chevre/repo/task.js +141 -27
  43. package/lib/chevre/repo/transaction.d.ts +45 -5
  44. package/lib/chevre/repo/transaction.js +187 -29
  45. package/lib/chevre/repo/trip.js +33 -27
  46. package/lib/chevre/repository.d.ts +3 -0
  47. package/lib/chevre/repository.js +5 -1
  48. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.d.ts +1 -1
  49. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +86 -59
  50. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +5 -8
  51. package/lib/chevre/service/aggregation/system.d.ts +93 -0
  52. package/lib/chevre/service/aggregation/system.js +377 -0
  53. package/lib/chevre/service/aggregation.d.ts +2 -0
  54. package/lib/chevre/service/aggregation.js +3 -1
  55. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
  56. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +2 -4
  57. package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
  58. package/lib/chevre/service/assetTransaction/pay.js +65 -32
  59. package/lib/chevre/service/assetTransaction/registerService.js +4 -1
  60. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
  61. package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
  62. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +16 -0
  63. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +84 -0
  64. package/lib/chevre/service/assetTransaction/reserve.d.ts +38 -6
  65. package/lib/chevre/service/assetTransaction/reserve.js +119 -94
  66. package/lib/chevre/service/delivery/factory.d.ts +1 -1
  67. package/lib/chevre/service/delivery/factory.js +1 -0
  68. package/lib/chevre/service/event.d.ts +2 -4
  69. package/lib/chevre/service/event.js +35 -14
  70. package/lib/chevre/service/offer/event/authorize.d.ts +4 -7
  71. package/lib/chevre/service/offer/event/authorize.js +26 -87
  72. package/lib/chevre/service/offer/event/cancel.js +0 -1
  73. package/lib/chevre/service/offer/event/factory.d.ts +3 -2
  74. package/lib/chevre/service/offer/event/factory.js +25 -5
  75. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +13 -7
  76. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +81 -45
  77. package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
  78. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  79. package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
  80. package/lib/chevre/service/offer/factory.js +10 -3
  81. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -0
  82. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  83. package/lib/chevre/service/offer/product.d.ts +1 -0
  84. package/lib/chevre/service/offer/product.js +6 -2
  85. package/lib/chevre/service/offer.d.ts +5 -1
  86. package/lib/chevre/service/offer.js +67 -46
  87. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +2 -1
  88. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -1
  89. package/lib/chevre/service/order/placeOrder.js +16 -0
  90. package/lib/chevre/service/order/returnOrder.js +1 -1
  91. package/lib/chevre/service/order/sendOrder.js +4 -2
  92. package/lib/chevre/service/payment/any.d.ts +5 -0
  93. package/lib/chevre/service/payment/any.js +1 -1
  94. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  95. package/lib/chevre/service/payment/movieTicket.js +8 -2
  96. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  97. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
  98. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
  99. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  100. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +2 -1
  101. package/lib/chevre/service/reserve/useReservation.js +7 -2
  102. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  103. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  104. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  105. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  106. package/lib/chevre/service/task/returnPayTransaction.js +5 -1
  107. package/lib/chevre/service/task.js +6 -9
  108. package/lib/chevre/service/transaction/orderProgramMembership.js +2 -1
  109. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +42 -27
  110. package/lib/chevre/service/transaction/placeOrderInProgress.js +7 -7
  111. package/lib/chevre/service/transaction/returnOrder.js +3 -3
  112. package/lib/chevre/settings.d.ts +2 -0
  113. package/lib/chevre/settings.js +7 -2
  114. package/package.json +3 -3
  115. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  116. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
@@ -677,5 +677,214 @@ class MongoRepository {
677
677
  .exec();
678
678
  });
679
679
  }
680
+ aggregateAuthorizeEventServiceOfferAction(params) {
681
+ return __awaiter(this, void 0, void 0, function* () {
682
+ const statuses = yield Promise.all([
683
+ factory.actionStatusType.CompletedActionStatus,
684
+ factory.actionStatusType.CanceledActionStatus,
685
+ factory.actionStatusType.FailedActionStatus
686
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
687
+ var _a, _b;
688
+ const matchConditions = Object.assign({ startDate: {
689
+ $gte: params.startFrom,
690
+ $lte: params.startThrough
691
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
692
+ $exists: true,
693
+ $eq: factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation
694
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
695
+ ? { 'project.id': { $ne: params.project.id.$ne } }
696
+ : undefined);
697
+ return this.agggregateByStatus({ matchConditions, actionStatus });
698
+ })));
699
+ return { statuses };
700
+ });
701
+ }
702
+ aggregateAuthorizePaymentAction(params) {
703
+ return __awaiter(this, void 0, void 0, function* () {
704
+ const statuses = yield Promise.all([
705
+ factory.actionStatusType.CompletedActionStatus,
706
+ factory.actionStatusType.CanceledActionStatus,
707
+ factory.actionStatusType.FailedActionStatus
708
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
709
+ var _a, _b;
710
+ const matchConditions = Object.assign({ startDate: {
711
+ $gte: params.startFrom,
712
+ $lte: params.startThrough
713
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
714
+ $exists: true,
715
+ $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
716
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
717
+ ? { 'project.id': { $ne: params.project.id.$ne } }
718
+ : undefined);
719
+ return this.agggregateByStatus({ matchConditions, actionStatus });
720
+ })));
721
+ return { statuses };
722
+ });
723
+ }
724
+ aggregateAuthorizeOrderAction(params) {
725
+ return __awaiter(this, void 0, void 0, function* () {
726
+ const statuses = yield Promise.all([
727
+ factory.actionStatusType.CompletedActionStatus,
728
+ factory.actionStatusType.CanceledActionStatus,
729
+ factory.actionStatusType.FailedActionStatus
730
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
731
+ var _a, _b;
732
+ const matchConditions = Object.assign({ startDate: {
733
+ $gte: params.startFrom,
734
+ $lte: params.startThrough
735
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
736
+ $exists: true,
737
+ $eq: factory.order.OrderType.Order
738
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
739
+ ? { 'project.id': { $ne: params.project.id.$ne } }
740
+ : undefined);
741
+ return this.agggregateByStatus({ matchConditions, actionStatus });
742
+ })));
743
+ return { statuses };
744
+ });
745
+ }
746
+ aggregateUseAction(params) {
747
+ return __awaiter(this, void 0, void 0, function* () {
748
+ const statuses = yield Promise.all([
749
+ factory.actionStatusType.CompletedActionStatus,
750
+ factory.actionStatusType.CanceledActionStatus,
751
+ factory.actionStatusType.FailedActionStatus
752
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
753
+ var _a, _b;
754
+ const matchConditions = Object.assign({ startDate: {
755
+ $gte: params.startFrom,
756
+ $lte: params.startThrough
757
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
758
+ ? { 'project.id': { $ne: params.project.id.$ne } }
759
+ : undefined);
760
+ return this.agggregateByStatus({ matchConditions, actionStatus });
761
+ })));
762
+ return { statuses };
763
+ });
764
+ }
765
+ aggregateCheckMovieTicketAction(params) {
766
+ return __awaiter(this, void 0, void 0, function* () {
767
+ const statuses = yield Promise.all([
768
+ factory.actionStatusType.CompletedActionStatus,
769
+ factory.actionStatusType.CanceledActionStatus,
770
+ factory.actionStatusType.FailedActionStatus
771
+ ].map((actionStatus) => __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: factory.actionType.CheckAction }, 'object.typeOf': {
777
+ $exists: true,
778
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
779
+ }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
780
+ ? { 'project.id': { $ne: params.project.id.$ne } }
781
+ : undefined);
782
+ return this.agggregateByStatus({ matchConditions, actionStatus });
783
+ })));
784
+ return { statuses };
785
+ });
786
+ }
787
+ // tslint:disable-next-line:max-func-body-length
788
+ agggregateByStatus(params) {
789
+ return __awaiter(this, void 0, void 0, function* () {
790
+ const aggregations = yield this.actionModel.aggregate([
791
+ { $match: params.matchConditions },
792
+ {
793
+ $project: {
794
+ duration: { $subtract: ['$endDate', '$startDate'] },
795
+ actionStatus: '$actionStatus',
796
+ startDate: '$startDate',
797
+ endDate: '$endDate',
798
+ typeOf: '$typeOf'
799
+ }
800
+ },
801
+ {
802
+ $group: {
803
+ _id: '$typeOf',
804
+ actionCount: { $sum: 1 },
805
+ maxDuration: { $max: '$duration' },
806
+ minDuration: { $min: '$duration' },
807
+ avgDuration: { $avg: '$duration' }
808
+ }
809
+ },
810
+ {
811
+ $project: {
812
+ _id: 0,
813
+ actionCount: '$actionCount',
814
+ avgDuration: '$avgDuration',
815
+ maxDuration: '$maxDuration',
816
+ minDuration: '$minDuration'
817
+ }
818
+ }
819
+ ])
820
+ .exec();
821
+ // tslint:disable-next-line:no-magic-numbers
822
+ const percents = [50, 95, 99];
823
+ if (aggregations.length === 0) {
824
+ return {
825
+ status: params.actionStatus,
826
+ aggregation: {
827
+ actionCount: 0,
828
+ avgDuration: 0,
829
+ maxDuration: 0,
830
+ minDuration: 0,
831
+ percentilesDuration: percents.map((percent) => {
832
+ return {
833
+ name: String(percent),
834
+ value: 0
835
+ };
836
+ })
837
+ }
838
+ };
839
+ }
840
+ const ranks4percentile = percents.map((percentile) => {
841
+ return {
842
+ percentile,
843
+ // tslint:disable-next-line:no-magic-numbers
844
+ rank: Math.floor(aggregations[0].actionCount * percentile / 100)
845
+ };
846
+ });
847
+ const aggregations2 = yield this.actionModel.aggregate([
848
+ {
849
+ $match: params.matchConditions
850
+ },
851
+ {
852
+ $project: {
853
+ duration: { $subtract: ['$endDate', '$startDate'] },
854
+ actionStatus: '$actionStatus',
855
+ startDate: '$startDate',
856
+ endDate: '$endDate',
857
+ typeOf: '$typeOf'
858
+ }
859
+ },
860
+ { $sort: { duration: 1 } },
861
+ {
862
+ $group: {
863
+ _id: '$typeOf',
864
+ durations: { $push: '$duration' }
865
+ }
866
+ },
867
+ {
868
+ $project: {
869
+ _id: 0,
870
+ avgSmallDuration: '$avgSmallDuration',
871
+ avgMediumDuration: '$avgMediumDuration',
872
+ avgLargeDuration: '$avgLargeDuration',
873
+ percentilesDuration: ranks4percentile.map((rank) => {
874
+ return {
875
+ name: String(rank.percentile),
876
+ value: { $arrayElemAt: ['$durations', rank.rank] }
877
+ };
878
+ })
879
+ }
880
+ }
881
+ ])
882
+ .exec();
883
+ return {
884
+ status: params.actionStatus,
885
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
886
+ };
887
+ });
888
+ }
680
889
  }
681
890
  exports.MongoRepository = MongoRepository;
@@ -0,0 +1,37 @@
1
+ import { Connection, Model } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ export declare enum AggregationType {
4
+ AggregateAuthorizeEventServiceOfferAction = "AggregateAuthorizeEventServiceOfferAction",
5
+ AggregateAuthorizeOrderAction = "AggregateAuthorizeOrderAction",
6
+ AggregateAuthorizePaymentAction = "AggregateAuthorizePaymentAction",
7
+ AggregateCheckMovieTicketAction = "AggregateCheckMovieTicketAction",
8
+ AggregateEvent = "AggregateEvent",
9
+ AggregatePay = "AggregatePay",
10
+ AggregatePlaceOrder = "AggregatePlaceOrder",
11
+ AggregateReserve = "AggregateReserve",
12
+ AggregateTask = "AggregateTask",
13
+ AggregateUseAction = "AggregateUseAction"
14
+ }
15
+ export interface IAggregationByClient {
16
+ clientId: string;
17
+ aggregation: any;
18
+ }
19
+ export interface IAggregation {
20
+ typeOf: AggregationType;
21
+ project: {
22
+ id: string;
23
+ typeOf: factory.organizationType.Project;
24
+ };
25
+ aggregateDate: Date;
26
+ aggregateDuration: string;
27
+ aggregateStart: Date;
28
+ aggregationByClient?: IAggregationByClient[];
29
+ }
30
+ /**
31
+ * 集計リポジトリ
32
+ */
33
+ export declare class MongoRepository {
34
+ readonly aggregationModel: typeof Model;
35
+ constructor(connection: Connection);
36
+ saveAggregation(params: IAggregation): Promise<any>;
37
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.MongoRepository = exports.AggregationType = void 0;
24
+ const aggregation_1 = require("./mongoose/model/aggregation");
25
+ var AggregationType;
26
+ (function (AggregationType) {
27
+ AggregationType["AggregateAuthorizeEventServiceOfferAction"] = "AggregateAuthorizeEventServiceOfferAction";
28
+ AggregationType["AggregateAuthorizeOrderAction"] = "AggregateAuthorizeOrderAction";
29
+ AggregationType["AggregateAuthorizePaymentAction"] = "AggregateAuthorizePaymentAction";
30
+ AggregationType["AggregateCheckMovieTicketAction"] = "AggregateCheckMovieTicketAction";
31
+ AggregationType["AggregateEvent"] = "AggregateEvent";
32
+ AggregationType["AggregatePay"] = "AggregatePay";
33
+ AggregationType["AggregatePlaceOrder"] = "AggregatePlaceOrder";
34
+ AggregationType["AggregateReserve"] = "AggregateReserve";
35
+ AggregationType["AggregateTask"] = "AggregateTask";
36
+ AggregationType["AggregateUseAction"] = "AggregateUseAction";
37
+ })(AggregationType = exports.AggregationType || (exports.AggregationType = {}));
38
+ /**
39
+ * 集計リポジトリ
40
+ */
41
+ class MongoRepository {
42
+ constructor(connection) {
43
+ this.aggregationModel = connection.model(aggregation_1.modelName);
44
+ }
45
+ saveAggregation(params) {
46
+ return __awaiter(this, void 0, void 0, function* () {
47
+ const { typeOf, project, aggregateDuration, aggregateStart } = params, setFields = __rest(params, ["typeOf", "project", "aggregateDuration", "aggregateStart"]);
48
+ const doc = yield this.aggregationModel.findOneAndUpdate({
49
+ typeOf: { $eq: params.typeOf },
50
+ 'project.id': { $eq: params.project.id },
51
+ aggregateStart: { $eq: params.aggregateStart },
52
+ aggregateDuration: { $eq: params.aggregateDuration }
53
+ }, {
54
+ $setOnInsert: {
55
+ typeOf: params.typeOf,
56
+ project: params.project,
57
+ aggregateDuration: params.aggregateDuration,
58
+ aggregateStart: params.aggregateStart
59
+ },
60
+ $set: setFields
61
+ }, { upsert: true, new: true })
62
+ .exec();
63
+ return doc.toObject();
64
+ });
65
+ }
66
+ }
67
+ exports.MongoRepository = MongoRepository;
@@ -2,6 +2,27 @@ import { Connection } from 'mongoose';
2
2
  import { modelName } from './mongoose/model/assetTransaction';
3
3
  import * as factory from '../factory';
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
+ reservationCount: number;
15
+ avgGraceTime: number;
16
+ maxGraceTime: number;
17
+ minGraceTime: number;
18
+ }
19
+ interface IStatus {
20
+ status: factory.transactionStatusType;
21
+ aggregation: IAggregationByStatus;
22
+ }
23
+ export interface IAggregateReserve {
24
+ statuses: IStatus[];
25
+ }
5
26
  /**
6
27
  * 資産取引リポジトリ
7
28
  */
@@ -123,4 +144,15 @@ export declare class MongoRepository {
123
144
  findByIdAndDelete(params: {
124
145
  id: string;
125
146
  }): Promise<void>;
147
+ aggregateAssetTransaction(params: {
148
+ project?: {
149
+ id?: {
150
+ $ne?: string;
151
+ };
152
+ };
153
+ startFrom: Date;
154
+ startThrough: Date;
155
+ typeOf: factory.assetTransactionType;
156
+ }): Promise<IAggregateReserve>;
157
+ private agggregateByStatus;
126
158
  }
@@ -536,5 +536,153 @@ class MongoRepository {
536
536
  .exec();
537
537
  });
538
538
  }
539
+ aggregateAssetTransaction(params) {
540
+ return __awaiter(this, void 0, void 0, function* () {
541
+ const statuses = yield Promise.all([
542
+ factory.transactionStatusType.Confirmed,
543
+ factory.transactionStatusType.Canceled,
544
+ factory.transactionStatusType.Expired
545
+ ].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
546
+ var _a, _b;
547
+ const matchConditions = Object.assign({ startDate: {
548
+ $gte: params.startFrom,
549
+ $lte: params.startThrough
550
+ }, 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')
551
+ ? { 'project.id': { $ne: params.project.id.$ne } }
552
+ : undefined);
553
+ return this.agggregateByStatus({ matchConditions, status: transactionStatus });
554
+ })));
555
+ return { statuses };
556
+ });
557
+ }
558
+ // tslint:disable-next-line:max-func-body-length
559
+ agggregateByStatus(params) {
560
+ return __awaiter(this, void 0, void 0, function* () {
561
+ const matchConditions = params.matchConditions;
562
+ const transactionStatus = params.status;
563
+ const aggregations = yield this.transactionModel.aggregate([
564
+ {
565
+ $match: matchConditions
566
+ },
567
+ {
568
+ $project: {
569
+ duration: { $subtract: ['$endDate', '$startDate'] },
570
+ graceTime: {
571
+ $cond: {
572
+ if: { $eq: ['$typeOf', factory.assetTransactionType.Reserve] },
573
+ then: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
574
+ else: 0
575
+ }
576
+ },
577
+ status: '$status',
578
+ startDate: '$startDate',
579
+ endDate: '$endDate',
580
+ typeOf: '$typeOf',
581
+ reservationCount: {
582
+ $cond: {
583
+ if: { $isArray: '$object.subReservation' },
584
+ then: { $size: '$object.subReservation' },
585
+ else: 0
586
+ }
587
+ }
588
+ }
589
+ },
590
+ {
591
+ $group: {
592
+ _id: '$typeOf',
593
+ transactionCount: { $sum: 1 },
594
+ maxDuration: { $max: '$duration' },
595
+ minDuration: { $min: '$duration' },
596
+ avgDuration: { $avg: '$duration' },
597
+ reservationCount: { $sum: '$reservationCount' },
598
+ maxGraceTime: { $max: '$graceTime' },
599
+ minGraceTime: { $min: '$graceTime' },
600
+ avgGraceTime: { $avg: '$graceTime' }
601
+ }
602
+ },
603
+ {
604
+ $project: {
605
+ _id: 0,
606
+ transactionCount: '$transactionCount',
607
+ avgDuration: '$avgDuration',
608
+ maxDuration: '$maxDuration',
609
+ minDuration: '$minDuration',
610
+ reservationCount: '$reservationCount',
611
+ avgGraceTime: '$avgGraceTime',
612
+ maxGraceTime: '$maxGraceTime',
613
+ minGraceTime: '$minGraceTime'
614
+ }
615
+ }
616
+ ])
617
+ .exec();
618
+ // tslint:disable-next-line:no-magic-numbers
619
+ const percents = [50, 95, 99];
620
+ if (aggregations.length === 0) {
621
+ return {
622
+ status: transactionStatus,
623
+ aggregation: {
624
+ transactionCount: 0,
625
+ avgDuration: 0,
626
+ maxDuration: 0,
627
+ minDuration: 0,
628
+ percentilesDuration: percents.map((percent) => {
629
+ return {
630
+ name: String(percent),
631
+ value: 0
632
+ };
633
+ }),
634
+ reservationCount: 0,
635
+ avgGraceTime: 0,
636
+ maxGraceTime: 0,
637
+ minGraceTime: 0
638
+ }
639
+ };
640
+ }
641
+ const ranks4percentile = percents.map((percentile) => {
642
+ return {
643
+ percentile,
644
+ // tslint:disable-next-line:no-magic-numbers
645
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
646
+ };
647
+ });
648
+ const aggregations2 = yield this.transactionModel.aggregate([
649
+ {
650
+ $match: matchConditions
651
+ },
652
+ {
653
+ $project: {
654
+ duration: { $subtract: ['$endDate', '$startDate'] },
655
+ status: '$status',
656
+ startDate: '$startDate',
657
+ endDate: '$endDate',
658
+ typeOf: '$typeOf'
659
+ }
660
+ },
661
+ { $sort: { duration: 1 } },
662
+ {
663
+ $group: {
664
+ _id: '$typeOf',
665
+ durations: { $push: '$duration' }
666
+ }
667
+ },
668
+ {
669
+ $project: {
670
+ _id: 0,
671
+ percentilesDuration: ranks4percentile.map((rank) => {
672
+ return {
673
+ name: String(rank.percentile),
674
+ value: { $arrayElemAt: ['$durations', rank.rank] }
675
+ };
676
+ })
677
+ }
678
+ }
679
+ ])
680
+ .exec();
681
+ return {
682
+ status: transactionStatus,
683
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
684
+ };
685
+ });
686
+ }
539
687
  }
540
688
  exports.MongoRepository = MongoRepository;
@@ -1,5 +1,6 @@
1
1
  import { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ import * as EventFactory from '../factory/event';
3
4
  export interface IAttributes4patchUpdate<T extends factory.eventType> {
4
5
  typeOf: T;
5
6
  eventStatus?: factory.eventStatusType;
@@ -30,6 +31,32 @@ export interface IUpdateAggregateUseActionsParams {
30
31
  };
31
32
  }
32
33
  export declare type ISearchConditions<T extends factory.eventType> = factory.event.ISearchConditions<T>;
34
+ interface IAggregationByStatus {
35
+ eventCount: number;
36
+ reservationCount: number;
37
+ avgOfferCount: number;
38
+ maximumAttendeeCapacity: number;
39
+ remainingAttendeeCapacity: number;
40
+ avgRemainingCapacityRate: number;
41
+ maxRemainingCapacityRate: number;
42
+ minRemainingCapacityRate: number;
43
+ percentilesRemainingCapacityRate: {
44
+ name: string;
45
+ value: number;
46
+ }[];
47
+ }
48
+ interface IStatus {
49
+ status: factory.eventStatusType;
50
+ aggregation: IAggregationByStatus;
51
+ }
52
+ export interface IAggregateEvent {
53
+ statuses: IStatus[];
54
+ }
55
+ interface IProjection {
56
+ [key: string]: number;
57
+ }
58
+ export import IMinimizedIndividualEvent = EventFactory.IMinimizedIndividualEvent;
59
+ export declare const PROJECTION_MINIMIZED_EVENT: IProjection;
33
60
  /**
34
61
  * イベントリポジトリ
35
62
  */
@@ -40,7 +67,19 @@ export declare class MongoRepository {
40
67
  /**
41
68
  * 複数イベントを作成する
42
69
  */
43
- createMany<T extends factory.eventType>(params: factory.event.IAttributes<T>[]): Promise<factory.event.IEvent<T>[]>;
70
+ createMany<T extends factory.eventType>(params: {
71
+ attributes: factory.event.IAttributes<T>[];
72
+ expectsNoContent: boolean;
73
+ }): Promise<factory.event.IEvent<T>[] | void>;
74
+ /**
75
+ * 特定の追加特性をキーにして、なければ作成する(複数対応)
76
+ */
77
+ createIfNotExistMany<T extends factory.eventType.ScreeningEvent>(params: {
78
+ attributes: factory.event.IAttributes<T>;
79
+ filter: {
80
+ name: string;
81
+ };
82
+ }[]): Promise<void>;
44
83
  /**
45
84
  * イベント部分更新
46
85
  */
@@ -54,36 +93,31 @@ export declare class MongoRepository {
54
93
  save<T extends factory.eventType>(params: {
55
94
  id?: string;
56
95
  attributes: factory.event.IAttributes<T>;
57
- $unset?: {
58
- [key: string]: number;
59
- };
96
+ $unset?: IProjection;
60
97
  upsert?: boolean;
61
98
  }): Promise<factory.event.IEvent<T>>;
62
99
  saveMany<T extends factory.eventType>(params: {
63
- id?: string;
100
+ id: string;
64
101
  attributes: factory.event.IAttributes<T>;
65
- $unset?: {
66
- [key: string]: number;
67
- };
68
- upsert?: boolean;
102
+ $unset?: IProjection;
103
+ upsert: boolean;
69
104
  }[]): Promise<void>;
70
105
  save4ttts(params: {
71
106
  oldEventId: string;
72
107
  attributes: factory.event.IAttributes<factory.eventType.ScreeningEvent>;
73
- useOldEventId: boolean;
74
108
  }): Promise<factory.event.IEvent<factory.eventType.ScreeningEvent>>;
75
109
  count<T extends factory.eventType>(params: ISearchConditions<T>): Promise<number>;
76
110
  /**
77
111
  * イベントを検索する
78
112
  */
79
- search<T extends factory.eventType>(params: ISearchConditions<T>, projection?: {
80
- [key: string]: number;
81
- }): Promise<factory.event.IEvent<T>[]>;
113
+ search<T extends factory.eventType>(params: ISearchConditions<T>, projection?: IProjection): Promise<factory.event.IEvent<T>[]>;
114
+ searchIds<T extends factory.eventType>(params: ISearchConditions<T>): Promise<string[]>;
82
115
  findById<T extends factory.eventType>(params: {
83
116
  id: string;
84
- }, projection?: {
85
- [key: string]: number;
86
- }): Promise<factory.event.IEvent<T>>;
117
+ }, projection?: IProjection): Promise<factory.event.IEvent<T>>;
118
+ findMinimizedIndividualEventById<T extends factory.eventType.ScreeningEvent | factory.eventType.Event>(params: {
119
+ id: string;
120
+ }): Promise<IMinimizedIndividualEvent<T>>;
87
121
  /**
88
122
  * イベントをキャンセルする
89
123
  */
@@ -109,4 +143,16 @@ export declare class MongoRepository {
109
143
  deleteUnnecessaryProjectAttributesById(params: {
110
144
  id: string;
111
145
  }): Promise<void>;
146
+ aggregateEvent(params: {
147
+ project?: {
148
+ id?: {
149
+ $ne?: string;
150
+ };
151
+ };
152
+ startFrom: Date;
153
+ startThrough: Date;
154
+ typeOf: factory.eventType;
155
+ }): Promise<IAggregateEvent>;
156
+ private agggregateByStatus;
112
157
  }
158
+ export {};