@chevre/domain 21.2.0-alpha.34 → 21.2.0-alpha.36

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.
@@ -6,8 +6,10 @@ import { chevre } from '../../../../lib/index';
6
6
  const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
7
7
  const AGGREGATE_DAYS = Number(process.env.AGGREGATE_DAYS);
8
8
  const AGGREGATE_CLIENT_IDS = (typeof process.env.AGGREGATE_CLIENT_IDS === 'string') ? process.env.AGGREGATE_CLIENT_IDS.split(' ') : [];
9
+ const ONE_DAY_IN_HOURS = 24;
9
10
  console.log('AGGREGATE_CLIENT_IDS:', AGGREGATE_CLIENT_IDS);
10
11
 
12
+ // tslint:disable-next-line:max-func-body-length
11
13
  async function main() {
12
14
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
15
 
@@ -18,94 +20,119 @@ async function main() {
18
20
  const actionRepo = new chevre.repository.Action(mongoose.connection);
19
21
  const taskRepo = new chevre.repository.Task(mongoose.connection);
20
22
 
21
- await chevre.service.aggregation.system.aggregatePayMovieTicketAction({
22
- aggregationDays: AGGREGATE_DAYS,
23
- excludedProjectId: EXCLUDED_PROJECT_ID
23
+ let result: { aggregationCount: number; aggregateDuration: string };
24
+
25
+ result = await chevre.service.aggregation.system.aggregatePlaceOrder({
26
+ aggregateDurationUnit: 'hours',
27
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
28
+ excludedProjectId: EXCLUDED_PROJECT_ID,
29
+ clientIds: AGGREGATE_CLIENT_IDS
24
30
  })({
25
31
  agregation: aggregationRepo,
26
- action: actionRepo
32
+ transaction: transactionRepo
27
33
  });
34
+ console.log('aggregatePlaceOrder processed.', result);
35
+ // return;
28
36
 
29
- await chevre.service.aggregation.system.aggregatePayTransaction({
30
- aggregationDays: AGGREGATE_DAYS,
37
+ result = await chevre.service.aggregation.system.aggregateTask({
38
+ aggregateDurationUnit: 'hours',
39
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
31
40
  excludedProjectId: EXCLUDED_PROJECT_ID
32
41
  })({
33
42
  agregation: aggregationRepo,
34
- assetTransaction: assetTransactionRepo
43
+ task: taskRepo
35
44
  });
45
+ console.log('aggregateTask processed.', result);
36
46
 
37
- await chevre.service.aggregation.system.aggregateEvent({
38
- aggregationDays: AGGREGATE_DAYS,
47
+ result = await chevre.service.aggregation.system.aggregatePayMovieTicketAction({
48
+ aggregateDurationUnit: 'hours',
49
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
39
50
  excludedProjectId: EXCLUDED_PROJECT_ID
40
51
  })({
41
52
  agregation: aggregationRepo,
42
- event: eventRepo
53
+ action: actionRepo
43
54
  });
55
+ console.log('aggregatePayMovieTicketAction processed.', result);
44
56
 
45
- await chevre.service.aggregation.system.aggregateTask({
46
- aggregationDays: AGGREGATE_DAYS,
57
+ result = await chevre.service.aggregation.system.aggregatePayTransaction({
58
+ aggregateDurationUnit: 'hours',
59
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
47
60
  excludedProjectId: EXCLUDED_PROJECT_ID
48
61
  })({
49
62
  agregation: aggregationRepo,
50
- task: taskRepo
63
+ assetTransaction: assetTransactionRepo
51
64
  });
65
+ console.log('aggregatePayTransaction processed.', result);
52
66
 
53
- await chevre.service.aggregation.system.aggregateReserveTransaction({
54
- aggregationDays: AGGREGATE_DAYS,
67
+ result = await chevre.service.aggregation.system.aggregateEvent({
68
+ aggregateDurationUnit: 'hours',
69
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
55
70
  excludedProjectId: EXCLUDED_PROJECT_ID
56
71
  })({
57
72
  agregation: aggregationRepo,
58
- assetTransaction: assetTransactionRepo
73
+ event: eventRepo
59
74
  });
75
+ console.log('aggregateEvent processed.', result);
60
76
 
61
- await chevre.service.aggregation.system.aggregatePlaceOrder({
62
- aggregationDays: AGGREGATE_DAYS,
63
- excludedProjectId: EXCLUDED_PROJECT_ID,
64
- clientIds: AGGREGATE_CLIENT_IDS
77
+ result = await chevre.service.aggregation.system.aggregateReserveTransaction({
78
+ aggregateDurationUnit: 'hours',
79
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
80
+ excludedProjectId: EXCLUDED_PROJECT_ID
65
81
  })({
66
82
  agregation: aggregationRepo,
67
- transaction: transactionRepo
83
+ assetTransaction: assetTransactionRepo
68
84
  });
85
+ console.log('aggregateReserveTransaction processed.', result);
69
86
 
70
- await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
71
- aggregationDays: AGGREGATE_DAYS,
87
+ result = await chevre.service.aggregation.system.aggregateAuthorizeOrderAction({
88
+ aggregateDurationUnit: 'hours',
89
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
72
90
  excludedProjectId: EXCLUDED_PROJECT_ID
73
91
  })({
74
92
  agregation: aggregationRepo,
75
93
  action: actionRepo
76
94
  });
95
+ console.log('aggregateAuthorizeOrderAction processed.', result);
77
96
 
78
- await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
79
- aggregationDays: AGGREGATE_DAYS,
97
+ result = await chevre.service.aggregation.system.aggregateAuthorizeEventServiceOfferAction({
98
+ aggregateDurationUnit: 'hours',
99
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
80
100
  excludedProjectId: EXCLUDED_PROJECT_ID
81
101
  })({
82
102
  agregation: aggregationRepo,
83
103
  action: actionRepo
84
104
  });
105
+ console.log('aggregateAuthorizeEventServiceOfferAction processed.', result);
85
106
 
86
- await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
87
- aggregationDays: AGGREGATE_DAYS,
107
+ result = await chevre.service.aggregation.system.aggregateAuthorizePaymentAction({
108
+ aggregateDurationUnit: 'hours',
109
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
88
110
  excludedProjectId: EXCLUDED_PROJECT_ID
89
111
  })({
90
112
  agregation: aggregationRepo,
91
113
  action: actionRepo
92
114
  });
115
+ console.log('aggregateAuthorizePaymentAction processed.', result);
93
116
 
94
- await chevre.service.aggregation.system.aggregateUseAction({
95
- aggregationDays: AGGREGATE_DAYS,
117
+ result = await chevre.service.aggregation.system.aggregateUseAction({
118
+ aggregateDurationUnit: 'hours',
119
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
96
120
  excludedProjectId: EXCLUDED_PROJECT_ID
97
121
  })({
98
122
  agregation: aggregationRepo,
99
123
  action: actionRepo
100
124
  });
125
+ console.log('aggregateUseAction processed.', result);
101
126
 
102
- await chevre.service.aggregation.system.aggregateCheckMovieTicketAction({
103
- aggregationDays: AGGREGATE_DAYS,
127
+ result = await chevre.service.aggregation.system.aggregateCheckMovieTicketAction({
128
+ aggregateDurationUnit: 'hours',
129
+ aggregationCount: AGGREGATE_DAYS * ONE_DAY_IN_HOURS,
104
130
  excludedProjectId: EXCLUDED_PROJECT_ID
105
131
  })({
106
132
  agregation: aggregationRepo,
107
133
  action: actionRepo
108
134
  });
135
+ console.log('aggregateCheckMovieTicketAction processed.', result);
109
136
  }
110
137
 
111
138
  main()
@@ -0,0 +1,26 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
+
9
+ const taskRepo = new chevre.repository.Task(mongoose.connection);
10
+ const result = await taskRepo.executeTasks({
11
+ now: new Date(),
12
+ delayInSeconds: 60,
13
+ limit: 1,
14
+ name: {
15
+ $nin: [
16
+ chevre.factory.taskName.ImportEventCapacitiesFromCOA,
17
+ chevre.factory.taskName.ImportEventsFromCOA
18
+ ]
19
+ }
20
+ });
21
+ console.log(result);
22
+ }
23
+
24
+ main()
25
+ .then(console.log)
26
+ .catch(console.error);
@@ -351,10 +351,17 @@ class MongoRepository {
351
351
  */
352
352
  startAndConfirm(params) {
353
353
  return __awaiter(this, void 0, void 0, function* () {
354
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { _id: params.id, typeOf: params.typeOf, startDate: new Date(), status: factory.transactionStatusType.Confirmed, tasksExportAction: {
354
+ const startDate = new Date();
355
+ const confirmedTransaction = yield this.transactionModel.create(Object.assign(Object.assign({}, params), { _id: params.id, typeOf: params.typeOf, startDate, status: factory.transactionStatusType.Confirmed, tasksExportAction: {
355
356
  actionStatus: factory.actionStatusType.PotentialActionStatus
356
- }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: new Date(), result: params.result, potentialActions: params.potentialActions }))
357
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported, endDate: startDate, result: params.result, potentialActions: params.potentialActions }))
357
358
  .then((doc) => doc.toObject());
359
+ assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
360
+ id: params.id,
361
+ typeOf: params.typeOf,
362
+ status: factory.transactionStatusType.Confirmed
363
+ });
364
+ return confirmedTransaction;
358
365
  });
359
366
  }
360
367
  /**
@@ -43,6 +43,17 @@ export declare class MongoRepository {
43
43
  name: string;
44
44
  };
45
45
  }): Promise<factory.task.ITask<T> | null>;
46
+ /**
47
+ * 一定期間遅延したタスクを実行する
48
+ */
49
+ executeTasks(params: {
50
+ now: Date;
51
+ delayInSeconds: number;
52
+ limit: number;
53
+ name: {
54
+ $nin?: factory.taskName[];
55
+ };
56
+ }): Promise<Pick<import("@chevre/factory/lib/task").ITask | import("@chevre/factory/lib/task/deleteAssetTransaction").ITask | import("@chevre/factory/lib/task/deleteOrder").ITask | import("@chevre/factory/lib/task/deleteTransaction").ITask | import("@chevre/factory/lib/task/sendEmailMessage").ITask | import("@chevre/factory/lib/task/triggerWebhook").ITask | import("@chevre/factory/lib/task/confirmMoneyTransfer").ITask | import("@chevre/factory/lib/task/confirmRegisterService").ITask | import("@chevre/factory/lib/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/task/confirmRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/task/deleteMember").ITask | import("@chevre/factory/lib/task/givePointAward").ITask | import("@chevre/factory/lib/task/orderProgramMembership").ITask | import("@chevre/factory/lib/task/placeOrder").ITask | import("@chevre/factory/lib/task/returnOrder").ITask | import("@chevre/factory/lib/task/returnMoneyTransfer").ITask | import("@chevre/factory/lib/task/returnPayTransaction").ITask | import("@chevre/factory/lib/task/returnPointAward").ITask | import("@chevre/factory/lib/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/task/sendOrder").ITask | import("@chevre/factory/lib/task/voidMoneyTransferTransaction").ITask | import("@chevre/factory/lib/task/voidPayTransaction").ITask | import("@chevre/factory/lib/task/voidRegisterServiceTransaction").ITask | import("@chevre/factory/lib/task/voidReserveTransaction").ITask, "name" | "id" | "status">[]>;
46
57
  retry(params: {
47
58
  intervalInMinutes: number;
48
59
  }): Promise<void>;
@@ -246,6 +246,35 @@ class MongoRepository {
246
246
  return doc.toObject();
247
247
  });
248
248
  }
249
+ /**
250
+ * 一定期間遅延したタスクを実行する
251
+ */
252
+ executeTasks(params) {
253
+ return __awaiter(this, void 0, void 0, function* () {
254
+ const runsAtLt = moment(params.now)
255
+ .add(-params.delayInSeconds, 'seconds')
256
+ .toDate();
257
+ const delayedTasks = yield this.taskModel.find(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: runsAtLt } }, (Array.isArray(params.name.$nin)) ? { name: { $nin: params.name.$nin } } : undefined))
258
+ .select({
259
+ _id: 1,
260
+ name: 1,
261
+ status: 1
262
+ })
263
+ .limit(params.limit)
264
+ .setOptions({ maxTimeMS: 10000 })
265
+ .exec();
266
+ if (delayedTasks.length > 0) {
267
+ delayedTasks.forEach((delayedTask) => {
268
+ task_2.taskEventEmitter.emitTaskStatusChanged({
269
+ id: delayedTask.id,
270
+ name: delayedTask.name,
271
+ status: delayedTask.status
272
+ });
273
+ });
274
+ }
275
+ return delayedTasks;
276
+ });
277
+ }
249
278
  retry(params) {
250
279
  return __awaiter(this, void 0, void 0, function* () {
251
280
  const lastTriedAtShoudBeLessThan = moment()
@@ -4,97 +4,142 @@ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransac
4
4
  import { MongoRepository as EventRepo } from '../../repo/event';
5
5
  import { MongoRepository as TasKRepo } from '../../repo/task';
6
6
  import { MongoRepository as TransactionRepo } from '../../repo/transaction';
7
+ type AggregateDurationUnit = 'days' | 'hours';
7
8
  declare function aggregateEvent(params: {
8
- aggregationDays: number;
9
+ aggregateDurationUnit: AggregateDurationUnit;
10
+ aggregationCount: number;
9
11
  excludedProjectId?: string;
10
12
  }): (repos: {
11
13
  agregation: AggregationRepo;
12
14
  event: EventRepo;
13
- }) => Promise<void>;
15
+ }) => Promise<{
16
+ aggregationCount: number;
17
+ aggregateDuration: string;
18
+ }>;
14
19
  /**
15
20
  * 注文取引集計
16
21
  */
17
22
  declare function aggregatePlaceOrder(params: {
18
- aggregationDays: number;
23
+ aggregateDurationUnit: AggregateDurationUnit;
24
+ aggregationCount: number;
19
25
  excludedProjectId?: string;
20
26
  clientIds?: string[];
21
27
  }): (repos: {
22
28
  agregation: AggregationRepo;
23
29
  transaction: TransactionRepo;
24
- }) => Promise<void>;
30
+ }) => Promise<{
31
+ aggregationCount: number;
32
+ aggregateDuration: string;
33
+ }>;
25
34
  /**
26
35
  * 興行オファー承認アクション集計
27
36
  */
28
37
  declare function aggregateAuthorizeEventServiceOfferAction(params: {
29
- aggregationDays: number;
38
+ aggregateDurationUnit: AggregateDurationUnit;
39
+ aggregationCount: number;
30
40
  excludedProjectId?: string;
31
41
  }): (repos: {
32
42
  agregation: AggregationRepo;
33
43
  action: ActionRepo;
34
- }) => Promise<void>;
44
+ }) => Promise<{
45
+ aggregationCount: number;
46
+ aggregateDuration: string;
47
+ }>;
35
48
  /**
36
49
  * 決済承認アクション集計
37
50
  */
38
51
  declare function aggregateAuthorizePaymentAction(params: {
39
- aggregationDays: number;
52
+ aggregateDurationUnit: AggregateDurationUnit;
53
+ aggregationCount: number;
40
54
  excludedProjectId?: string;
41
55
  }): (repos: {
42
56
  agregation: AggregationRepo;
43
57
  action: ActionRepo;
44
- }) => Promise<void>;
58
+ }) => Promise<{
59
+ aggregationCount: number;
60
+ aggregateDuration: string;
61
+ }>;
45
62
  declare function aggregateAuthorizeOrderAction(params: {
46
- aggregationDays: number;
63
+ aggregateDurationUnit: AggregateDurationUnit;
64
+ aggregationCount: number;
47
65
  excludedProjectId?: string;
48
66
  }): (repos: {
49
67
  agregation: AggregationRepo;
50
68
  action: ActionRepo;
51
- }) => Promise<void>;
69
+ }) => Promise<{
70
+ aggregationCount: number;
71
+ aggregateDuration: string;
72
+ }>;
52
73
  /**
53
74
  * 使用アクション集計
54
75
  */
55
76
  declare function aggregateUseAction(params: {
56
- aggregationDays: number;
77
+ aggregateDurationUnit: AggregateDurationUnit;
78
+ aggregationCount: number;
57
79
  excludedProjectId?: string;
58
80
  }): (repos: {
59
81
  agregation: AggregationRepo;
60
82
  action: ActionRepo;
61
- }) => Promise<void>;
83
+ }) => Promise<{
84
+ aggregationCount: number;
85
+ aggregateDuration: string;
86
+ }>;
62
87
  declare function aggregateCheckMovieTicketAction(params: {
63
- aggregationDays: number;
88
+ aggregateDurationUnit: AggregateDurationUnit;
89
+ aggregationCount: number;
64
90
  excludedProjectId?: string;
65
91
  }): (repos: {
66
92
  agregation: AggregationRepo;
67
93
  action: ActionRepo;
68
- }) => Promise<void>;
94
+ }) => Promise<{
95
+ aggregationCount: number;
96
+ aggregateDuration: string;
97
+ }>;
69
98
  declare function aggregatePayMovieTicketAction(params: {
70
- aggregationDays: number;
99
+ aggregateDurationUnit: AggregateDurationUnit;
100
+ aggregationCount: number;
71
101
  excludedProjectId?: string;
72
102
  }): (repos: {
73
103
  agregation: AggregationRepo;
74
104
  action: ActionRepo;
75
- }) => Promise<void>;
105
+ }) => Promise<{
106
+ aggregationCount: number;
107
+ aggregateDuration: string;
108
+ }>;
76
109
  declare function aggregatePayTransaction(params: {
77
- aggregationDays: number;
110
+ aggregateDurationUnit: AggregateDurationUnit;
111
+ aggregationCount: number;
78
112
  excludedProjectId?: string;
79
113
  }): (repos: {
80
114
  agregation: AggregationRepo;
81
115
  assetTransaction: AssetTransactionRepo;
82
- }) => Promise<void>;
116
+ }) => Promise<{
117
+ aggregationCount: number;
118
+ aggregateDuration: string;
119
+ }>;
83
120
  /**
84
121
  * 予約集計
85
122
  */
