@chevre/domain 20.2.0-alpha.9 → 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 (135) 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 +72 -60
  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 +0 -3
  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 +23 -26
  96. package/lib/chevre/service/order/returnOrder.js +6 -4
  97. package/lib/chevre/service/order/sendOrder.js +4 -2
  98. package/lib/chevre/service/payment/any.d.ts +9 -0
  99. package/lib/chevre/service/payment/any.js +16 -1
  100. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  101. package/lib/chevre/service/payment/movieTicket.js +8 -2
  102. package/lib/chevre/service/product.js +5 -3
  103. package/lib/chevre/service/report/telemetry.js +1 -1
  104. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  105. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  106. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
  107. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
  108. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  109. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +32 -35
  110. package/lib/chevre/service/reserve/useReservation.d.ts +0 -3
  111. package/lib/chevre/service/reserve/useReservation.js +58 -33
  112. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  113. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  114. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  115. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  116. package/lib/chevre/service/task/returnPayTransaction.js +10 -4
  117. package/lib/chevre/service/task.js +6 -9
  118. package/lib/chevre/service/transaction/moneyTransfer.js +9 -1
  119. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +1 -1
  120. package/lib/chevre/service/transaction/orderProgramMembership.js +6 -6
  121. package/lib/chevre/service/transaction/placeOrder.js +5 -3
  122. package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +1 -1
  123. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +0 -2
  124. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +2 -11
  125. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +1 -1
  126. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +3 -8
  127. package/lib/chevre/service/transaction/placeOrderInProgress.js +92 -107
  128. package/lib/chevre/service/transaction/returnOrder.js +8 -6
  129. package/lib/chevre/settings.d.ts +2 -0
  130. package/lib/chevre/settings.js +20 -12
  131. package/package.json +3 -3
  132. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  133. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
  134. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.d.ts +0 -6
  135. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.js +0 -65
@@ -1,5 +1,4 @@
1
1
  // tslint:disable:no-console
2
- import * as moment from 'moment';
3
2
  import * as mongoose from 'mongoose';
4
3
 
5
4
  import { chevre } from '../../../lib/index';
