@chevre/domain 21.2.0-alpha.12 → 21.2.0-alpha.13
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/example/src/chevre/transaction/startExportTasks.ts +19 -0
- package/lib/chevre/repo/accountTransaction.d.ts +0 -10
- package/lib/chevre/repo/accountTransaction.js +0 -53
- package/lib/chevre/repo/assetTransaction.d.ts +2 -1
- package/lib/chevre/repo/assetTransaction.js +8 -9
- package/lib/chevre/repo/transaction.d.ts +2 -1
- package/lib/chevre/repo/transaction.js +8 -8
- package/lib/chevre/service/transaction.d.ts +1 -0
- package/lib/chevre/service/transaction.js +1 -7
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
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 transactionRepo = new chevre.repository.Transaction(mongoose.connection);
|
|
10
|
+
const result = await transactionRepo.startExportTasks({
|
|
11
|
+
typeOf: { $in: [chevre.factory.transactionType.PlaceOrder] },
|
|
12
|
+
status: chevre.factory.transactionStatusType.Confirmed
|
|
13
|
+
});
|
|
14
|
+
console.log(result);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
main()
|
|
18
|
+
.then(console.log)
|
|
19
|
+
.catch(console.error);
|
|
@@ -42,16 +42,6 @@ export declare class MongoRepository {
|
|
|
42
42
|
id?: string;
|
|
43
43
|
transactionNumber?: string;
|
|
44
44
|
}): Promise<factory.account.transaction.ITransaction<T>>;
|
|
45
|
-
/**
|
|
46
|
-
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
47
|
-
*/
|
|
48
|
-
/**
|
|
49
|
-
* タスクエクスポートリトライ
|
|
50
|
-
* TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* タスクをエクスポート済に変更する
|
|
54
|
-
*/
|
|
55
45
|
/**
|
|
56
46
|
* 取引を期限切れにする
|
|
57
47
|
*/
|
|
@@ -221,59 +221,6 @@ class MongoRepository {
|
|
|
221
221
|
return doc.toObject();
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
|
-
/**
|
|
225
|
-
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
226
|
-
*/
|
|
227
|
-
// public async startExportTasks<T extends factory.account.transactionType>(
|
|
228
|
-
// status: factory.transactionStatusType
|
|
229
|
-
// ): Promise<factory.account.transaction.ITransaction<T> | null> {
|
|
230
|
-
// return this.transactionModel.findOneAndUpdate(
|
|
231
|
-
// {
|
|
232
|
-
// status: status,
|
|
233
|
-
// tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
234
|
-
// },
|
|
235
|
-
// { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting },
|
|
236
|
-
// { new: true }
|
|
237
|
-
// )
|
|
238
|
-
// .exec()
|
|
239
|
-
// // tslint:disable-next-line:no-null-keyword
|
|
240
|
-
// .then((doc) => (doc === null) ? null : doc.toObject());
|
|
241
|
-
// }
|
|
242
|
-
// tslint:disable-next-line:no-suspicious-comment
|
|
243
|
-
/**
|
|
244
|
-
* タスクエクスポートリトライ
|
|
245
|
-
* TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
|
|
246
|
-
*/
|
|
247
|
-
// public async reexportTasks(params: { intervalInMinutes: number }): Promise<void> {
|
|
248
|
-
// await this.transactionModel.updateMany(
|
|
249
|
-
// {
|
|
250
|
-
// tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
|
|
251
|
-
// updatedAt: {
|
|
252
|
-
// $lt: moment()
|
|
253
|
-
// .add(-params.intervalInMinutes, 'minutes')
|
|
254
|
-
// .toDate()
|
|
255
|
-
// }
|
|
256
|
-
// },
|
|
257
|
-
// {
|
|
258
|
-
// tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
259
|
-
// }
|
|
260
|
-
// )
|
|
261
|
-
// .exec();
|
|
262
|
-
// }
|
|
263
|
-
/**
|
|
264
|
-
* タスクをエクスポート済に変更する
|
|
265
|
-
*/
|
|
266
|
-
// public async setTasksExportedById(transactionId: string): Promise<void> {
|
|
267
|
-
// await this.transactionModel.findByIdAndUpdate(
|
|
268
|
-
// transactionId,
|
|
269
|
-
// {
|
|
270
|
-
// tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
271
|
-
// tasksExportedAt: moment()
|
|
272
|
-
// .toDate()
|
|
273
|
-
// }
|
|
274
|
-
// )
|
|
275
|
-
// .exec();
|
|
276
|
-
// }
|
|
277
224
|
/**
|
|
278
225
|
* 取引を期限切れにする
|
|
279
226
|
*/
|
|
@@ -100,7 +100,8 @@ export declare class MongoRepository {
|
|
|
100
100
|
$in: T[];
|
|
101
101
|
};
|
|
102
102
|
status: factory.transactionStatusType;
|
|
103
|
-
|
|
103
|
+
id?: string;
|
|
104
|
+
}): Promise<Pick<factory.assetTransaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
|
|
104
105
|
/**
|
|
105
106
|
* タスクエクスポートリトライ
|
|
106
107
|
* TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
|
|
@@ -353,15 +353,14 @@ class MongoRepository {
|
|
|
353
353
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
354
354
|
*/
|
|
355
355
|
startExportTasks(params) {
|
|
356
|
-
var _a, _b
|
|
356
|
+
var _a, _b;
|
|
357
357
|
return __awaiter(this, void 0, void 0, function* () {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
? { typeOf: { $in: (_c = params.typeOf) === null || _c === void 0 ? void 0 : _c.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
358
|
+
const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
|
|
359
|
+
return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof ((_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === 'string') ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
360
|
+
.select({
|
|
361
|
+
_id: 1,
|
|
362
|
+
typeOf: 1
|
|
363
|
+
})
|
|
365
364
|
.exec()
|
|
366
365
|
// tslint:disable-next-line:no-null-keyword
|
|
367
366
|
.then((doc) => (doc === null) ? null : doc.toObject());
|
|
@@ -393,7 +392,7 @@ class MongoRepository {
|
|
|
393
392
|
*/
|
|
394
393
|
setTasksExportedById(params) {
|
|
395
394
|
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
yield this.transactionModel.
|
|
395
|
+
yield this.transactionModel.updateOne({ _id: { $eq: params.id } }, {
|
|
397
396
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
398
397
|
tasksExportedAt: moment()
|
|
399
398
|
.toDate()
|
|
@@ -111,7 +111,8 @@ export declare class MongoRepository {
|
|
|
111
111
|
$in: T[];
|
|
112
112
|
};
|
|
113
113
|
status: factory.transactionStatusType;
|
|
114
|
-
|
|
114
|
+
id?: string;
|
|
115
|
+
}): Promise<Pick<factory.transaction.ITransaction<T>, 'id' | 'typeOf'> | null>;
|
|
115
116
|
/**
|
|
116
117
|
* タスクエクスポートリトライ
|
|
117
118
|
* TODO updatedAtを基準にしているが、タスクエクスポートトライ日時を持たせた方が安全か?
|
|
@@ -453,14 +453,14 @@ class MongoRepository {
|
|
|
453
453
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
454
454
|
*/
|
|
455
455
|
startExportTasks(params) {
|
|
456
|
+
var _a;
|
|
456
457
|
return __awaiter(this, void 0, void 0, function* () {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
? { typeOf: { $in: params.typeOf.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
458
|
+
const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
|
|
459
|
+
return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.project !== undefined) ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
460
|
+
.select({
|
|
461
|
+
_id: 1,
|
|
462
|
+
typeOf: 1
|
|
463
|
+
})
|
|
464
464
|
.exec()
|
|
465
465
|
// tslint:disable-next-line:no-null-keyword
|
|
466
466
|
.then((doc) => (doc === null) ? null : doc.toObject());
|
|
@@ -492,7 +492,7 @@ class MongoRepository {
|
|
|
492
492
|
*/
|
|
493
493
|
setTasksExportedById(params) {
|
|
494
494
|
return __awaiter(this, void 0, void 0, function* () {
|
|
495
|
-
yield this.transactionModel.
|
|
495
|
+
yield this.transactionModel.updateOne({ _id: { $eq: params.id } }, {
|
|
496
496
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
497
497
|
tasksExportedAt: new Date()
|
|
498
498
|
})
|
|
@@ -77,15 +77,10 @@ exports.updateAgent = updateAgent;
|
|
|
77
77
|
*/
|
|
78
78
|
function exportTasks(params) {
|
|
79
79
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
const transaction = yield repos.transaction.startExportTasks({
|
|
81
|
-
project: params.project,
|
|
82
|
-
typeOf: params.typeOf,
|
|
83
|
-
status: params.status
|
|
84
|
-
});
|
|
80
|
+
const transaction = yield repos.transaction.startExportTasks(Object.assign({ project: params.project, typeOf: params.typeOf, status: params.status }, (typeof params.id === 'string') ? { id: params.id } : undefined));
|
|
85
81
|
if (transaction === null) {
|
|
86
82
|
return;
|
|
87
83
|
}
|
|
88
|
-
// let tasks: factory.task.ITask<factory.taskName>[] = [];
|
|
89
84
|
// 失敗してもここでは戻さない(RUNNINGのまま待機)
|
|
90
85
|
switch (transaction.typeOf) {
|
|
91
86
|
case factory.transactionType.MoneyTransfer:
|
|
@@ -109,7 +104,6 @@ function exportTasks(params) {
|
|
|
109
104
|
default:
|
|
110
105
|
}
|
|
111
106
|
yield repos.transaction.setTasksExportedById({ id: transaction.id });
|
|
112
|
-
// return tasks;
|
|
113
107
|
});
|
|
114
108
|
}
|
|
115
109
|
exports.exportTasks = exportTasks;
|
package/package.json
CHANGED