@chevre/domain 21.2.0-alpha.27 → 21.2.0-alpha.28
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.
- package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
- package/lib/chevre/eventEmitter/assetTransaction.js +28 -0
- package/lib/chevre/eventEmitter.d.ts +2 -1
- package/lib/chevre/eventEmitter.js +3 -1
- package/lib/chevre/repo/assetTransaction.js +55 -3
- package/lib/chevre/service/assetTransaction.d.ts +1 -0
- package/lib/chevre/service/assetTransaction.js +2 -6
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import * as factory from '../factory';
|
|
4
|
+
interface IListenArgsOnAssetTransactionStatusChanged {
|
|
5
|
+
/**
|
|
6
|
+
* 取引ID
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
typeOf: factory.assetTransactionType;
|
|
10
|
+
status: factory.transactionStatusType;
|
|
11
|
+
}
|
|
12
|
+
type IOnAssetTransactionStatusChangedListener = (listenArgs: IListenArgsOnAssetTransactionStatusChanged) => void;
|
|
13
|
+
/**
|
|
14
|
+
* 資産取引イベントエミッター
|
|
15
|
+
*/
|
|
16
|
+
declare class AssetTransactionEventEmitter extends EventEmitter {
|
|
17
|
+
onAssetTransactionStatusChanged(listner: IOnAssetTransactionStatusChangedListener): void;
|
|
18
|
+
emitAssetTransactionStatusChanged(args: IListenArgsOnAssetTransactionStatusChanged): void;
|
|
19
|
+
}
|
|
20
|
+
declare const assetTransactionEventEmitter: AssetTransactionEventEmitter;
|
|
21
|
+
export { IListenArgsOnAssetTransactionStatusChanged, assetTransactionEventEmitter };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assetTransactionEventEmitter = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
const settings_1 = require("../settings");
|
|
6
|
+
var EventName;
|
|
7
|
+
(function (EventName) {
|
|
8
|
+
EventName["OnAssetTransactionStatusChanged"] = "OnAssetTransactionStatusChanged";
|
|
9
|
+
})(EventName || (EventName = {}));
|
|
10
|
+
/**
|
|
11
|
+
* 資産取引イベントエミッター
|
|
12
|
+
*/
|
|
13
|
+
class AssetTransactionEventEmitter extends events_1.EventEmitter {
|
|
14
|
+
onAssetTransactionStatusChanged(listner) {
|
|
15
|
+
this.on(EventName.OnAssetTransactionStatusChanged, listner);
|
|
16
|
+
}
|
|
17
|
+
emitAssetTransactionStatusChanged(args) {
|
|
18
|
+
if (settings_1.USE_EVENT_EMITTERS) {
|
|
19
|
+
this.emit(EventName.OnAssetTransactionStatusChanged, args);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const assetTransactionEventEmitter = new AssetTransactionEventEmitter();
|
|
24
|
+
exports.assetTransactionEventEmitter = assetTransactionEventEmitter;
|
|
25
|
+
assetTransactionEventEmitter.on('error', (err) => {
|
|
26
|
+
// tslint:disable-next-line:no-console
|
|
27
|
+
console.error('assetTransactionEventEmitter listened an error.', err);
|
|
28
|
+
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assetTransactionEventEmitter } from './eventEmitter/assetTransaction';
|
|
1
2
|
import { taskEventEmitter } from './eventEmitter/task';
|
|
2
3
|
import { transactionEventEmitter } from './eventEmitter/transaction';
|
|
3
|
-
export { taskEventEmitter as task, transactionEventEmitter as transaction };
|
|
4
|
+
export { assetTransactionEventEmitter as assetTransaction, taskEventEmitter as task, transactionEventEmitter as transaction };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transaction = exports.task = void 0;
|
|
3
|
+
exports.transaction = exports.task = exports.assetTransaction = void 0;
|
|
4
|
+
const assetTransaction_1 = require("./eventEmitter/assetTransaction");
|
|
5
|
+
Object.defineProperty(exports, "assetTransaction", { enumerable: true, get: function () { return assetTransaction_1.assetTransactionEventEmitter; } });
|
|
4
6
|
const task_1 = require("./eventEmitter/task");
|
|
5
7
|
Object.defineProperty(exports, "task", { enumerable: true, get: function () { return task_1.taskEventEmitter; } });
|
|
6
8
|
const transaction_1 = require("./eventEmitter/transaction");
|
|
@@ -13,6 +13,7 @@ exports.MongoRepository = void 0;
|
|
|
13
13
|
const moment = require("moment");
|
|
14
14
|
const assetTransaction_1 = require("./mongoose/schemas/assetTransaction");
|
|
15
15
|
const factory = require("../factory");
|
|
16
|
+
const assetTransaction_2 = require("../eventEmitter/assetTransaction");
|
|
16
17
|
/**
|
|
17
18
|
* 資産取引リポジトリ
|
|
18
19
|
*/
|
|
@@ -336,6 +337,11 @@ class MongoRepository {
|
|
|
336
337
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
337
338
|
}
|
|
338
339
|
}
|
|
340
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
341
|
+
id: params.id,
|
|
342
|
+
typeOf: params.typeOf,
|
|
343
|
+
status: factory.transactionStatusType.Confirmed
|
|
344
|
+
});
|
|
339
345
|
});
|
|
340
346
|
}
|
|
341
347
|
/**
|
|
@@ -383,17 +389,51 @@ class MongoRepository {
|
|
|
383
389
|
*/
|
|
384
390
|
reexportTasks(params) {
|
|
385
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
386
|
-
yield this.transactionModel.
|
|
392
|
+
const reexportingTransactions = yield this.transactionModel.find({
|
|
387
393
|
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
388
394
|
updatedAt: {
|
|
389
395
|
$lt: moment()
|
|
390
396
|
.add(-params.intervalInMinutes, 'minutes')
|
|
391
397
|
.toDate()
|
|
392
398
|
}
|
|
393
|
-
}, {
|
|
394
|
-
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
395
399
|
})
|
|
400
|
+
.select({
|
|
401
|
+
_id: 1,
|
|
402
|
+
typeOf: 1,
|
|
403
|
+
status: 1
|
|
404
|
+
})
|
|
405
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
396
406
|
.exec();
|
|
407
|
+
if (reexportingTransactions.length > 0) {
|
|
408
|
+
for (const reexportingTransaction of reexportingTransactions) {
|
|
409
|
+
yield this.transactionModel.updateOne({
|
|
410
|
+
_id: { $eq: reexportingTransaction.id },
|
|
411
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
412
|
+
}, {
|
|
413
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
414
|
+
})
|
|
415
|
+
.exec();
|
|
416
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
417
|
+
id: reexportingTransaction.id,
|
|
418
|
+
typeOf: reexportingTransaction.typeOf,
|
|
419
|
+
status: reexportingTransaction.status
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
// await this.transactionModel.updateMany(
|
|
424
|
+
// {
|
|
425
|
+
// tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
426
|
+
// updatedAt: {
|
|
427
|
+
// $lt: moment()
|
|
428
|
+
// .add(-params.intervalInMinutes, 'minutes')
|
|
429
|
+
// .toDate()
|
|
430
|
+
// }
|
|
431
|
+
// },
|
|
432
|
+
// {
|
|
433
|
+
// tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
434
|
+
// }
|
|
435
|
+
// )
|
|
436
|
+
// .exec();
|
|
397
437
|
});
|
|
398
438
|
}
|
|
399
439
|
/**
|
|
@@ -441,6 +481,13 @@ class MongoRepository {
|
|
|
441
481
|
endDate: new Date()
|
|
442
482
|
})
|
|
443
483
|
.exec();
|
|
484
|
+
expiringTransactions.forEach((expiringTransaction) => {
|
|
485
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
486
|
+
id: expiringTransaction.id,
|
|
487
|
+
typeOf: expiringTransaction.typeOf,
|
|
488
|
+
status: factory.transactionStatusType.Expired
|
|
489
|
+
});
|
|
490
|
+
});
|
|
444
491
|
}
|
|
445
492
|
});
|
|
446
493
|
}
|
|
@@ -489,6 +536,11 @@ class MongoRepository {
|
|
|
489
536
|
else {
|
|
490
537
|
transaction = doc.toObject();
|
|
491
538
|
}
|
|
539
|
+
assetTransaction_2.assetTransactionEventEmitter.emitAssetTransactionStatusChanged({
|
|
540
|
+
id: transaction.id,
|
|
541
|
+
typeOf: params.typeOf,
|
|
542
|
+
status: factory.transactionStatusType.Canceled
|
|
543
|
+
});
|
|
492
544
|
return transaction;
|
|
493
545
|
});
|
|
494
546
|
}
|
|
@@ -33,17 +33,13 @@ exports.reserve = ReserveTransactionService;
|
|
|
33
33
|
function exportTasks(params) {
|
|
34
34
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
35
35
|
var _a;
|
|
36
|
-
const transaction = yield repos.assetTransaction.startExportTasks({
|
|
37
|
-
typeOf: params.typeOf,
|
|
38
|
-
status: params.status,
|
|
39
|
-
tasksExportAction: {
|
|
36
|
+
const transaction = yield repos.assetTransaction.startExportTasks(Object.assign({ typeOf: params.typeOf, status: params.status, tasksExportAction: {
|
|
40
37
|
agent: {
|
|
41
38
|
name: (typeof ((_a = params.tasksExportAction) === null || _a === void 0 ? void 0 : _a.agent.name) === 'string')
|
|
42
39
|
? params.tasksExportAction.agent.name
|
|
43
40
|
: settings_1.DEFAULT_TASKS_EXPORT_AGENT_NAME
|
|
44
41
|
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
42
|
+
} }, (typeof params.id === 'string') ? { id: params.id } : undefined));
|
|
47
43
|
if (transaction === null) {
|
|
48
44
|
return;
|
|
49
45
|
}
|
package/package.json
CHANGED