@chevre/domain 20.2.0-alpha.22 → 20.2.0-alpha.24

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.
@@ -13,36 +13,42 @@ async function main() {
13
13
 
14
14
  const aggregationRepo = new chevre.repository.Aggregation(mongoose.connection);
15
15
  const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
16
- const reservationRepo = new chevre.repository.Reservation(mongoose.connection);
17
- const orderRepo = new chevre.repository.Order(mongoose.connection);
16
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
18
17
  const actionRepo = new chevre.repository.Action(mongoose.connection);
18
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
19
19
 
20
- await chevre.service.aggregation.system.aggregatePlaceOrder({
20
+ await aggregationRepo.aggregationModel.deleteMany({
21
+ typeOf: { $in: ['AggregateOrder', 'AggregateReservation'] }
22
+ })
23
+ .exec();
24
+ await chevre.service.aggregation.system.aggregateReserveTransaction({
21
25
  aggregationDays: AGGREGATE_DAYS,
22
- excludedProjectId: EXCLUDED_PROJECT_ID,
23
- clientIds: AGGREGATE_CLIENT_IDS
26
+ excludedProjectId: EXCLUDED_PROJECT_ID
24
27
  })({
25
28
  agregation: aggregationRepo,
26
- transaction: transactionRepo
29
+ assetTransaction: assetTransactionRepo
27
30
  });
28
31
 
29
- await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
32
+ return;
33
+
34
+ await chevre.service.aggregation.system.aggregateTask({
30
35
  aggregationDays: AGGREGATE_DAYS,
31
36
  excludedProjectId: EXCLUDED_PROJECT_ID
32
37
  })({
33
38
  agregation: aggregationRepo,
34
- action: actionRepo
39
+ task: taskRepo
35
40
  });
36
41
 
37
- await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
42
+ await chevre.service.aggregation.system.aggregatePlaceOrder({
38
43
  aggregationDays: AGGREGATE_DAYS,
39
- excludedProjectId: EXCLUDED_PROJECT_ID
44
+ excludedProjectId: EXCLUDED_PROJECT_ID,
45
+ clientIds: AGGREGATE_CLIENT_IDS
40
46
  })({
41
47
  agregation: aggregationRepo,
42
- action: actionRepo
48
+ transaction: transactionRepo
43
49
  });
44
50
 
45
- await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
51
+ await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
46
52
  aggregationDays: AGGREGATE_DAYS,
47
53
  excludedProjectId: EXCLUDED_PROJECT_ID
48
54
  })({
@@ -50,7 +56,7 @@ async function main() {
50
56
  action: actionRepo
51
57
  });
52
58
 
53
- await chevre.service.aggregation.system.aggregateUseAction({
59
+ await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
54
60
  aggregationDays: AGGREGATE_DAYS,
55
61
  excludedProjectId: EXCLUDED_PROJECT_ID
56
62
  })({
@@ -58,20 +64,20 @@ async function main() {
58
64
  action: actionRepo
59
65
  });
60
66
 
61
- await chevre.service.aggregation.system.aggregateOrder({
67
+ await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
62
68
  aggregationDays: AGGREGATE_DAYS,
63
69
  excludedProjectId: EXCLUDED_PROJECT_ID
64
70
  })({
65
71
  agregation: aggregationRepo,
66
- order: orderRepo
72
+ action: actionRepo
67
73
  });
68
74
 
69
- await chevre.service.aggregation.system.aggregateReservation({
75
+ await chevre.service.aggregation.system.aggregateUseAction({
70
76
  aggregationDays: AGGREGATE_DAYS,
71
77
  excludedProjectId: EXCLUDED_PROJECT_ID
72
78
  })({
73
79
  agregation: aggregationRepo,
74
- reservation: reservationRepo
80
+ action: actionRepo
75
81
  });
76
82
  }
77
83
 
@@ -5,8 +5,8 @@ export declare enum AggregationType {
5
5
  AggregateAuthorizeEventServiceOfferAction = "AggregateAuthorizeEventServiceOfferAction",
6
6
  AggregateAuthorizeOrderAction = "AggregateAuthorizeOrderAction",
7
7
  AggregateAuthorizePaymentAction = "AggregateAuthorizePaymentAction",
8
- AggregateOrder = "AggregateOrder",
9
- AggregateReservation = "AggregateReservation",
8
+ AggregateReserve = "AggregateReserve",
9
+ AggregateTask = "AggregateTask",
10
10
  AggregateUseAction = "AggregateUseAction"
11
11
  }
12
12
  export interface IAggregationByClient {
@@ -28,8 +28,8 @@ var AggregationType;
28
28
  AggregationType["AggregateAuthorizeEventServiceOfferAction"] = "AggregateAuthorizeEventServiceOfferAction";
29
29
  AggregationType["AggregateAuthorizeOrderAction"] = "AggregateAuthorizeOrderAction";
30
30
  AggregationType["AggregateAuthorizePaymentAction"] = "AggregateAuthorizePaymentAction";
31
- AggregationType["AggregateOrder"] = "AggregateOrder";
32
- AggregationType["AggregateReservation"] = "AggregateReservation";
31
+ AggregationType["AggregateReserve"] = "AggregateReserve";
32
+ AggregationType["AggregateTask"] = "AggregateTask";
33
33
  AggregationType["AggregateUseAction"] = "AggregateUseAction";
34
34
  })(AggregationType = exports.AggregationType || (exports.AggregationType = {}));
35
35
  /**
@@ -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
+ aggregateReserve(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,147 @@ class MongoRepository {
536
536
  .exec();
537
537
  });
538
538
  }
539
+ aggregateReserve(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: { $subtract: ['$object.reservationFor.startDate', '$startDate'] },
571
+ status: '$status',
572
+ startDate: '$startDate',
573
+ endDate: '$endDate',
574
+ typeOf: '$typeOf',
575
+ reservationCount: {
576
+ $cond: {
577
+ if: { $isArray: '$object.subReservation' },
578
+ then: { $size: '$object.subReservation' },
579
+ else: 0
580
+ }
581
+ }
582
+ }
583
+ },
584
+ {
585
+ $group: {
586
+ _id: '$typeOf',
587
+ transactionCount: { $sum: 1 },
588
+ maxDuration: { $max: '$duration' },
589
+ minDuration: { $min: '$duration' },
590
+ avgDuration: { $avg: '$duration' },
591
+ reservationCount: { $sum: 1 },
592
+ maxGraceTime: { $max: '$graceTime' },
593
+ minGraceTime: { $min: '$graceTime' },
594
+ avgGraceTime: { $avg: '$graceTime' }
595
+ }
596
+ },
597
+ {
598
+ $project: {
599
+ _id: 0,
600
+ transactionCount: '$transactionCount',
601
+ avgDuration: '$avgDuration',
602
+ maxDuration: '$maxDuration',
603
+ minDuration: '$minDuration',
604
+ reservationCount: '$reservationCount',
605
+ avgGraceTime: '$avgGraceTime',
606
+ maxGraceTime: '$maxGraceTime',
607
+ minGraceTime: '$minGraceTime'
608
+ }
609
+ }
610
+ ])
611
+ .exec();
612
+ // tslint:disable-next-line:no-magic-numbers
613
+ const percents = [50, 95, 99];
614
+ if (aggregations.length === 0) {
615
+ return {
616
+ status: transactionStatus,
617
+ aggregation: {
618
+ transactionCount: 0,
619
+ avgDuration: 0,
620
+ maxDuration: 0,
621
+ minDuration: 0,
622
+ percentilesDuration: percents.map((percent) => {
623
+ return {
624
+ name: String(percent),
625
+ value: 0
626
+ };
627
+ }),
628
+ reservationCount: 0,
629
+ avgGraceTime: 0,
630
+ maxGraceTime: 0,
631
+ minGraceTime: 0
632
+ }
633
+ };
634
+ }
635
+ const ranks4percentile = percents.map((percentile) => {
636
+ return {
637
+ percentile,
638
+ // tslint:disable-next-line:no-magic-numbers
639
+ rank: Math.floor(aggregations[0].transactionCount * percentile / 100)
640
+ };
641
+ });
642
+ const aggregations2 = yield this.transactionModel.aggregate([
643
+ {
644
+ $match: matchConditions
645
+ },
646
+ {
647
+ $project: {
648
+ duration: { $subtract: ['$endDate', '$startDate'] },
649
+ status: '$status',
650
+ startDate: '$startDate',
651
+ endDate: '$endDate',
652
+ typeOf: '$typeOf'
653
+ }
654
+ },
655
+ { $sort: { duration: 1 } },
656
+ {
657
+ $group: {
658
+ _id: '$typeOf',
659
+ durations: { $push: '$duration' }
660
+ }
661
+ },
662
+ {
663
+ $project: {
664
+ _id: 0,
665
+ percentilesDuration: ranks4percentile.map((rank) => {
666
+ return {
667
+ name: String(rank.percentile),
668
+ value: { $arrayElemAt: ['$durations', rank.rank] }
669
+ };
670
+ })
671
+ }
672
+ }
673
+ ])
674
+ .exec();
675
+ return {
676
+ status: transactionStatus,
677
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
678
+ };
679
+ });
680
+ }
539
681
  }
540
682
  exports.MongoRepository = MongoRepository;
@@ -76,13 +76,4 @@ export declare class MongoRepository {
76
76
  $in: string[];
77
77
  };
78
78
  }): Promise<(string)[]>;
79
- aggregateOrder(params: factory.order.ISearchConditions): Promise<{
80
- orderCount: number;
81
- acceptedOfferCount: number;
82
- avgAcceptedOfferCount: number;
83
- totalPrice: number;
84
- maxPrice: number;
85
- minPrice: number;
86
- avgPrice: number;
87
- }>;
88
79
  }
@@ -920,54 +920,5 @@ class MongoRepository {
920
920
  return [...new Set(reservationNumbers)];
921
921
  });
922
922
  }
923
- aggregateOrder(params) {
924
- var _a, _b;
925
- return __awaiter(this, void 0, void 0, function* () {
926
- const aggregations = yield this.orderModel.aggregate([
927
- {
928
- $match: {
929
- orderDate: {
930
- $gte: (_a = params.orderDate) === null || _a === void 0 ? void 0 : _a.$gte,
931
- $lte: (_b = params.orderDate) === null || _b === void 0 ? void 0 : _b.$lte
932
- }
933
- }
934
- },
935
- {
936
- $group: {
937
- _id: '$typeOf',
938
- acceptedOfferCount: {
939
- $sum: {
940
- $cond: { if: { $isArray: '$acceptedOffers' }, then: { $size: '$acceptedOffers' }, else: 0 }
941
- }
942
- },
943
- avgAcceptedOfferCount: {
944
- $avg: {
945
- $cond: { if: { $isArray: '$acceptedOffers' }, then: { $size: '$acceptedOffers' }, else: 0 }
946
- }
947
- },
948
- orderCount: { $sum: 1 },
949
- totalPrice: { $sum: '$price' },
950
- maxPrice: { $max: '$price' },
951
- minPrice: { $min: '$price' },
952
- avgPrice: { $avg: '$price' }
953
- }
954
- },
955
- {
956
- $project: {
957
- _id: 0,
958
- acceptedOfferCount: '$acceptedOfferCount',
959
- avgAcceptedOfferCount: '$avgAcceptedOfferCount',
960
- orderCount: '$orderCount',
961
- totalPrice: '$totalPrice',
962
- maxPrice: '$maxPrice',
963
- minPrice: '$minPrice',
964
- avgPrice: '$avgPrice'
965
- }
966
- }
967
- ])
968
- .exec();
969
- return aggregations[0];
970
- });
971
- }
972
923
  }
973
924
  exports.MongoRepository = MongoRepository;
@@ -1,5 +1,22 @@
1
1
  import { Connection, Model } from 'mongoose';
2
2
  import * as factory from '../factory';
3
+ interface IAggregationByStatus {
4
+ taskCount: number;
5
+ avgLatency: number;
6
+ maxLatency: number;
7
+ minLatency: number;
8
+ percentilesLatency: {
9
+ name: string;
10
+ value: number;
11
+ }[];
12
+ }
13
+ interface IStatus {
14
+ status: factory.taskStatus;
15
+ aggregation: IAggregationByStatus;
16
+ }
17
+ export interface IAggregateTask {
18
+ statuses: IStatus[];
19
+ }
3
20
  /**
4
21
  * タスクリポジトリ
5
22
  */
@@ -39,4 +56,15 @@ export declare class MongoRepository {
39
56
  id: string;
40
57
  };
41
58
  }): Promise<void>;
59
+ aggregateTask(params: {
60
+ project?: {
61
+ id?: {
62
+ $ne?: string;
63
+ };
64
+ };
65
+ runsFrom: Date;
66
+ runsThrough: Date;
67
+ }): Promise<IAggregateTask>;
68
+ private agggregateByStatus;
42
69
  }
