@chevre/domain 21.2.0-alpha.17 → 21.2.0-alpha.19
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/makeExpired.ts +18 -0
- package/example/src/chevre/updateTransaction.ts +1 -1
- package/lib/chevre/repo/assetTransaction.d.ts +2 -5
- package/lib/chevre/repo/assetTransaction.js +58 -34
- package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/action.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/authorization.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/comments.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/order.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/reservation.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/task.js +1 -1
- package/lib/chevre/repo/mongoose/schemas/transaction.js +1 -1
- package/lib/chevre/repo/transaction.d.ts +1 -1
- package/lib/chevre/repo/transaction.js +99 -42
- package/lib/chevre/service/assetTransaction/pay.js +1 -1
- package/lib/chevre/service/payment/any.js +1 -1
- package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
- package/package.json +1 -1
- package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
|
@@ -0,0 +1,18 @@
|
|
|
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.makeExpired({
|
|
11
|
+
expires: new Date()
|
|
12
|
+
});
|
|
13
|
+
console.log(result);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
main()
|
|
17
|
+
.then(console.log)
|
|
18
|
+
.catch(console.error);
|
|
@@ -64,9 +64,6 @@ export declare class MongoRepository {
|
|
|
64
64
|
typeOf: T;
|
|
65
65
|
transactionNumber: string;
|
|
66
66
|
}): Promise<factory.assetTransaction.ITransaction<T>>;
|
|
67
|
-
/**
|
|
68
|
-
* 取引を確定する
|
|
69
|
-
*/
|
|
70
67
|
addReservations(params: {
|
|
71
68
|
typeOf: factory.assetTransactionType.Reserve;
|
|
72
69
|
id: string;
|
|
@@ -80,7 +77,7 @@ export declare class MongoRepository {
|
|
|
80
77
|
id: string;
|
|
81
78
|
result: factory.assetTransaction.IResult<T>;
|
|
82
79
|
potentialActions: factory.assetTransaction.IPotentialActions<T>;
|
|
83
|
-
}): Promise<
|
|
80
|
+
}): Promise<void>;
|
|
84
81
|
/**
|
|
85
82
|
* 取引を開始&確定
|
|
86
83
|
*/
|
|
@@ -160,7 +157,7 @@ export declare class MongoRepository {
|
|
|
160
157
|
/**
|
|
161
158
|
* 特定の取引を更新する(汎用)
|
|
162
159
|
*/
|
|
163
|
-
|
|
160
|
+
findByIdAndUpdateInProgress<T extends factory.assetTransactionType>(params: {
|
|
164
161
|
id: string;
|
|
165
162
|
update: any;
|
|
166
163
|
}): Promise<factory.assetTransaction.ITransaction<T>>;
|
|
@@ -277,15 +277,12 @@ class MongoRepository {
|
|
|
277
277
|
return doc.toObject();
|
|
278
278
|
});
|
|
279
279
|
}
|
|
280
|
-
/**
|
|
281
|
-
* 取引を確定する
|
|
282
|
-
*/
|
|
283
280
|
addReservations(params) {
|
|
284
281
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
282
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
286
|
-
_id: params.id,
|
|
287
|
-
typeOf: params.typeOf,
|
|
288
|
-
status: factory.transactionStatusType.InProgress
|
|
283
|
+
_id: { $eq: params.id },
|
|
284
|
+
typeOf: { $eq: params.typeOf },
|
|
285
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
289
286
|
}, {
|
|
290
287
|
'object.acceptedOffer': params.object.acceptedOffer,
|
|
291
288
|
// 念のため残す(2021/10/14)が、そのうち削除
|
|
@@ -310,22 +307,24 @@ class MongoRepository {
|
|
|
310
307
|
confirm(params) {
|
|
311
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
312
309
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
313
|
-
_id: params.id,
|
|
314
|
-
typeOf: params.typeOf,
|
|
315
|
-
status: factory.transactionStatusType.InProgress
|
|
310
|
+
_id: { $eq: params.id },
|
|
311
|
+
typeOf: { $eq: params.typeOf },
|
|
312
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
316
313
|
}, {
|
|
317
314
|
status: factory.transactionStatusType.Confirmed,
|
|
318
315
|
endDate: new Date(),
|
|
319
316
|
result: params.result,
|
|
320
317
|
potentialActions: params.potentialActions // resultを更新
|
|
321
|
-
}, {
|
|
318
|
+
}, {
|
|
319
|
+
new: true,
|
|
320
|
+
projection: { _id: 1 }
|
|
321
|
+
})
|
|
322
322
|
.exec();
|
|
323
323
|
// NotFoundであれば取引状態確認
|
|
324
324
|
if (doc === null) {
|
|
325
325
|
const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
|
|
326
326
|
if (transaction.status === factory.transactionStatusType.Confirmed) {
|
|
327
|
-
//
|
|
328
|
-
return transaction;
|
|
327
|
+
// すでに確定済の場合スルー
|
|
329
328
|
}
|
|
330
329
|
else if (transaction.status === factory.transactionStatusType.Expired) {
|
|
331
330
|
throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
|
|
@@ -337,7 +336,6 @@ class MongoRepository {
|
|
|
337
336
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
338
337
|
}
|
|
339
338
|
}
|
|
340
|
-
return doc.toObject();
|
|
341
339
|
});
|
|
342
340
|
}
|
|
343
341
|
/**
|
|
@@ -355,8 +353,14 @@ class MongoRepository {
|
|
|
355
353
|
startExportTasks(params) {
|
|
356
354
|
var _a, _b;
|
|
357
355
|
return __awaiter(this, void 0, void 0, function* () {
|
|
356
|
+
switch (params.status) {
|
|
357
|
+
case factory.transactionStatusType.InProgress:
|
|
358
|
+
throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
|
|
359
|
+
default:
|
|
360
|
+
// no op
|
|
361
|
+
}
|
|
358
362
|
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 })
|
|
363
|
+
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: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
360
364
|
.select({
|
|
361
365
|
_id: 1,
|
|
362
366
|
typeOf: 1
|
|
@@ -374,7 +378,7 @@ class MongoRepository {
|
|
|
374
378
|
reexportTasks(params) {
|
|
375
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
376
380
|
yield this.transactionModel.updateMany({
|
|
377
|
-
tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
|
|
381
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
378
382
|
updatedAt: {
|
|
379
383
|
$lt: moment()
|
|
380
384
|
.add(-params.intervalInMinutes, 'minutes')
|
|
@@ -392,10 +396,12 @@ class MongoRepository {
|
|
|
392
396
|
*/
|
|
393
397
|
setTasksExportedById(params) {
|
|
394
398
|
return __awaiter(this, void 0, void 0, function* () {
|
|
395
|
-
yield this.transactionModel.updateOne({
|
|
399
|
+
yield this.transactionModel.updateOne({
|
|
400
|
+
_id: { $eq: params.id },
|
|
401
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
402
|
+
}, {
|
|
396
403
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
397
|
-
tasksExportedAt:
|
|
398
|
-
.toDate()
|
|
404
|
+
tasksExportedAt: new Date()
|
|
399
405
|
})
|
|
400
406
|
.exec();
|
|
401
407
|
});
|
|
@@ -405,15 +411,29 @@ class MongoRepository {
|
|
|
405
411
|
*/
|
|
406
412
|
makeExpired(params) {
|
|
407
413
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
-
//
|
|
409
|
-
yield this.transactionModel.
|
|
410
|
-
status: factory.transactionStatusType.InProgress,
|
|
414
|
+
// IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
415
|
+
const expiringTransactions = yield this.transactionModel.find({
|
|
416
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
411
417
|
expires: { $lt: params.expires }
|
|
412
|
-
}, {
|
|
413
|
-
status: factory.transactionStatusType.Expired,
|
|
414
|
-
endDate: new Date()
|
|
415
418
|
})
|
|
419
|
+
.select({
|
|
420
|
+
_id: 1,
|
|
421
|
+
typeOf: 1
|
|
422
|
+
})
|
|
423
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
416
424
|
.exec();
|
|
425
|
+
if (expiringTransactions.length > 0) {
|
|
426
|
+
// ステータスと期限を見て更新
|
|
427
|
+
yield this.transactionModel.updateMany({
|
|
428
|
+
_id: { $in: expiringTransactions.map((t) => t.id) },
|
|
429
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
430
|
+
expires: { $lt: params.expires }
|
|
431
|
+
}, {
|
|
432
|
+
status: factory.transactionStatusType.Expired,
|
|
433
|
+
endDate: new Date()
|
|
434
|
+
})
|
|
435
|
+
.exec();
|
|
436
|
+
}
|
|
417
437
|
});
|
|
418
438
|
}
|
|
419
439
|
/**
|
|
@@ -421,19 +441,18 @@ class MongoRepository {
|
|
|
421
441
|
*/
|
|
422
442
|
cancel(params) {
|
|
423
443
|
return __awaiter(this, void 0, void 0, function* () {
|
|
424
|
-
const endDate =
|
|
425
|
-
.toDate();
|
|
444
|
+
const endDate = new Date();
|
|
426
445
|
// 進行中ステータスの取引を中止する
|
|
427
|
-
const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: params.typeOf }, (typeof params.id === 'string') ? { _id: params.id } : undefined), (typeof params.transactionNumber === 'string')
|
|
446
|
+
const doc = yield this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({ typeOf: { $eq: params.typeOf } }, (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), (typeof params.transactionNumber === 'string')
|
|
428
447
|
? { transactionNumber: { $exists: true, $eq: params.transactionNumber } }
|
|
429
|
-
: undefined), { status: factory.transactionStatusType.InProgress }), {
|
|
448
|
+
: undefined), { status: { $eq: factory.transactionStatusType.InProgress } }), {
|
|
430
449
|
status: factory.transactionStatusType.Canceled,
|
|
431
450
|
endDate: endDate
|
|
432
451
|
}, { new: true })
|
|
433
452
|
.exec();
|
|
453
|
+
let transaction;
|
|
434
454
|
// NotFoundであれば取引状態確認
|
|
435
455
|
if (doc === null) {
|
|
436
|
-
let transaction;
|
|
437
456
|
if (typeof params.id === 'string') {
|
|
438
457
|
transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
|
|
439
458
|
}
|
|
@@ -447,8 +466,7 @@ class MongoRepository {
|
|
|
447
466
|
throw new factory.errors.ArgumentNull('Transaction ID or Transaction Number');
|
|
448
467
|
}
|
|
449
468
|
if (transaction.status === factory.transactionStatusType.Canceled) {
|
|
450
|
-
//
|
|
451
|
-
return transaction;
|
|
469
|
+
// すでに中止済の場合スルー
|
|
452
470
|
}
|
|
453
471
|
else if (transaction.status === factory.transactionStatusType.Expired) {
|
|
454
472
|
throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
|
|
@@ -460,7 +478,10 @@ class MongoRepository {
|
|
|
460
478
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
461
479
|
}
|
|
462
480
|
}
|
|
463
|
-
|
|
481
|
+
else {
|
|
482
|
+
transaction = doc.toObject();
|
|
483
|
+
}
|
|
484
|
+
return transaction;
|
|
464
485
|
});
|
|
465
486
|
}
|
|
466
487
|
count(params) {
|
|
@@ -522,9 +543,12 @@ class MongoRepository {
|
|
|
522
543
|
/**
|
|
523
544
|
* 特定の取引を更新する(汎用)
|
|
524
545
|
*/
|
|
525
|
-
|
|
546
|
+
findByIdAndUpdateInProgress(params) {
|
|
526
547
|
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
-
return this.transactionModel.findOneAndUpdate({
|
|
548
|
+
return this.transactionModel.findOneAndUpdate({
|
|
549
|
+
_id: { $eq: params.id },
|
|
550
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
551
|
+
}, params.update, { new: true })
|
|
528
552
|
.exec()
|
|
529
553
|
.then((doc) => {
|
|
530
554
|
if (doc === null) {
|
|
@@ -344,9 +344,9 @@ class MongoRepository {
|
|
|
344
344
|
var _a, _b;
|
|
345
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
346
346
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
347
|
-
_id: params.id,
|
|
348
|
-
typeOf: params.typeOf,
|
|
349
|
-
status: factory.transactionStatusType.InProgress
|
|
347
|
+
_id: { $eq: params.id },
|
|
348
|
+
typeOf: { $eq: params.typeOf },
|
|
349
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
350
350
|
}, {
|
|
351
351
|
$set: Object.assign(Object.assign({ 'agent.id': params.agent.id }, (typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined), (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { 'object.customer': params.object.customer } : undefined)
|
|
352
352
|
}, {
|
|
@@ -364,9 +364,9 @@ class MongoRepository {
|
|
|
364
364
|
updateExpires(params) {
|
|
365
365
|
return __awaiter(this, void 0, void 0, function* () {
|
|
366
366
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
367
|
-
_id: params.id,
|
|
368
|
-
typeOf: params.typeOf,
|
|
369
|
-
status: factory.transactionStatusType.InProgress
|
|
367
|
+
_id: { $eq: params.id },
|
|
368
|
+
typeOf: { $eq: params.typeOf },
|
|
369
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
370
370
|
}, {
|
|
371
371
|
$set: {
|
|
372
372
|
expires: params.expires
|
|
@@ -388,9 +388,9 @@ class MongoRepository {
|
|
|
388
388
|
var _a;
|
|
389
389
|
return __awaiter(this, void 0, void 0, function* () {
|
|
390
390
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
391
|
-
_id: params.id,
|
|
392
|
-
typeOf: params.typeOf,
|
|
393
|
-
status: factory.transactionStatusType.InProgress
|
|
391
|
+
_id: { $eq: params.id },
|
|
392
|
+
typeOf: { $eq: params.typeOf },
|
|
393
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
394
394
|
}, {
|
|
395
395
|
$set: Object.assign({}, (typeof ((_a = params.object) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? { 'object.name': params.object.name } : undefined)
|
|
396
396
|
}, {
|
|
@@ -408,9 +408,9 @@ class MongoRepository {
|
|
|
408
408
|
confirm(params) {
|
|
409
409
|
return __awaiter(this, void 0, void 0, function* () {
|
|
410
410
|
const doc = yield this.transactionModel.findOneAndUpdate({
|
|
411
|
-
_id: params.id,
|
|
412
|
-
typeOf: params.typeOf,
|
|
413
|
-
status: factory.transactionStatusType.InProgress
|
|
411
|
+
_id: { $eq: params.id },
|
|
412
|
+
typeOf: { $eq: params.typeOf },
|
|
413
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
414
414
|
}, {
|
|
415
415
|
status: factory.transactionStatusType.Confirmed,
|
|
416
416
|
endDate: new Date(),
|
|
@@ -425,23 +425,14 @@ class MongoRepository {
|
|
|
425
425
|
// NotFoundであれば取引状態確認
|
|
426
426
|
if (doc === null) {
|
|
427
427
|
const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
|
|
428
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
429
|
-
/* istanbul ignore next */
|
|
430
428
|
if (transaction.status === factory.transactionStatusType.Confirmed) {
|
|
431
|
-
//
|
|
432
|
-
return;
|
|
433
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
434
|
-
/* istanbul ignore next */
|
|
429
|
+
// すでに確定済の場合スルー
|
|
435
430
|
}
|
|
436
431
|
else if (transaction.status === factory.transactionStatusType.Expired) {
|
|
437
432
|
throw new factory.errors.Argument('Transaction id', 'Already expired');
|
|
438
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
439
|
-
/* istanbul ignore next */
|
|
440
433
|
}
|
|
441
434
|
else if (transaction.status === factory.transactionStatusType.Canceled) {
|
|
442
435
|
throw new factory.errors.Argument('Transaction id', 'Already canceled');
|
|
443
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
444
|
-
/* istanbul ignore next */
|
|
445
436
|
}
|
|
446
437
|
else {
|
|
447
438
|
throw new factory.errors.NotFound(this.transactionModel.modelName);
|
|
@@ -460,8 +451,14 @@ class MongoRepository {
|
|
|
460
451
|
startExportTasks(params) {
|
|
461
452
|
var _a;
|
|
462
453
|
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
+
switch (params.status) {
|
|
455
|
+
case factory.transactionStatusType.InProgress:
|
|
456
|
+
throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
|
|
457
|
+
default:
|
|
458
|
+
// no op
|
|
459
|
+
}
|
|
463
460
|
const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
|
|
464
|
-
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 })
|
|
461
|
+
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: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
|
|
465
462
|
.select({
|
|
466
463
|
_id: 1,
|
|
467
464
|
typeOf: 1
|
|
@@ -478,17 +475,51 @@ class MongoRepository {
|
|
|
478
475
|
*/
|
|
479
476
|
reexportTasks(params) {
|
|
480
477
|
return __awaiter(this, void 0, void 0, function* () {
|
|
481
|
-
yield this.transactionModel.
|
|
482
|
-
tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
|
|
478
|
+
const reexportingTransactions = yield this.transactionModel.find({
|
|
479
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
483
480
|
updatedAt: {
|
|
484
481
|
$lt: moment()
|
|
485
482
|
.add(-params.intervalInMinutes, 'minutes')
|
|
486
483
|
.toDate()
|
|
487
484
|
}
|
|
488
|
-
}, {
|
|
489
|
-
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
490
485
|
})
|
|
486
|
+
.select({
|
|
487
|
+
_id: 1,
|
|
488
|
+
typeOf: 1,
|
|
489
|
+
status: 1
|
|
490
|
+
})
|
|
491
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
491
492
|
.exec();
|
|
493
|
+
if (reexportingTransactions.length > 0) {
|
|
494
|
+
for (const reexportingTransaction of reexportingTransactions) {
|
|
495
|
+
yield this.transactionModel.updateOne({
|
|
496
|
+
_id: { $eq: reexportingTransaction.id },
|
|
497
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
498
|
+
}, {
|
|
499
|
+
tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
500
|
+
})
|
|
501
|
+
.exec();
|
|
502
|
+
transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
|
|
503
|
+
id: reexportingTransaction.id,
|
|
504
|
+
typeOf: reexportingTransaction.typeOf,
|
|
505
|
+
status: reexportingTransaction.status
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
// await this.transactionModel.updateMany(
|
|
510
|
+
// {
|
|
511
|
+
// tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
|
|
512
|
+
// updatedAt: {
|
|
513
|
+
// $lt: moment()
|
|
514
|
+
// .add(-params.intervalInMinutes, 'minutes')
|
|
515
|
+
// .toDate()
|
|
516
|
+
// }
|
|
517
|
+
// },
|
|
518
|
+
// {
|
|
519
|
+
// tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
|
|
520
|
+
// }
|
|
521
|
+
// )
|
|
522
|
+
// .exec();
|
|
492
523
|
});
|
|
493
524
|
}
|
|
494
525
|
/**
|
|
@@ -497,7 +528,10 @@ class MongoRepository {
|
|
|
497
528
|
*/
|
|
498
529
|
setTasksExportedById(params) {
|
|
499
530
|
return __awaiter(this, void 0, void 0, function* () {
|
|
500
|
-
yield this.transactionModel.updateOne({
|
|
531
|
+
yield this.transactionModel.updateOne({
|
|
532
|
+
_id: { $eq: params.id },
|
|
533
|
+
tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
|
|
534
|
+
}, {
|
|
501
535
|
tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
|
|
502
536
|
tasksExportedAt: new Date()
|
|
503
537
|
})
|
|
@@ -509,15 +543,36 @@ class MongoRepository {
|
|
|
509
543
|
*/
|
|
510
544
|
makeExpired(params) {
|
|
511
545
|
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
//
|
|
513
|
-
yield this.transactionModel.
|
|
514
|
-
status: factory.transactionStatusType.InProgress,
|
|
546
|
+
// IDをemitしたいのでまずリスト検索(2023-04-27~)
|
|
547
|
+
const expiringTransactions = yield this.transactionModel.find({
|
|
548
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
515
549
|
expires: { $lt: params.expires }
|
|
516
|
-
}, {
|
|
517
|
-
status: factory.transactionStatusType.Expired,
|
|
518
|
-
endDate: new Date()
|
|
519
550
|
})
|
|
551
|
+
.select({
|
|
552
|
+
_id: 1,
|
|
553
|
+
typeOf: 1
|
|
554
|
+
})
|
|
555
|
+
.setOptions({ maxTimeMS: 10000 })
|
|
520
556
|
.exec();
|
|
557
|
+
if (expiringTransactions.length > 0) {
|
|
558
|
+
// ステータスと期限を見て更新
|
|
559
|
+
yield this.transactionModel.updateMany({
|
|
560
|
+
_id: { $in: expiringTransactions.map((t) => t.id) },
|
|
561
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
562
|
+
expires: { $lt: params.expires }
|
|
563
|
+
}, {
|
|
564
|
+
status: factory.transactionStatusType.Expired,
|
|
565
|
+
endDate: new Date()
|
|
566
|
+
})
|
|
567
|
+
.exec();
|
|
568
|
+
expiringTransactions.forEach((expiringTransaction) => {
|
|
569
|
+
transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
|
|
570
|
+
id: expiringTransaction.id,
|
|
571
|
+
typeOf: expiringTransaction.typeOf,
|
|
572
|
+
status: factory.transactionStatusType.Expired
|
|
573
|
+
});
|
|
574
|
+
});
|
|
575
|
+
}
|
|
521
576
|
});
|
|
522
577
|
}
|
|
523
578
|
/**
|
|
@@ -542,11 +597,8 @@ class MongoRepository {
|
|
|
542
597
|
// NotFoundであれば取引状態確認
|
|
543
598
|
if (doc === null) {
|
|
544
599
|
const transaction = yield this.findById(params);
|
|
545
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
546
|
-
/* istanbul ignore next */
|
|
547
600
|
if (transaction.status === factory.transactionStatusType.Canceled) {
|
|
548
|
-
//
|
|
549
|
-
return;
|
|
601
|
+
// すでに中止済の場合スルー
|
|
550
602
|
}
|
|
551
603
|
else if (transaction.status === factory.transactionStatusType.Expired) {
|
|
552
604
|
throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
|
|
@@ -620,9 +672,12 @@ class MongoRepository {
|
|
|
620
672
|
/**
|
|
621
673
|
* 特定の取引を更新する(汎用)
|
|
622
674
|
*/
|
|
623
|
-
|
|
675
|
+
findByIdAndUpdateInProgress(params) {
|
|
624
676
|
return __awaiter(this, void 0, void 0, function* () {
|
|
625
|
-
yield this.transactionModel.findOneAndUpdate({
|
|
677
|
+
yield this.transactionModel.findOneAndUpdate({
|
|
678
|
+
_id: { $eq: params.id },
|
|
679
|
+
status: { $eq: factory.transactionStatusType.InProgress }
|
|
680
|
+
}, params.update, {
|
|
626
681
|
// new: true,
|
|
627
682
|
projection: { _id: 1 }
|
|
628
683
|
})
|
|
@@ -637,7 +692,8 @@ class MongoRepository {
|
|
|
637
692
|
saveOrderNumberIfNotExist(params) {
|
|
638
693
|
return __awaiter(this, void 0, void 0, function* () {
|
|
639
694
|
yield this.transactionModel.updateOne({
|
|
640
|
-
_id: params.id,
|
|
695
|
+
_id: { $eq: params.id },
|
|
696
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
641
697
|
'object.orderNumber': { $exists: false }
|
|
642
698
|
}, { 'object.orderNumber': params.orderNumber })
|
|
643
699
|
.exec();
|
|
@@ -646,7 +702,8 @@ class MongoRepository {
|
|
|
646
702
|
saveConfirmationNumberIfNotExist(params) {
|
|
647
703
|
return __awaiter(this, void 0, void 0, function* () {
|
|
648
704
|
yield this.transactionModel.updateOne({
|
|
649
|
-
_id: params.id,
|
|
705
|
+
_id: { $eq: params.id },
|
|
706
|
+
status: { $eq: factory.transactionStatusType.InProgress },
|
|
650
707
|
'object.confirmationNumber': { $exists: false }
|
|
651
708
|
}, { 'object.confirmationNumber': params.confirmationNumber })
|
|
652
709
|
.exec();
|
|
@@ -281,7 +281,7 @@ function processAuthorizeMovieTicket(params, transaction, paymentServiceId, useC
|
|
|
281
281
|
}
|
|
282
282
|
function saveAuthorizeResult(params) {
|
|
283
283
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
return repos.assetTransaction.
|
|
284
|
+
return repos.assetTransaction.findByIdAndUpdateInProgress(params);
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
/**
|
|
@@ -194,7 +194,7 @@ function publishPaymentUrl(params) {
|
|
|
194
194
|
paymentUrl: result.paymentUrl,
|
|
195
195
|
issuedThrough: { id: (typeof startParams.object.id === 'string') ? startParams.object.id : '' }
|
|
196
196
|
};
|
|
197
|
-
yield repos.transaction.
|
|
197
|
+
yield repos.transaction.findByIdAndUpdateInProgress({
|
|
198
198
|
id: transaction.id,
|
|
199
199
|
update: { $set: { 'object.paymentMethods': paymentMethodByPaymentUrl } }
|
|
200
200
|
});
|
|
@@ -311,7 +311,7 @@ function authorizeAward(params) {
|
|
|
311
311
|
if (Array.isArray(givePointAwardParams)) {
|
|
312
312
|
const pointAwardIdentifiers = givePointAwardParams.map((g) => { var _a; return String((_a = g.object) === null || _a === void 0 ? void 0 : _a.identifier); });
|
|
313
313
|
// 取引にインセンティブ付与アクションパラメータを保管する
|
|
314
|
-
yield repos.transaction.
|
|
314
|
+
yield repos.transaction.findByIdAndUpdateInProgress({
|
|
315
315
|
id: transaction.id,
|
|
316
316
|
update: {
|
|
317
317
|
$set: {
|
|
@@ -339,7 +339,7 @@ function voidAward(params) {
|
|
|
339
339
|
if (transaction.agent.id !== params.agent.id) {
|
|
340
340
|
throw new factory.errors.Forbidden('Transaction not yours');
|
|
341
341
|
}
|
|
342
|
-
yield repos.transaction.
|
|
342
|
+
yield repos.transaction.findByIdAndUpdateInProgress({
|
|
343
343
|
id: transaction.id,
|
|
344
344
|
update: {
|
|
345
345
|
$unset: {
|
package/package.json
CHANGED
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
// tslint:disable-next-line:max-func-body-length
|
|
10
|
-
async function main() {
|
|
11
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
-
|
|
13
|
-
const accountTransactionRepo = new chevre.repository.AccountTransaction(mongoose.connection);
|
|
14
|
-
const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = assetTransactionRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
'project.id': { $eq: project.id },
|
|
19
|
-
typeOf: { $eq: chevre.factory.assetTransactionType.MoneyTransfer },
|
|
20
|
-
startDate: {
|
|
21
|
-
$gte: moment('2023-02-17T15:00:00Z')
|
|
22
|
-
.toDate()
|
|
23
|
-
}
|
|
24
|
-
// _id: { $eq: 'al6aff83w' }
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
// _id: 1,
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
console.log('assetTransactions found');
|
|
31
|
-
|
|
32
|
-
let i = 0;
|
|
33
|
-
let updateCount = 0;
|
|
34
|
-
// tslint:disable-next-line:max-func-body-length
|
|
35
|
-
await cursor.eachAsync(async (doc) => {
|
|
36
|
-
i += 1;
|
|
37
|
-
const moneyTransferTransaction: chevre.factory.assetTransaction.moneyTransfer.ITransaction = doc.toObject();
|
|
38
|
-
|
|
39
|
-
const description = moneyTransferTransaction.object.description;
|
|
40
|
-
if (description !== '鑑賞' && description !== '受け取り') {
|
|
41
|
-
console.log(
|
|
42
|
-
'no operation needed',
|
|
43
|
-
description,
|
|
44
|
-
moneyTransferTransaction.project.id,
|
|
45
|
-
moneyTransferTransaction.transactionNumber,
|
|
46
|
-
moneyTransferTransaction.startDate
|
|
47
|
-
);
|
|
48
|
-
} else {
|
|
49
|
-
const pendingTransactionIdentifier = moneyTransferTransaction.object.pendingTransaction?.identifier;
|
|
50
|
-
if (typeof pendingTransactionIdentifier === 'string' && pendingTransactionIdentifier.length > 0) {
|
|
51
|
-
console.log(
|
|
52
|
-
'pendingTransactionIdentifier found',
|
|
53
|
-
description,
|
|
54
|
-
moneyTransferTransaction.project.id,
|
|
55
|
-
moneyTransferTransaction.transactionNumber,
|
|
56
|
-
moneyTransferTransaction.startDate
|
|
57
|
-
);
|
|
58
|
-
} else {
|
|
59
|
-
// 口座取引からidentifierを取得
|
|
60
|
-
const accountTransaction =
|
|
61
|
-
await accountTransactionRepo.findByTransactionNumber({ transactionNumber: moneyTransferTransaction.transactionNumber });
|
|
62
|
-
console.log(
|
|
63
|
-
'updating identifier...',
|
|
64
|
-
accountTransaction.identifier,
|
|
65
|
-
description,
|
|
66
|
-
moneyTransferTransaction.project.id,
|
|
67
|
-
moneyTransferTransaction.transactionNumber,
|
|
68
|
-
moneyTransferTransaction.startDate
|
|
69
|
-
);
|
|
70
|
-
if (typeof accountTransaction.identifier === 'string') {
|
|
71
|
-
await assetTransactionRepo.findByIdAndUpdate({
|
|
72
|
-
id: moneyTransferTransaction.id,
|
|
73
|
-
update: {
|
|
74
|
-
'object.pendingTransaction.identifier': accountTransaction.identifier
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
console.log(
|
|
79
|
-
'ientifier updated',
|
|
80
|
-
accountTransaction.identifier,
|
|
81
|
-
description,
|
|
82
|
-
moneyTransferTransaction.project.id,
|
|
83
|
-
moneyTransferTransaction.transactionNumber,
|
|
84
|
-
moneyTransferTransaction.startDate
|
|
85
|
-
);
|
|
86
|
-
updateCount += 1;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
console.log(i, 'assetTransactions checked');
|
|
91
|
-
console.log(updateCount, 'assetTransactions updated');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
main()
|
|
95
|
-
.then()
|
|
96
|
-
.catch(console.error);
|