@@ -11,47 +10,27 @@ async function main() {
11
10
 
12
11
  const eventRepo = new chevre.repository.Event(mongoose.connection);
13
12
 
14
- const events = await eventRepo.search({
15
- limit: 100,
16
- page: 1,
17
- sort: { startDate: 1 },
18
- typeOf: chevre.factory.eventType.ScreeningEvent,
19
- project: { id: { $eq: PROJECT_ID } },
20
- offers: {
21
- seller: {
22
- makesOffer: {
23
- $elemMatch: {
24
- 'availableAtOrFrom.id': { $eq: '5h3gs22mu9j3ok7o63uog9o9i3' },
25
- availabilityEnds: {
26
- $gte: moment('2022-11-18T02:20:00.000Z')
27
- .toDate(),
28
- $lte: moment('2022-11-18T02:20:00.000Z')
29
- .toDate()
30
- },
31
- availabilityStarts: {
32
- $gte: moment('2022-11-15T15:00:00.000Z')
33
- .toDate(),
34
- $lte: moment('2022-11-15T15:00:00.000Z')
35
- .toDate()
36
- },
37
- validFrom: {
38
- $gte: moment('2022-11-15T15:00:00.000Z')
39
- .toDate(),
40
- $lte: moment('2022-11-15T15:00:00.000Z')
41
- .toDate()
42
- },
43
- validThrough: {
44
- $gte: moment('2022-11-18T02:20:00.000Z')
45
- .toDate(),
46
- $lte: moment('2022-11-18T02:20:00.000Z')
47
- .toDate()
48
- }
49
- }
50
- }
51
- }
13
+ const event = await eventRepo.findById(
14
+ { id: 'al6aff83y' },
15
+ {
16
+ name: 1
17
+ }
18
+ );
19
+ console.log('event found', event);
20
+
21
+ const events = await eventRepo.search(
22
+ {
23
+ limit: 100,
24
+ page: 1,
25
+ sort: { startDate: 1 },
26
+ typeOf: chevre.factory.eventType.ScreeningEvent,
27
+ project: { id: { $eq: PROJECT_ID } },
28
+ id: { $in: ['al6aff83y'] }
52
29
  },
53
- id: { $in: ['al6aff83y'] }
54
- });
30
+ {
31
+ name: 1
32
+ }
33
+ );
55
34
  console.log(events);
56
35
  console.log(events.length);
57
36
  }
@@ -0,0 +1,27 @@
1
+ // tslint:disable:no-console
2
+ // import * as redis from 'redis';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
9
+
10
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
+
12
+ const offers = await offerRepo.findOffersByOfferCatalogId({
13
+ ids: ['al96nqj7z', 'xxx', '1001'],
14
+ // ids: ['xx', 'xxx'],
15
+ offerCatalog: {
16
+ id: '0001'
17
+ // id: 'xxx'
18
+ },
19
+ sort: true
20
+ });
21
+ console.log(offers.map((o) => o.id));
22
+ console.log(offers.length);
23
+ }
24
+
25
+ main()
26
+ .then(console.log)
27
+ .catch(console.error);
@@ -0,0 +1,38 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
9
+
10
+ const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
11
+ const transactionId = '63ce4d501c45c2000bdb2f9d';
12
+ let update = {
13
+ $set: { 'object.modifiedTime': new Date() }
14
+ };
15
+
16
+ let now = moment();
17
+ await transactionRepo.findByIdAndUpdate({
18
+ id: transactionId,
19
+ update
20
+ });
21
+ console.log(moment()
22
+ .diff(now));
23
+
24
+ update = {
25
+ $set: { 'object.modifiedTime': new Date() }
26
+ };
27
+ now = moment();
28
+ // await transactionRepo.updateById({
29
+ // id: transactionId,
30
+ // update
31
+ // });
32
+ console.log(moment()
33
+ .diff(now));
34
+ }
35
+
36
+ main()
37
+ .then()
38
+ .catch(console.error);
@@ -0,0 +1,2 @@
1
+ import * as factory from '../factory';
2
+ export declare type IMinimizedIndividualEvent<T extends factory.eventType.ScreeningEvent | factory.eventType.Event> = T extends factory.eventType.ScreeningEvent ? Pick<factory.event.IEvent<T>, 'project' | 'id' | 'typeOf' | 'additionalProperty' | 'name' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'startDate' | 'superEvent' | 'offers' | 'coaInfo' | 'identifier'> : T extends factory.eventType.Event ? Pick<factory.event.IEvent<T>, 'project' | 'id' | 'typeOf' | 'additionalProperty' | 'name' | 'doorTime' | 'endDate' | 'eventStatus' | 'location' | 'startDate' | 'offers'> : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,6 +7,23 @@ export interface IUseActionCountByOffer {
7
7
  _id: string[];
8
8
  useActionCount?: number;
9
9
  }
10
+ interface IAggregationByStatus {
11
+ actionCount: number;
12
+ avgDuration: number;
13
+ maxDuration: number;
14
+ minDuration: number;
15
+ percentilesDuration: {
16
+ name: string;
17
+ value: number;
18
+ }[];
19
+ }
20
+ interface IStatus {
21
+ status: factory.actionStatusType;
22
+ aggregation: IAggregationByStatus;
23
+ }
24
+ interface IAggregateAction {
25
+ statuses: IStatus[];
26
+ }
10
27
  export { modelName };
11
28
  /**
12
29
  * アクションリポジトリ
@@ -18,7 +35,7 @@ export declare class MongoRepository {
18
35
  /**
19
36
  * アクション検索
20
37
  */