86
123
  declare function aggregateReserveTransaction(params: {
87
- aggregationDays: number;
124
+ aggregateDurationUnit: AggregateDurationUnit;
125
+ aggregationCount: number;
88
126
  excludedProjectId?: string;
89
127
  }): (repos: {
90
128
  agregation: AggregationRepo;
91
129
  assetTransaction: AssetTransactionRepo;
92
- }) => Promise<void>;
130
+ }) => Promise<{
131
+ aggregationCount: number;
132
+ aggregateDuration: string;
133
+ }>;
93
134
  declare function aggregateTask(params: {
94
- aggregationDays: number;
135
+ aggregateDurationUnit: AggregateDurationUnit;
136
+ aggregationCount: number;
95
137
  excludedProjectId?: string;
96
138
  }): (repos: {
97
139
  agregation: AggregationRepo;
98
140
  task: TasKRepo;
99
- }) => Promise<void>;
141
+ }) => Promise<{
142
+ aggregationCount: number;
143
+ aggregateDuration: string;
144
+ }>;
100
145
  export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateCheckMovieTicketAction, aggregateEvent, aggregatePayMovieTicketAction, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
@@ -19,22 +19,22 @@ function aggregateEvent(params) {
19
19
  return (repos) => __awaiter(this, void 0, void 0, function* () {
20
20
  var _a;
21
21
  const aggregateDate = new Date();
22
- const aggregateDuration = moment.duration(1, 'days')
22
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
23
23
  .toISOString();
24
24
  let i = -1;
25
- while (i < params.aggregationDays) {
25
+ while (i < params.aggregationCount) {
26
26
  i += 1;
27
- const startFrom = moment()
27
+ const startFrom = moment(aggregateDate)
28
28
  .utc()
29
29
  // .tz('Asia/Tokyo')
30
- .add(-i, 'days')
31
- .startOf('day')
30
+ .add(-i, params.aggregateDurationUnit)
31
+ .startOf(params.aggregateDurationUnit)
32
32
  .toDate();
33
- const startThrough = moment()
33
+ const startThrough = moment(aggregateDate)
34
34
  .utc()
35
35
  // .tz('Asia/Tokyo')
36
- .add(-i, 'days')
37
- .endOf('day')
36
+ .add(-i, params.aggregateDurationUnit)
37
+ .endOf(params.aggregateDurationUnit)
38
38
  .toDate();
39
39
  const aggregateResult = yield repos.event.aggregateEvent({
40
40
  project: { id: { $ne: params.excludedProjectId } },
@@ -45,6 +45,7 @@ function aggregateEvent(params) {
45
45
  debug('aggregateEvent:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesRemainingCapacityRate, startFrom);
46
46
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateEvent, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
47
47
  }
48
+ return { aggregationCount: i, aggregateDuration };
48
49
  });
49
50
  }
50
51
  exports.aggregateEvent = aggregateEvent;
@@ -55,22 +56,22 @@ function aggregatePlaceOrder(params) {
55
56
  return (repos) => __awaiter(this, void 0, void 0, function* () {
56
57
  var _a, _b;
57
58
  const aggregateDate = new Date();
58
- const aggregateDuration = moment.duration(1, 'days')
59
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
59
60
  .toISOString();
60
61
  let i = -1;
61
- while (i < params.aggregationDays) {
62
+ while (i < params.aggregationCount) {
62
63
  i += 1;
63
- const startFrom = moment()
64
+ const startFrom = moment(aggregateDate)
64
65
  .utc()
65
66
  // .tz('Asia/Tokyo')
66
- .add(-i, 'days')
67
- .startOf('day')
67
+ .add(-i, params.aggregateDurationUnit)
68
+ .startOf(params.aggregateDurationUnit)
68
69
  .toDate();
69
- const startThrough = moment()
70
+ const startThrough = moment(aggregateDate)
70
71
  .utc()
71
72
  // .tz('Asia/Tokyo')
72
- .add(-i, 'days')
73
- .endOf('day')
73
+ .add(-i, params.aggregateDurationUnit)
74
+ .endOf(params.aggregateDurationUnit)
74
75
  .toDate();
75
76
  const aggregateResult = yield repos.transaction.aggregatePlaceOrder({
76
77
  project: { id: { $ne: params.excludedProjectId } },
@@ -98,6 +99,7 @@ function aggregatePlaceOrder(params) {
98
99
  }
99
100
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePlaceOrder, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate, aggregationByClient: aggregateResultsByClientId }, aggregateResult));
100
101
  }
102
+ return { aggregationCount: i, aggregateDuration };
101
103
  });
102
104
  }
103
105
  exports.aggregatePlaceOrder = aggregatePlaceOrder;
@@ -108,22 +110,22 @@ function aggregateAuthorizeEventServiceOfferAction(params) {
108
110
  return (repos) => __awaiter(this, void 0, void 0, function* () {
109
111
  var _a;
110
112
  const aggregateDate = new Date();
111
- const aggregateDuration = moment.duration(1, 'days')
113
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
112
114
  .toISOString();
113
115
  let i = -1;
114
- while (i < params.aggregationDays) {
116
+ while (i < params.aggregationCount) {
115
117
  i += 1;
116
- const startFrom = moment()
118
+ const startFrom = moment(aggregateDate)
117
119
  .utc()
118
120
  // .tz('Asia/Tokyo')
119
- .add(-i, 'days')
120
- .startOf('day')
121
+ .add(-i, params.aggregateDurationUnit)
122
+ .startOf(params.aggregateDurationUnit)
121
123
  .toDate();
122
- const startThrough = moment()
124
+ const startThrough = moment(aggregateDate)
123
125
  .utc()
124
126
  // .tz('Asia/Tokyo')
125
- .add(-i, 'days')
126
- .endOf('day')
127
+ .add(-i, params.aggregateDurationUnit)
128
+ .endOf(params.aggregateDurationUnit)
127
129
  .toDate();
128
130
  const aggregateResult = yield repos.action.aggregateAuthorizeEventServiceOfferAction({
129
131
  project: { id: { $ne: params.excludedProjectId } },
@@ -134,6 +136,7 @@ function aggregateAuthorizeEventServiceOfferAction(params) {
134
136
  debug('aggregateAuthorizeEventServiceOfferAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
135
137
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateAuthorizeEventServiceOfferAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
136
138
  }
139
+ return { aggregationCount: i, aggregateDuration };
137
140
  });
138
141
  }
139
142
  exports.aggregateAuthorizeEventServiceOfferAction = aggregateAuthorizeEventServiceOfferAction;
@@ -144,22 +147,22 @@ function aggregateAuthorizePaymentAction(params) {
144
147
  return (repos) => __awaiter(this, void 0, void 0, function* () {
145
148
  var _a;
146
149
  const aggregateDate = new Date();
147
- const aggregateDuration = moment.duration(1, 'days')
150
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
148
151
  .toISOString();
149
152
  let i = -1;
150
- while (i < params.aggregationDays) {
153
+ while (i < params.aggregationCount) {
151
154
  i += 1;
152
- const startFrom = moment()
155
+ const startFrom = moment(aggregateDate)
153
156
  .utc()
154
157
  // .tz('Asia/Tokyo')
155
- .add(-i, 'days')
156
- .startOf('day')
158
+ .add(-i, params.aggregateDurationUnit)
159
+ .startOf(params.aggregateDurationUnit)
157
160
  .toDate();
158
- const startThrough = moment()
161
+ const startThrough = moment(aggregateDate)
159
162
  .utc()
160
163
  // .tz('Asia/Tokyo')
161
- .add(-i, 'days')
162
- .endOf('day')
164
+ .add(-i, params.aggregateDurationUnit)
165
+ .endOf(params.aggregateDurationUnit)
163
166
  .toDate();
164
167
  const aggregateResult = yield repos.action.aggregateAuthorizePaymentAction({
165
168
  project: { id: { $ne: params.excludedProjectId } },
@@ -170,6 +173,7 @@ function aggregateAuthorizePaymentAction(params) {
170
173
  debug('aggregateAuthorizePaymentAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
171
174
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateAuthorizePaymentAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
172
175
  }
176
+ return { aggregationCount: i, aggregateDuration };
173
177
  });
174
178
  }
175
179
  exports.aggregateAuthorizePaymentAction = aggregateAuthorizePaymentAction;
@@ -177,22 +181,22 @@ function aggregateAuthorizeOrderAction(params) {
177
181
  return (repos) => __awaiter(this, void 0, void 0, function* () {
178
182
  var _a;
179
183
  const aggregateDate = new Date();
180
- const aggregateDuration = moment.duration(1, 'days')
184
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
181
185
  .toISOString();
182
186
  let i = -1;
183
- while (i < params.aggregationDays) {
187
+ while (i < params.aggregationCount) {
184
188
  i += 1;
185
- const startFrom = moment()
189
+ const startFrom = moment(aggregateDate)
186
190
  .utc()
187
191
  // .tz('Asia/Tokyo')
188
- .add(-i, 'days')
189
- .startOf('day')
192
+ .add(-i, params.aggregateDurationUnit)
193
+ .startOf(params.aggregateDurationUnit)
190
194
  .toDate();
191
- const startThrough = moment()
195
+ const startThrough = moment(aggregateDate)
192
196
  .utc()
193
197
  // .tz('Asia/Tokyo')
194
- .add(-i, 'days')
195
- .endOf('day')
198
+ .add(-i, params.aggregateDurationUnit)
199
+ .endOf(params.aggregateDurationUnit)
196
200
  .toDate();
197
201
  const aggregateResult = yield repos.action.aggregateAuthorizeOrderAction({
198
202
  project: { id: { $ne: params.excludedProjectId } },
@@ -203,6 +207,7 @@ function aggregateAuthorizeOrderAction(params) {
203
207
  debug('aggregateAuthorizeOrderAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
204
208
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateAuthorizeOrderAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
205
209
  }
210
+ return { aggregationCount: i, aggregateDuration };
206
211
  });
207
212
  }
208
213
  exports.aggregateAuthorizeOrderAction = aggregateAuthorizeOrderAction;
@@ -213,22 +218,22 @@ function aggregateUseAction(params) {
213
218
  return (repos) => __awaiter(this, void 0, void 0, function* () {
214
219
  var _a;
215
220
  const aggregateDate = new Date();
216
- const aggregateDuration = moment.duration(1, 'days')
221
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
217
222
  .toISOString();
218
223
  let i = -1;
219
- while (i < params.aggregationDays) {
224
+ while (i < params.aggregationCount) {
220
225
  i += 1;
221
- const startFrom = moment()
226
+ const startFrom = moment(aggregateDate)
222
227
  .utc()
223
228
  // .tz('Asia/Tokyo')
224
- .add(-i, 'days')
225
- .startOf('day')
229
+ .add(-i, params.aggregateDurationUnit)
230
+ .startOf(params.aggregateDurationUnit)
226
231
  .toDate();
227
- const startThrough = moment()
232
+ const startThrough = moment(aggregateDate)
228
233
  .utc()
229
234
  // .tz('Asia/Tokyo')
230
- .add(-i, 'days')
231
- .endOf('day')
235
+ .add(-i, params.aggregateDurationUnit)
236
+ .endOf(params.aggregateDurationUnit)
232
237
  .toDate();
233
238
  const aggregateResult = yield repos.action.aggregateUseAction({
234
239
  project: { id: { $ne: params.excludedProjectId } },
@@ -239,6 +244,7 @@ function aggregateUseAction(params) {
239
244
  debug('aggregateUseAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
240
245
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateUseAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
241
246
  }
247
+ return { aggregationCount: i, aggregateDuration };
242
248
  });
243
249
  }
244
250
  exports.aggregateUseAction = aggregateUseAction;
@@ -246,22 +252,22 @@ function aggregateCheckMovieTicketAction(params) {
246
252
  return (repos) => __awaiter(this, void 0, void 0, function* () {
247
253
  var _a;
248
254
  const aggregateDate = new Date();
249
- const aggregateDuration = moment.duration(1, 'days')
255
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
250
256
  .toISOString();
251
257
  let i = -1;
252
- while (i < params.aggregationDays) {
258
+ while (i < params.aggregationCount) {
253
259
  i += 1;
254
- const startFrom = moment()
260
+ const startFrom = moment(aggregateDate)
255
261
  .utc()
256
262
  // .tz('Asia/Tokyo')
257
- .add(-i, 'days')
258
- .startOf('day')
263
+ .add(-i, params.aggregateDurationUnit)
264
+ .startOf(params.aggregateDurationUnit)
259
265
  .toDate();
260
- const startThrough = moment()
266
+ const startThrough = moment(aggregateDate)
261
267
  .utc()
262
268
  // .tz('Asia/Tokyo')
263
- .add(-i, 'days')
264
- .endOf('day')
269
+ .add(-i, params.aggregateDurationUnit)
270
+ .endOf(params.aggregateDurationUnit)
265
271
  .toDate();
266
272
  const aggregateResult = yield repos.action.aggregateCheckMovieTicketAction({
267
273
  project: { id: { $ne: params.excludedProjectId } },
@@ -271,6 +277,7 @@ function aggregateCheckMovieTicketAction(params) {
271
277
  debug('aggregateCheckMovieTicketAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
272
278
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateCheckMovieTicketAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
273
279
  }
280
+ return { aggregationCount: i, aggregateDuration };
274
281
  });
275
282
  }
276
283
  exports.aggregateCheckMovieTicketAction = aggregateCheckMovieTicketAction;
@@ -278,22 +285,22 @@ function aggregatePayMovieTicketAction(params) {
278
285
  return (repos) => __awaiter(this, void 0, void 0, function* () {
279
286
  var _a;
280
287
  const aggregateDate = new Date();
281
- const aggregateDuration = moment.duration(1, 'days')
288
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
282
289
  .toISOString();
283
290
  let i = -1;
284
- while (i < params.aggregationDays) {
291
+ while (i < params.aggregationCount) {
285
292
  i += 1;
286
- const startFrom = moment()
293
+ const startFrom = moment(aggregateDate)
287
294
  .utc()
288
295
  // .tz('Asia/Tokyo')
289
- .add(-i, 'days')
290
- .startOf('day')
296
+ .add(-i, params.aggregateDurationUnit)
297
+ .startOf(params.aggregateDurationUnit)
291
298
  .toDate();
292
- const startThrough = moment()
299
+ const startThrough = moment(aggregateDate)
293
300
  .utc()
294
301
  // .tz('Asia/Tokyo')
295
- .add(-i, 'days')
296
- .endOf('day')
302
+ .add(-i, params.aggregateDurationUnit)
303
+ .endOf(params.aggregateDurationUnit)
297
304
  .toDate();
298
305
  const aggregateResult = yield repos.action.aggregatePayMovieTicketAction({
299
306
  project: { id: { $ne: params.excludedProjectId } },
@@ -303,6 +310,7 @@ function aggregatePayMovieTicketAction(params) {
303
310
  debug('aggregatePayMovieTicketAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
304
311
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePayMovieTicketAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
305
312
  }
313
+ return { aggregationCount: i, aggregateDuration };
306
314
  });
307
315
  }
308
316
  exports.aggregatePayMovieTicketAction = aggregatePayMovieTicketAction;
@@ -310,22 +318,22 @@ function aggregatePayTransaction(params) {
310
318
  return (repos) => __awaiter(this, void 0, void 0, function* () {
311
319
  var _a;
312
320
  const aggregateDate = new Date();
313
- const aggregateDuration = moment.duration(1, 'days')
321
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
314
322
  .toISOString();
315
323
  let i = -1;
316
- while (i < params.aggregationDays) {
324
+ while (i < params.aggregationCount) {
317
325
  i += 1;
318
- const startFrom = moment()
326
+ const startFrom = moment(aggregateDate)
319
327
  .utc()
320
328
  // .tz('Asia/Tokyo')
321
- .add(-i, 'days')
322
- .startOf('day')
329
+ .add(-i, params.aggregateDurationUnit)
330
+ .startOf(params.aggregateDurationUnit)
323
331
  .toDate();
324
- const startThrough = moment()
332
+ const startThrough = moment(aggregateDate)
325
333
  .utc()
326
334
  // .tz('Asia/Tokyo')
327
- .add(-i, 'days')
328
- .endOf('day')
335
+ .add(-i, params.aggregateDurationUnit)
336
+ .endOf(params.aggregateDurationUnit)
329
337
  .toDate();
330
338
  const aggregateResult = yield repos.assetTransaction.aggregateAssetTransaction({
331
339
  project: { id: { $ne: params.excludedProjectId } },
@@ -336,6 +344,7 @@ function aggregatePayTransaction(params) {
336
344
  debug('aggregatePayTransaction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, startFrom);
337
345
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregatePay, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
338
346
  }
347
+ return { aggregationCount: i, aggregateDuration };
339
348
  });
340
349
  }
341
350
  exports.aggregatePayTransaction = aggregatePayTransaction;
@@ -346,22 +355,22 @@ function aggregateReserveTransaction(params) {
346
355
  return (repos) => __awaiter(this, void 0, void 0, function* () {
347
356
  var _a;
348
357
  const aggregateDate = new Date();
349
- const aggregateDuration = moment.duration(1, 'days')
358
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
350
359
  .toISOString();
351
360
  let i = -1;
352
- while (i < params.aggregationDays) {
361
+ while (i < params.aggregationCount) {
353
362
  i += 1;
354
- const startFrom = moment()
363
+ const startFrom = moment(aggregateDate)
355
364
  .utc()
356
365
  // .tz('Asia/Tokyo')
357
- .add(-i, 'days')
358
- .startOf('day')
366
+ .add(-i, params.aggregateDurationUnit)
367
+ .startOf(params.aggregateDurationUnit)
359
368
  .toDate();
360
- const startThrough = moment()
369
+ const startThrough = moment(aggregateDate)
361
370
  .utc()
362
371
  // .tz('Asia/Tokyo')
363
- .add(-i, 'days')
364
- .endOf('day')
372
+ .add(-i, params.aggregateDurationUnit)
373
+ .endOf(params.aggregateDurationUnit)
365
374
  .toDate();
366
375
  const aggregateResult = yield repos.assetTransaction.aggregateAssetTransaction({
367
376
  project: { id: { $ne: params.excludedProjectId } },
@@ -372,6 +381,7 @@ function aggregateReserveTransaction(params) {
372
381
  debug('aggregateReserveTransaction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, startFrom);
373
382
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateReserve, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
374
383
  }
384
+ return { aggregationCount: i, aggregateDuration };
375
385
  });
376
386
  }
377
387
  exports.aggregateReserveTransaction = aggregateReserveTransaction;
@@ -379,31 +389,33 @@ function aggregateTask(params) {
379
389
  return (repos) => __awaiter(this, void 0, void 0, function* () {
380
390
  var _a;
381
391
  const aggregateDate = new Date();
382
- const aggregateDuration = moment.duration(1, 'days')
392
+ const aggregateDuration = moment.duration(1, params.aggregateDurationUnit)
383
393
  .toISOString();
384
394
  let i = -1;
385
- while (i < params.aggregationDays) {
395
+ while (i < params.aggregationCount) {
386
396
  i += 1;
387
- const runsFrom = moment()
397
+ const runsFrom = moment(aggregateDate)
388
398
  .utc()
389
399
  // .tz('Asia/Tokyo')
390
- .add(-i, 'days')
391
- .startOf('day')
400
+ .add(-i, params.aggregateDurationUnit)
401
+ .startOf(params.aggregateDurationUnit)
392
402
  .toDate();
393
- const runsThrough = moment()
403
+ const runsThrough = moment(aggregateDate)
394
404
  .utc()
395
405
  // .tz('Asia/Tokyo')
396
- .add(-i, 'days')
397
- .endOf('day')
406
+ .add(-i, params.aggregateDurationUnit)
407
+ .endOf(params.aggregateDurationUnit)
398
408
  .toDate();
399
409
  const aggregateResult = yield repos.task.aggregateTask({
400
410
  project: { id: { $ne: params.excludedProjectId } },
401
411
  runsFrom,
402
412
  runsThrough
403
413
  });
404
- debug('aggregateTask:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, runsFrom);
414
+ debug('aggregateTask:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation, runsFrom, runsThrough);
405
415
  yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateTask, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: runsFrom, aggregateDate }, aggregateResult));
406
416
  }
417
+ debug(i, 'aggregations saved');
418
+ return { aggregationCount: i, aggregateDuration };
407
419
  });
408
420
  }
409
421
  exports.aggregateTask = aggregateTask;
@@ -92,7 +92,21 @@ function createTasks(params) {
92
92
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
93
93
  }
94
94
  };
95
- taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes);
95
+ // 確定取引にも興行オファー承認中止タスクを追加(2023-05-09~)
96
+ const voidReserveTaskAttributes = {
97
+ project: transaction.project,
98
+ name: factory.taskName.VoidReserveTransaction,
99
+ status: factory.taskStatus.Ready,
100
+ runsAt: taskRunsAt,
101
+ remainingNumberOfTries: 10,
102
+ numberOfTried: 0,
103
+ executionResults: [],
104
+ data: {
105
+ project: transaction.project,
106
+ purpose: { typeOf: transaction.typeOf, id: transaction.id }
107
+ }
108
+ };
109
+ taskAttributes.push(...triggerWebhookTaskAttributes, deleteTransactionTask, voidPaymentTaskAttributes, voidReserveTaskAttributes);
96
110
  switch (transaction.status) {
97
111
  case factory.transactionStatusType.Confirmed:
98
112
  const potentialActions = transaction.potentialActions;
@@ -123,19 +137,6 @@ function createTasks(params) {
123
137
  break;
124
138
  case factory.transactionStatusType.Canceled:
125
139
  case factory.transactionStatusType.Expired:
126
- const voidReserveTaskAttributes = {
127
- project: transaction.project,
128
- name: factory.taskName.VoidReserveTransaction,
129
- status: factory.taskStatus.Ready,
130
- runsAt: taskRunsAt,
131
- remainingNumberOfTries: 10,
132
- numberOfTried: 0,
133
- executionResults: [],
134
- data: {
135
- project: transaction.project,
136
- purpose: { typeOf: transaction.typeOf, id: transaction.id }
137
- }
138
- };
139
140
  const voidRegisterServiceTaskAttributes = {
140
141
  project: transaction.project,
141
142
  name: factory.taskName.VoidRegisterServiceTransaction,
@@ -162,7 +163,7 @@ function createTasks(params) {
162
163
  purpose: { typeOf: transaction.typeOf, id: transaction.id }
163
164
  }
164
165
  };
165
- taskAttributes.push(voidReserveTaskAttributes, voidRegisterServiceTaskAttributes, voidMoneyTransferTaskAttributes);
166
+ taskAttributes.push(voidRegisterServiceTaskAttributes, voidMoneyTransferTaskAttributes);
166
167
  break;
167
168
  default:
168
169
  throw new factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.34"
120
+ "version": "21.2.0-alpha.36"
121
121
  }