@chevre/domain 22.9.0-alpha.64 → 22.9.0-alpha.65
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/findExportableTransaction.ts +41 -0
- package/lib/chevre/repo/mongoose/schemas/transaction.js +10 -0
- package/lib/chevre/repo/transaction.d.ts +16 -0
- package/lib/chevre/repo/transaction.js +53 -8
- package/lib/chevre/service/transaction.d.ts +4 -0
- package/lib/chevre/service/transaction.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
11
|
+
|
|
12
|
+
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
setInterval(
|
|
15
|
+
async () => {
|
|
16
|
+
const startTime = process.hrtime();
|
|
17
|
+
const transaction = await transactionRepo.findExportableTransaction({
|
|
18
|
+
// status: { $eq: params.status },
|
|
19
|
+
// id: params.id,
|
|
20
|
+
endDate: {
|
|
21
|
+
$lt: moment()
|
|
22
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
23
|
+
.add(-60, 'seconds')
|
|
24
|
+
.toDate()
|
|
25
|
+
},
|
|
26
|
+
sort: { endDate: chevre.factory.sortType.Ascending }
|
|
27
|
+
});
|
|
28
|
+
const diff = process.hrtime(startTime);
|
|
29
|
+
console.log(`took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
|
|
30
|
+
|
|
31
|
+
// tslint:disable-next-line:no-null-keyword
|
|
32
|
+
console.dir(transaction?.id, { depth: null });
|
|
33
|
+
},
|
|
34
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
35
|
+
1000
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main()
|
|
40
|
+
.then()
|
|
41
|
+
.catch(console.error);
|
|
@@ -193,6 +193,16 @@ const indexes = [
|
|
|
193
193
|
{ status: 1, expires: 1 },
|
|
194
194
|
{ name: 'makeExpired' }
|
|
195
195
|
],
|
|
196
|
+
[
|
|
197
|
+
{ status: 1, 'tasksExportAction.actionStatus': 1, endDate: 1 },
|
|
198
|
+
{
|
|
199
|
+
name: 'exportTasksIfExists',
|
|
200
|
+
partialFilterExpression: {
|
|
201
|
+
'tasksExportAction.actionStatus': { $exists: true },
|
|
202
|
+
endDate: { $exists: true }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
],
|
|
196
206
|
[
|
|
197
207
|
{ 'tasksExportAction.actionStatus': 1, startDate: -1 },
|
|
198
208
|
{
|
|
@@ -123,6 +123,22 @@ export declare class TransactionRepo {
|
|
|
123
123
|
endDate: {
|
|
124
124
|
$lt: Date;
|
|
125
125
|
};
|
|
126
|
+
sort?: {
|
|
127
|
+
endDate?: factory.sortType;
|
|
128
|
+
startDate?: factory.sortType;
|
|
129
|
+
};
|
|
130
|
+
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
|
|
131
|
+
findExportableTransaction(params: {
|
|
132
|
+
status?: {
|
|
133
|
+
$eq?: factory.transactionStatusType;
|
|
134
|
+
};
|
|
135
|
+
endDate: {
|
|
136
|
+
$lt: Date;
|
|
137
|
+
};
|
|
138
|
+
sort?: {
|
|
139
|
+
endDate?: factory.sortType;
|
|
140
|
+
startDate?: factory.sortType;
|
|
141
|
+
};
|
|
126
142
|
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
|
|
127
143
|
reexportTasksByExportAction(params: {
|
|
128
144
|
intervalInMinutes: number;
|
|
@@ -553,7 +553,7 @@ class TransactionRepo {
|
|
|
553
553
|
*/
|
|
554
554
|
startExportTasks(params) {
|
|
555
555
|
return __awaiter(this, void 0, void 0, function* () {
|
|
556
|
-
var _a, _b;
|
|
556
|
+
var _a, _b, _c, _d;
|
|
557
557
|
const statusEq = (_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
558
558
|
const endDateLt = (_b = params.endDate) === null || _b === void 0 ? void 0 : _b.$lt;
|
|
559
559
|
if (typeof statusEq === 'string') {
|
|
@@ -567,11 +567,7 @@ class TransactionRepo {
|
|
|
567
567
|
if (!(endDateLt instanceof Date)) {
|
|
568
568
|
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
569
569
|
}
|
|
570
|
-
|
|
571
|
-
const sort = {
|
|
572
|
-
startDate: factory.sortType.Ascending
|
|
573
|
-
};
|
|
574
|
-
return this.transactionModel.findOneAndUpdate(Object.assign({
|
|
570
|
+
const query = this.transactionModel.findOneAndUpdate(Object.assign({
|
|
575
571
|
// ...(Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined,
|
|
576
572
|
status: Object.assign({}, (typeof statusEq === 'string')
|
|
577
573
|
? { $eq: statusEq }
|
|
@@ -596,8 +592,57 @@ class TransactionRepo {
|
|
|
596
592
|
id: { $toString: '$_id' },
|
|
597
593
|
typeOf: 1
|
|
598
594
|
}
|
|
599
|
-
})
|
|
600
|
-
|
|
595
|
+
});
|
|
596
|
+
if (typeof ((_c = params.sort) === null || _c === void 0 ? void 0 : _c.endDate) === 'number' || typeof ((_d = params.sort) === null || _d === void 0 ? void 0 : _d.startDate) === 'number') {
|
|
597
|
+
query.sort(params.sort);
|
|
598
|
+
}
|
|
599
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
600
|
+
.lean() // 2024-08-26~
|
|
601
|
+
.exec()
|
|
602
|
+
// tslint:disable-next-line:no-null-keyword
|
|
603
|
+
.then((doc) => (doc === null) ? null : doc);
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
findExportableTransaction(params) {
|
|
607
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
608
|
+
var _a, _b, _c, _d;
|
|
609
|
+
const statusEq = (_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
610
|
+
const endDateLt = (_b = params.endDate) === null || _b === void 0 ? void 0 : _b.$lt;
|
|
611
|
+
if (typeof statusEq === 'string') {
|
|
612
|
+
switch (statusEq) {
|
|
613
|
+
case factory.transactionStatusType.InProgress:
|
|
614
|
+
throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
|
|
615
|
+
default:
|
|
616
|
+
// no op
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (!(endDateLt instanceof Date)) {
|
|
620
|
+
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
621
|
+
}
|
|
622
|
+
const query = this.transactionModel.findOne({
|
|
623
|
+
status: Object.assign({}, (typeof statusEq === 'string')
|
|
624
|
+
? { $eq: statusEq }
|
|
625
|
+
: {
|
|
626
|
+
$in: [
|
|
627
|
+
factory.transactionStatusType.Canceled,
|
|
628
|
+
factory.transactionStatusType.Confirmed,
|
|
629
|
+
factory.transactionStatusType.Expired
|
|
630
|
+
]
|
|
631
|
+
}),
|
|
632
|
+
'tasksExportAction.actionStatus': {
|
|
633
|
+
$exists: true,
|
|
634
|
+
$eq: factory.actionStatusType.PotentialActionStatus
|
|
635
|
+
},
|
|
636
|
+
endDate: { $exists: true, $lt: endDateLt }
|
|
637
|
+
}, {
|
|
638
|
+
_id: 0,
|
|
639
|
+
id: { $toString: '$_id' },
|
|
640
|
+
typeOf: 1
|
|
641
|
+
});
|
|
642
|
+
if (typeof ((_c = params.sort) === null || _c === void 0 ? void 0 : _c.endDate) === 'number' || typeof ((_d = params.sort) === null || _d === void 0 ? void 0 : _d.startDate) === 'number') {
|
|
643
|
+
query.sort(params.sort);
|
|
644
|
+
}
|
|
645
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
601
646
|
.lean() // 2024-08-26~
|
|
602
647
|
.exec()
|
|
603
648
|
// tslint:disable-next-line:no-null-keyword
|
|
@@ -112,9 +112,9 @@ function updateAgent(params) {
|
|
|
112
112
|
function exportOneTransactionTasksIfExists(params) {
|
|
113
113
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
114
114
|
var _a;
|
|
115
|
-
const transaction = yield repos.transaction.startExportTasks(Object.assign(Object.assign({ tasksExportAction: {
|
|
115
|
+
const transaction = yield repos.transaction.startExportTasks(Object.assign(Object.assign(Object.assign({ tasksExportAction: {
|
|
116
116
|
agent: { name: params.tasksExportAction.agent.name }
|
|
117
|
-
}, endDate: { $lt: params.endDate.$lt } }, (typeof params.id === 'string') ? { id: params.id } : undefined), (typeof ((_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { status: params.status } : undefined));
|
|
117
|
+
}, endDate: { $lt: params.endDate.$lt } }, (typeof params.id === 'string') ? { id: params.id } : undefined), (typeof ((_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq) === 'string') ? { status: params.status } : undefined), (params.sort !== undefined) ? { sort: params.sort } : undefined));
|
|
118
118
|
if (transaction === null) {
|
|
119
119
|
return;
|
|
120
120
|
}
|
package/package.json
CHANGED