70
+ export {};
@@ -307,5 +307,124 @@ class MongoRepository {
307
307
  .exec();
308
308
  });
309
309
  }
310
+ aggregateTask(params) {
311
+ return __awaiter(this, void 0, void 0, function* () {
312
+ const statuses = yield Promise.all([
313
+ factory.taskStatus.Executed,
314
+ factory.taskStatus.Aborted
315
+ ].map((taskStatus) => __awaiter(this, void 0, void 0, function* () {
316
+ var _a, _b;
317
+ const matchConditions = Object.assign({ runsAt: {
318
+ $gte: params.runsFrom,
319
+ $lte: params.runsThrough
320
+ }, status: { $eq: taskStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
321
+ ? { 'project.id': { $ne: params.project.id.$ne } }
322
+ : undefined);
323
+ return this.agggregateByStatus({ matchConditions, status: taskStatus });
324
+ })));
325
+ return { statuses };
326
+ });
327
+ }
328
+ // tslint:disable-next-line:max-func-body-length
329
+ agggregateByStatus(params) {
330
+ return __awaiter(this, void 0, void 0, function* () {
331
+ const matchConditions = params.matchConditions;
332
+ const taskStatus = params.status;
333
+ const aggregations = yield this.taskModel.aggregate([
334
+ {
335
+ $match: matchConditions
336
+ },
337
+ {
338
+ $project: {
339
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
340
+ status: '$status',
341
+ runsAt: '$runsAt',
342
+ lastTriedAt: '$lastTriedAt'
343
+ }
344
+ },
345
+ {
346
+ $group: {
347
+ _id: '$status',
348
+ taskCount: { $sum: 1 },
349
+ maxLatency: { $max: '$latency' },
350
+ minLatency: { $min: '$latency' },
351
+ avgLatency: { $avg: '$latency' }
352
+ }
353
+ },
354
+ {
355
+ $project: {
356
+ _id: 0,
357
+ taskCount: '$taskCount',
358
+ avgLatency: '$avgLatency',
359
+ maxLatency: '$maxLatency',
360
+ minLatency: '$minLatency'
361
+ }
362
+ }
363
+ ])
364
+ .exec();
365
+ // tslint:disable-next-line:no-magic-numbers
366
+ const percents = [50, 95, 99];
367
+ if (aggregations.length === 0) {
368
+ return {
369
+ status: taskStatus,
370
+ aggregation: {
371
+ taskCount: 0,
372
+ avgLatency: 0,
373
+ maxLatency: 0,
374
+ minLatency: 0,
375
+ percentilesLatency: percents.map((percent) => {
376
+ return {
377
+ name: String(percent),
378
+ value: 0
379
+ };
380
+ })
381
+ }
382
+ };
383
+ }
384
+ const ranks4percentile = percents.map((percentile) => {
385
+ return {
386
+ percentile,
387
+ // tslint:disable-next-line:no-magic-numbers
388
+ rank: Math.floor(aggregations[0].taskCount * percentile / 100)
389
+ };
390
+ });
391
+ const aggregations2 = yield this.taskModel.aggregate([
392
+ {
393
+ $match: matchConditions
394
+ },
395
+ {
396
+ $project: {
397
+ latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
398
+ status: '$status',
399
+ runsAt: '$runsAt',
400
+ lastTriedAt: '$lastTriedAt'
401
+ }
402
+ },
403
+ { $sort: { latency: 1 } },
404
+ {
405
+ $group: {
406
+ _id: '$status',
407
+ latencies: { $push: '$latency' }
408
+ }
409
+ },
410
+ {
411
+ $project: {
412
+ _id: 0,
413
+ percentilesLatency: ranks4percentile.map((rank) => {
414
+ return {
415
+ name: String(rank.percentile),
416
+ value: { $arrayElemAt: ['$latencies', rank.rank] }
417
+ };
418
+ })
419
+ }
420
+ }
421
+ ])
422
+ .exec();
423
+ return {
424
+ status: taskStatus,
425
+ aggregation: Object.assign(Object.assign({}, aggregations[0]), aggregations2[0])
426
+ };
427
+ });
428
+ }
310
429
  }
311
430
  exports.MongoRepository = MongoRepository;
@@ -11,6 +11,12 @@ interface IAggregationByStatus {
11
11
  name: string;
12
12
  value: number;
13
13
  }[];
14
+ acceptedOfferCount: number;
15
+ avgAcceptedOfferCount: number;
16
+ totalPrice: number;
17
+ maxPrice: number;
18
+ minPrice: number;
19
+ avgPrice: number;
14
20
  }