21
- search<T extends factory.actionType>(params: factory.action.ISearchConditions, projection?: any): Promise<IAction<T>[]>;
38
+ search<T extends factory.actionType>(params: factory.action.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<IAction<T>[]>;
22
39
  /**
23
40
  * アクション開始
24
41
  */
@@ -107,4 +124,63 @@ export declare class MongoRepository {
107
124
  deleteEndDatePassedCertainPeriod(params: {
108
125
  $lt: Date;
109
126
  }): Promise<void>;
127
+ aggregateAuthorizeEventServiceOfferAction(params: {
128
+ project?: {
129
+ id?: {
130
+ $ne?: string;
131
+ };
132
+ };
133
+ startFrom: Date;
134
+ startThrough: Date;
135
+ typeOf: factory.actionType;
136
+ }): Promise<IAggregateAction>;
137
+ aggregateAuthorizePaymentAction(params: {
138
+ project?: {
139
+ id?: {
140
+ $ne?: string;
141
+ };
142
+ };
143
+ startFrom: Date;
144
+ startThrough: Date;
145
+ typeOf: factory.actionType;
146
+ }): Promise<IAggregateAction>;
147
+ aggregateAuthorizeOrderAction(params: {
148
+ project?: {
149
+ id?: {
150
+ $ne?: string;
151
+ };
152
+ };
153
+ startFrom: Date;
154
+ startThrough: Date;
155
+ typeOf: factory.actionType;
156
+ }): Promise<IAggregateAction>;
157
+ aggregateUseAction(params: {
158
+ project?: {
159
+ id?: {
160
+ $ne?: string;
161
+ };
162
+ };
163
+ startFrom: Date;
164
+ startThrough: Date;
165
+ typeOf: factory.actionType;
166
+ }): Promise<IAggregateAction>;
167
+ aggregateCheckMovieTicketAction(params: {
168
+ project?: {
169
+ id?: {
170
+ $ne?: string;
171
+ };
172
+ };
173
+ startFrom: Date;
174
+ startThrough: Date;
175
+ }): Promise<IAggregateAction>;
176
+ aggregatePayMovieTicketAction(params: {
177
+ project?: {
178
+ id?: {
179
+ $ne?: string;
180
+ };
181
+ };
182
+ startFrom: Date;
183
+ startThrough: Date;
184
+ }): Promise<IAggregateAction>;
185
+ private agggregateByStatus;
110
186
  }
@@ -386,16 +386,28 @@ class MongoRepository {
386
386
  /**
387
387
  * アクション検索
388
388
  */
389
- search(params, projection) {
389
+ search(params, inclusion, exclusion) {
390
390
  return __awaiter(this, void 0, void 0, function* () {
391
391
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
392
- const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, (projection !== undefined && projection !== null)
393
- ? projection
394
- : {
392
+ let projection = {};
393
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
394
+ inclusion.forEach((field) => {
395
+ projection[field] = 1;
396
+ });
397
+ }
398
+ else {
399
+ projection = {
395
400
  __v: 0,
396
401
  createdAt: 0,
397
402
  updatedAt: 0
398
- });
403
+ };
404
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
405
+ exclusion.forEach((field) => {
406
+ projection[field] = 0;
407
+ });
408
+ }
409
+ }
410
+ const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
399
411
  if (typeof params.limit === 'number') {
400
412
  const page = (typeof params.page === 'number') ? params.page : 1;
401
413
  query.limit(params.limit)
@@ -507,7 +519,7 @@ class MongoRepository {
507
519
  project: { id: { $eq: params.project.id } },
508
520
  typeOf: { $eq: factory.actionType.PayAction },
509
521
  object: { paymentMethod: { paymentMethodId: { $eq: params.paymentMethodId } } }
510
- });
522
+ }, [], []);
511
523
  return payActions.shift();
512
524
  });
513
525
  }
@@ -677,5 +689,236 @@ class MongoRepository {
677
689
  .exec();
678
690
  });
679
691
  }