15
21
  interface IStatus {
16
22
  status: factory.transactionStatusType;
@@ -603,9 +603,9 @@ class MongoRepository {
603
603
  aggregatePlaceOrder(params) {
604
604
  return __awaiter(this, void 0, void 0, function* () {
605
605
  const statuses = yield Promise.all([
606
+ factory.transactionStatusType.Confirmed,
606
607
  factory.transactionStatusType.Canceled,
607
- factory.transactionStatusType.Expired,
608
- factory.transactionStatusType.Confirmed
608
+ factory.transactionStatusType.Expired
609
609
  ].map((transactionStatus) => __awaiter(this, void 0, void 0, function* () {
610
610
  var _a, _b;
611
611
  const matchConditions = Object.assign(Object.assign({ startDate: {
@@ -680,7 +680,13 @@ class MongoRepository {
680
680
  name: String(percent),
681
681
  value: 0
682
682
  };
683
- })
683
+ }),
684
+ acceptedOfferCount: 0,
685
+ avgAcceptedOfferCount: 0,
686
+ totalPrice: 0,
687
+ maxPrice: 0,
688
+ minPrice: 0,
689
+ avgPrice: 0
684
690
  }
685
691
  };
686
692
  }
@@ -701,28 +707,52 @@ class MongoRepository {
701
707
  status: '$status',
702
708
  startDate: '$startDate',
703
709
  endDate: '$endDate',
704
- typeOf: '$typeOf'
710
+ typeOf: '$typeOf',
711
+ // result: '$result',
712
+ acceptedOffers: {
713
+ $cond: {
714
+ if: { $isArray: '$result.order.acceptedOffers' },
715
+ then: '$result.order.acceptedOffers',
716
+ else: []
717
+ }
718
+ },
719
+ price: {
720
+ $cond: {
721
+ if: { $isNumber: '$result.order.price' },
722
+ then: '$result.order.price',
723
+ else: 0
724
+ }
725
+ }
705
726
  }
706
727
  },
707
728
  { $sort: { duration: 1 } },
708
729
  {
709
730
  $group: {
710
731
  _id: '$typeOf',
711
- durations: { $push: '$duration' }
732
+ durations: { $push: '$duration' },
733
+ acceptedOfferCount: { $sum: { $size: '$acceptedOffers' } },
734
+ avgAcceptedOfferCount: { $avg: { $size: '$acceptedOffers' } },
735
+ totalPrice: { $sum: '$price' },
736
+ maxPrice: { $max: '$price' },
737
+ minPrice: { $min: '$price' },
738
+ avgPrice: { $avg: '$price' }
712
739
  }
713
740
  },
714
741
  {
715
742
  $project: {
716
743
  _id: 0,
717
- avgSmallDuration: '$avgSmallDuration',
718
- avgMediumDuration: '$avgMediumDuration',
719
- avgLargeDuration: '$avgLargeDuration',
720
744
  percentilesDuration: ranks4percentile.map((rank) => {
721
745
  return {
722
746
  name: String(rank.percentile),
723
747
  value: { $arrayElemAt: ['$durations', rank.rank] }
724
748
  };
725
- })
749
+ }),
750
+ acceptedOfferCount: '$acceptedOfferCount',
751
+ avgAcceptedOfferCount: '$avgAcceptedOfferCount',
752
+ totalPrice: '$totalPrice',
753
+ maxPrice: '$maxPrice',
754
+ minPrice: '$minPrice',
755
+ avgPrice: '$avgPrice'
726
756
  }
727
757
  }
728
758
  ])
@@ -1,7 +1,7 @@
1
1
  import { MongoRepository as ActionRepo } from '../../repo/action';
2
2
  import { MongoRepository as AggregationRepo } from '../../repo/aggregation';
3
- import { MongoRepository as OrderRepo } from '../../repo/order';
4
- import { MongoRepository as ReservationRepo } from '../../repo/reservation';
3
+ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
4
+ import { MongoRepository as TasKRepo } from '../../repo/task';
5
5
  import { MongoRepository as TransactionRepo } from '../../repo/transaction';
6
6
  /**
7
7
  * 注文取引集計
@@ -52,23 +52,20 @@ declare function aggregateUseAction(params: {
52
52
  action: ActionRepo;
53
53
  }) => Promise<void>;
54
54
  /**
55
- * 注文集計
55
+ * 予約集計
56
56
  */
57
- declare function aggregateOrder(params: {
57
+ declare function aggregateReserveTransaction(params: {
58
58
  aggregationDays: number;
59
59
  excludedProjectId?: string;
60
60
  }): (repos: {
61
61
  agregation: AggregationRepo;
62
- order: OrderRepo;
62
+ assetTransaction: AssetTransactionRepo;
63
63
  }) => Promise<void>;
64
- /**
65
- * 予約集計
66
- */
67
- declare function aggregateReservation(params: {
64
+ declare function aggregateTask(params: {
68
65
  aggregationDays: number;
69
66
  excludedProjectId?: string;
70
67
  }): (repos: {
71
68
  agregation: AggregationRepo;
72
- reservation: ReservationRepo;
69
+ task: TasKRepo;
73
70
  }) => Promise<void>;
74
- export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateOrder, aggregatePlaceOrder, aggregateReservation, aggregateUseAction };
71
+ export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.aggregateUseAction = exports.aggregateReservation = exports.aggregatePlaceOrder = exports.aggregateOrder = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
12
+ exports.aggregateUseAction = exports.aggregateTask = exports.aggregateReserveTransaction = exports.aggregatePlaceOrder = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
13
13
  const createDebug = require("debug");
14
14
  const moment = require("moment-timezone");
15
15
  const factory = require("../../factory");
@@ -20,7 +20,7 @@ const debug = createDebug('chevre-domain:service:aggregation:system');
20
20
  */
21
21
  function aggregatePlaceOrder(params) {
22
22
  return (repos) => __awaiter(this, void 0, void 0, function* () {
23
- var _a;
23
+ var _a, _b;
24
24
  const aggregateDate = new Date();
25
25
  const aggregateDuration = moment.duration(1, 'days')
26
26
  .toISOString();
@@ -43,19 +43,21 @@ function aggregatePlaceOrder(params) {
43
43
  startThrough,
44
44
  typeOf: factory.transactionType.PlaceOrder
45
45
  });
46
- debug('aggregatePlaceOrder:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
46
+ debug('aggregatePlaceOrder:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, startFrom);
47
47
  const aggregateResultsByClientId = [];
48
48
  if (Array.isArray(params.clientIds)) {
49
49
  for (const clientId of params.clientIds) {
50
+ const aggregateResultByClientId = yield repos.transaction.aggregatePlaceOrder({
51
+ project: { id: { $ne: params.excludedProjectId } },
52
+ startFrom,
53
+ startThrough,
54
+ typeOf: factory.transactionType.PlaceOrder,
55
+ clientId
56
+ });
57
+ debug('aggregateResultByClientId', aggregateResultByClientId, (_b = aggregateResultByClientId.statuses[0]) === null || _b === void 0 ? void 0 : _b.aggregation, clientId, startFrom);
50
58
  aggregateResultsByClientId.push({
51
59
  clientId,
52
- aggregation: yield repos.transaction.aggregatePlaceOrder({
53
- project: { id: { $ne: params.excludedProjectId } },
54
- startFrom,
55
- startThrough,
56
- typeOf: factory.transactionType.PlaceOrder,
57
- clientId
58
- })
60
+ aggregation: aggregateResultByClientId
59
61
  });
60
62
  }
61
63
  }
@@ -198,69 +200,66 @@ function aggregateUseAction(params) {
198
200
  }
199
201
  exports.aggregateUseAction = aggregateUseAction;
200
202
  /**
201
- * 注文集計
203
+ * 予約集計
202
204
  */
203
- function aggregateOrder(params) {
205
+ function aggregateReserveTransaction(params) {
204
206
  return (repos) => __awaiter(this, void 0, void 0, function* () {
207
+ var _a;
205
208
  const aggregateDate = new Date();
206
209
  const aggregateDuration = moment.duration(1, 'days')
207
210
  .toISOString();
208
211
  let i = -1;
209
212
  while (i < params.aggregationDays) {
210
213
  i += 1;
211
- const orderDateFrom = moment()
214
+ const startFrom = moment()
212
215
  // .tz('Asia/Tokyo')
213
216
  .add(-i, 'days')
214
217
  .startOf('day')
215
218
  .toDate();
216
- const orderDateThrough = moment()
219
+ const startThrough = moment()
217
220
  // .tz('Asia/Tokyo')
218
221
  .add(-i, 'days')
219
222
  .endOf('day')
220
223
  .toDate();
221
- const aggregateResult = yield repos.order.aggregateOrder({
222
- orderDate: {
223
- $gte: orderDateFrom,
224
- $lte: orderDateThrough
225
- }
224
+ const aggregateResult = yield repos.assetTransaction.aggregateReserve({
225
+ project: { id: { $ne: params.excludedProjectId } },
226
+ startFrom,
227
+ startThrough,
228
+ typeOf: factory.assetTransactionType.Reserve
226
229
  });
227
- debug('aggregateOrder:result', aggregateResult);
228
- yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: orderDateFrom, aggregateDate }, aggregateResult));
230
+ debug('aggregateReserveTransaction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, startFrom);
231
+ yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateReserve, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
229
232
  }
230
233
  });
231
234
  }
232
- exports.aggregateOrder = aggregateOrder;
233
- /**
234
- * 予約集計
235
- */
236
- function aggregateReservation(params) {
235
+ exports.aggregateReserveTransaction = aggregateReserveTransaction;
236
+ function aggregateTask(params) {
237
237
  return (repos) => __awaiter(this, void 0, void 0, function* () {
238
+ var _a;
238
239
  const aggregateDate = new Date();
239
240
  const aggregateDuration = moment.duration(1, 'days')
240
241
  .toISOString();
241
242
  let i = -1;
242
243
  while (i < params.aggregationDays) {
243
244
  i += 1;
244
- const bookingFrom = moment()
245
+ const runsFrom = moment()
245
246
  // .tz('Asia/Tokyo')
246
247
  .add(-i, 'days')
247
248
  .startOf('day')
248
249
  .toDate();
249
- const bookingThrough = moment()
250
+ const runsThrough = moment()
250
251
  // .tz('Asia/Tokyo')
251
252
  .add(-i, 'days')
252
253
  .endOf('day')
253
254
  .toDate();
254
- // i日前の予約検索
255
- const reservationCount = yield repos.reservation.count({
256
- typeOf: factory.reservationType.EventReservation,
257
- reservationStatus: { $eq: factory.reservationStatusType.ReservationConfirmed },
258
- bookingFrom,
259
- bookingThrough
255
+ const aggregateResult = yield repos.task.aggregateTask({
256
+ project: { id: { $ne: params.excludedProjectId } },
257
+ runsFrom,
258
+ runsThrough
260
259
  });
261
- const aggregateResult = { reservationCount };
262
- yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateReservation, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: bookingFrom, aggregateDate }, aggregateResult));
260
+ debug('aggregateTask:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, runsFrom);
261
+ yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateTask, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: runsFrom, aggregateDate }, aggregateResult));
263
262
  }
264
263
  });
265
264
  }
266
- exports.aggregateReservation = aggregateReservation;
265
+ exports.aggregateTask = aggregateTask;
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.22"
123
+ "version": "20.2.0-alpha.24"
124
124
  }