692
+ aggregateAuthorizeEventServiceOfferAction(params) {
693
+ return __awaiter(this, void 0, void 0, function* () {
694
+ const statuses = yield Promise.all([
695
+ factory.actionStatusType.CompletedActionStatus,
696
+ factory.actionStatusType.CanceledActionStatus,
697
+ factory.actionStatusType.FailedActionStatus
698
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
699
+ var _a, _b;
700
+ const matchConditions = Object.assign({ startDate: {
701
+ $gte: params.startFrom,
702
+ $lte: params.startThrough
703
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
704
+ $exists: true,
705
+ $eq: factory.action.authorize.offer.seatReservation.ObjectType.SeatReservation
706
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
707
+ ? { 'project.id': { $ne: params.project.id.$ne } }
708
+ : undefined);
709
+ return this.agggregateByStatus({ matchConditions, actionStatus });
710
+ })));
711
+ return { statuses };
712
+ });
713
+ }
714
+ aggregateAuthorizePaymentAction(params) {
715
+ return __awaiter(this, void 0, void 0, function* () {
716
+ const statuses = yield Promise.all([
717
+ factory.actionStatusType.CompletedActionStatus,
718
+ factory.actionStatusType.CanceledActionStatus,
719
+ factory.actionStatusType.FailedActionStatus
720
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
721
+ var _a, _b;
722
+ const matchConditions = Object.assign({ startDate: {
723
+ $gte: params.startFrom,
724
+ $lte: params.startThrough
725
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
726
+ $exists: true,
727
+ $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment
728
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
729
+ ? { 'project.id': { $ne: params.project.id.$ne } }
730
+ : undefined);
731
+ return this.agggregateByStatus({ matchConditions, actionStatus });
732
+ })));
733
+ return { statuses };
734
+ });
735
+ }
736
+ aggregateAuthorizeOrderAction(params) {
737
+ return __awaiter(this, void 0, void 0, function* () {
738
+ const statuses = yield Promise.all([
739
+ factory.actionStatusType.CompletedActionStatus,
740
+ factory.actionStatusType.CanceledActionStatus,
741
+ factory.actionStatusType.FailedActionStatus
742
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
743
+ var _a, _b;
744
+ const matchConditions = Object.assign({ startDate: {
745
+ $gte: params.startFrom,
746
+ $lte: params.startThrough
747
+ }, typeOf: { $eq: params.typeOf }, actionStatus: { $eq: actionStatus }, 'object.typeOf': {
748
+ $exists: true,
749
+ $eq: factory.order.OrderType.Order
750
+ } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
751
+ ? { 'project.id': { $ne: params.project.id.$ne } }
752
+ : undefined);
753
+ return this.agggregateByStatus({ matchConditions, actionStatus });
754
+ })));
755
+ return { statuses };
756
+ });
757
+ }
758
+ aggregateUseAction(params) {
759
+ return __awaiter(this, void 0, void 0, function* () {
760
+ const statuses = yield Promise.all([
761
+ factory.actionStatusType.CompletedActionStatus,
762
+ factory.actionStatusType.CanceledActionStatus,
763
+ factory.actionStatusType.FailedActionStatus
764
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
765
+ var _a, _b;
766
+ const matchConditions = Object.assign({ startDate: {
767
+ $gte: params.startFrom,
768
+ $lte: params.startThrough
769
+ }, 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')
770
+ ? { 'project.id': { $ne: params.project.id.$ne } }
771
+ : undefined);
772
+ return this.agggregateByStatus({ matchConditions, actionStatus });
773
+ })));
774
+ return { statuses };
775
+ });
776
+ }
777
+ aggregateCheckMovieTicketAction(params) {
778
+ return __awaiter(this, void 0, void 0, function* () {
779
+ const statuses = yield Promise.all([
780
+ factory.actionStatusType.CompletedActionStatus,
781
+ factory.actionStatusType.CanceledActionStatus,
782
+ factory.actionStatusType.FailedActionStatus
783
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
784
+ var _a, _b;
785
+ const matchConditions = Object.assign({ startDate: {
786
+ $gte: params.startFrom,
787
+ $lte: params.startThrough
788
+ }, typeOf: { $eq: factory.actionType.CheckAction }, 'object.typeOf': {
789
+ $exists: true,
790
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
791
+ }, 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')
792
+ ? { 'project.id': { $ne: params.project.id.$ne } }
793
+ : undefined);
794
+ return this.agggregateByStatus({ matchConditions, actionStatus });
795
+ })));
796
+ return { statuses };
797
+ });
798
+ }
799
+ aggregatePayMovieTicketAction(params) {
800
+ return __awaiter(this, void 0, void 0, function* () {
801
+ const statuses = yield Promise.all([
802
+ factory.actionStatusType.CompletedActionStatus,
803
+ factory.actionStatusType.CanceledActionStatus,
804
+ factory.actionStatusType.FailedActionStatus
805
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
806
+ var _a, _b;
807
+ const matchConditions = Object.assign({ startDate: {
808
+ $gte: params.startFrom,
809
+ $lte: params.startThrough
810
+ }, typeOf: { $eq: factory.actionType.PayAction }, 'object.typeOf': {
811
+ $exists: true,
812
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
813
+ }, 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')
814
+ ? { 'project.id': { $ne: params.project.id.$ne } }
815
+ : undefined);
816
+ return this.agggregateByStatus({ matchConditions, actionStatus });
817
+ })));
818
+ return { statuses };
819
+ });
820
+ }
821
+ // tslint:disable-next-line:max-func-body-length
822
+ agggregateByStatus(params) {
823
+ return __awaiter(this, void 0, void 0, function* () {
824
+ const aggregations = yield this.actionModel.aggregate([
825
+ { $match: params.matchConditions },
826
+ {
827
+ $project: {
828
+ duration: { $subtract: ['$endDate', '$startDate'] },
829
+ actionStatus: '$actionStatus',
830
+ startDate: '$startDate',
831
+ endDate: '$endDate',
832
+ typeOf: '$typeOf'
833
+ }
834
+ },
835
+ {
836
+ $group: {
837
+ _id: '$typeOf',
838
+ actionCount: { $sum: 1 },
839
+ maxDuration: { $max: '$duration' },
840
+ minDuration: { $min: '$duration' },
841
+ avgDuration: { $avg: '$duration' }
842
+ }
843
+ },
844
+ {
845
+ $project: {
846
+ _id: 0,
847
+ actionCount: '$actionCount',
848
+ avgDuration: '$avgDuration',
849
+ maxDuration: '$maxDuration',
850
+ minDuration: '$minDuration'
851
+ }
852
+ }
853
+ ])
854
+ .exec();
855
+ // tslint:disable-next-line:no-magic-numbers
856
+ const percents = [50, 95, 99];
857
+ if (aggregations.length === 0) {
858
+ return {
859
+ status: params.actionStatus,
860
+ aggregation: {
861
+ actionCount: 0,
862
+ avgDuration: 0,
863
+ maxDuration: 0,
864
+ minDuration: 0,
865
+ percentilesDuration: percents.map((percent) => {
866
+ return {
867
+ name: String(percent),
868
+ value: 0
869
+ };
870
+ })
871
+ }
872
+ };
873
+ }
874
+ const ranks4percentile = percents.map((percentile) => {
875
+ return {
876
+ percentile,
877
+ // tslint:disable-next-line:no-magic-numbers
878
+ rank: Math.floor(aggregations[0].actionCount * percentile / 100)
879
+ };
880
+ });
881
+ const aggregations2 = yield this.actionModel.aggregate([
882
+ {
883
+ $match: params.matchConditions
884
+ },
885
+ {
886
+ $project: {
887
+ duration: { $subtract: ['$endDate', '$startDate'] },
888
+ actionStatus: '$actionStatus',
889
+ startDate: '$startDate',
890
+ endDate: '$endDate',
891
+ typeOf: '$typeOf'
892
+ }
893
+ },
894
+ { $sort: { duration: 1 } },
895
+ {
896
+ $group: {
897
+ _id: '$typeOf',
898
+ durations: { $push: '$duration' }
899
+ }
900
+ },
901
+ {
902
+ $project: {
903
+ _id: 0,
904
+ avgSmallDuration: '$avgSmallDuration',
905
+ avgMediumDuration: '$avgMediumDuration',
906
+ avgLargeDuration: '$avgLargeDuration',
907
+ percentilesDuration: ranks4percentile.map((rank) => {
908
+ return {
909
+ name: String(rank.percentile),
910
+ value: { $arrayElemAt: ['$durations', rank.rank] }
911
+ };
912
+ })
913
+ }
914
+ }
915
+ ])
916
+ .exec();
917
+ return {
918
+ status: params.actionStatus,
919
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
920
+ };
921
+ });
922
+ }
680
923
  }
681
924
  exports.MongoRepository = MongoRepository;
@@ -0,0 +1,38 @@
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
+ AggregatePayMovieTicketAction = "AggregatePayMovieTicketAction",
11
+ AggregatePlaceOrder = "AggregatePlaceOrder",
12
+ AggregateReserve = "AggregateReserve",
13
+ AggregateTask = "AggregateTask",
14
+ AggregateUseAction = "AggregateUseAction"
15
+ }
16
+ export interface IAggregationByClient {
17
+ clientId: string;
18
+ aggregation: any;
19
+ }
20
+ export interface IAggregation {
21
+ typeOf: AggregationType;
22
+ project: {
23
+ id: string;
24
+ typeOf: factory.organizationType.Project;
25
+ };
26
+ aggregateDate: Date;
27
+ aggregateDuration: string;
28
+ aggregateStart: Date;
29
+ aggregationByClient?: IAggregationByClient[];
30
+ }
31
+ /**
32
+ * 集計リポジトリ
33
+ */
34
+ export declare class MongoRepository {
35
+ readonly aggregationModel: typeof Model;
36
+ constructor(connection: Connection);
37
+ saveAggregation(params: IAggregation): Promise<any>;
38
+ }
@@ -0,0 +1,68 @@
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["AggregatePayMovieTicketAction"] = "AggregatePayMovieTicketAction";
34
+ AggregationType["AggregatePlaceOrder"] = "AggregatePlaceOrder";
35
+ AggregationType["AggregateReserve"] = "AggregateReserve";
36
+ AggregationType["AggregateTask"] = "AggregateTask";
37
+ AggregationType["AggregateUseAction"] = "AggregateUseAction";
38
+ })(AggregationType = exports.AggregationType || (exports.AggregationType = {}));
39
+ /**
40
+ * 集計リポジトリ
41
+ */
42
+ class MongoRepository {
43
+ constructor(connection) {
44
+ this.aggregationModel = connection.model(aggregation_1.modelName);
45
+ }
46
+ saveAggregation(params) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const { typeOf, project, aggregateDuration, aggregateStart } = params, setFields = __rest(params, ["typeOf", "project", "aggregateDuration", "aggregateStart"]);
49
+ const doc = yield this.aggregationModel.findOneAndUpdate({
50
+ typeOf: { $eq: params.typeOf },
51
+ 'project.id': { $eq: params.project.id },
52
+ aggregateStart: { $eq: params.aggregateStart },
53
+ aggregateDuration: { $eq: params.aggregateDuration }
54
+ }, {
55
+ $setOnInsert: {
56
+ typeOf: params.typeOf,
57
+ project: params.project,
58
+ aggregateDuration: params.aggregateDuration,
59
+ aggregateStart: params.aggregateStart
60
+ },
61
+ $set: setFields
62
+ }, { upsert: true, new: true })
63
+ .exec();
64
+ return doc.toObject();
65
+ });
66
+ }
67
+ }
68
+ 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
  }