@chevre/domain 21.7.0-alpha.14 → 21.7.0-alpha.15
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.
|
@@ -0,0 +1,98 @@
|
|
|
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 ONE_YEAR_IN_DAYS = 365;
|
|
8
|
+
type IDeletingTransaction = Pick<
|
|
9
|
+
chevre.factory.transaction.placeOrder.ITransaction,
|
|
10
|
+
'id' | 'project' | 'typeOf' | 'startDate' | 'endDate' | 'object'
|
|
11
|
+
>;
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
15
|
+
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const endDateLt: Date = moment(now)
|
|
18
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
19
|
+
.add(-ONE_YEAR_IN_DAYS, 'days')
|
|
20
|
+
.toDate();
|
|
21
|
+
|
|
22
|
+
const taskRepo = new chevre.repository.Task(mongoose.connection);
|
|
23
|
+
const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
|
|
24
|
+
|
|
25
|
+
const deletingTransactions = <IDeletingTransaction[]>await transactionRepo.search<chevre.factory.transactionType.PlaceOrder>(
|
|
26
|
+
{
|
|
27
|
+
limit: 100,
|
|
28
|
+
page: 1,
|
|
29
|
+
sort: { startDate: chevre.factory.sortType.Ascending },
|
|
30
|
+
typeOf: chevre.factory.transactionType.PlaceOrder,
|
|
31
|
+
statuses: [
|
|
32
|
+
chevre.factory.transactionStatusType.Canceled,
|
|
33
|
+
chevre.factory.transactionStatusType.Confirmed,
|
|
34
|
+
chevre.factory.transactionStatusType.Expired
|
|
35
|
+
],
|
|
36
|
+
endThrough: endDateLt,
|
|
37
|
+
inclusion: ['_id', 'project', 'typeOf', 'startDate', 'endDate', 'object'],
|
|
38
|
+
exclusion: []
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
let i = 0;
|
|
43
|
+
let updateCount = 0;
|
|
44
|
+
for (const deletingTransaction of deletingTransactions) {
|
|
45
|
+
i += 1;
|
|
46
|
+
const transaction: IDeletingTransaction = deletingTransaction;
|
|
47
|
+
console.log('checking...', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
|
|
48
|
+
|
|
49
|
+
const isEndDateBefore = transaction.endDate !== undefined && moment(transaction.endDate)
|
|
50
|
+
.isBefore(endDateLt);
|
|
51
|
+
if (isEndDateBefore) {
|
|
52
|
+
const runsAt: Date = moment(transaction.endDate)
|
|
53
|
+
.add(ONE_YEAR_IN_DAYS, 'days')
|
|
54
|
+
.toDate();
|
|
55
|
+
|
|
56
|
+
updateCount += 1;
|
|
57
|
+
const deleteTransactionTask: chevre.factory.task.deleteTransaction.IAttributes = {
|
|
58
|
+
project: transaction.project,
|
|
59
|
+
name: chevre.factory.taskName.DeleteTransaction,
|
|
60
|
+
status: chevre.factory.taskStatus.Ready,
|
|
61
|
+
runsAt,
|
|
62
|
+
remainingNumberOfTries: 3,
|
|
63
|
+
numberOfTried: 0,
|
|
64
|
+
executionResults: [],
|
|
65
|
+
data: {
|
|
66
|
+
object: {
|
|
67
|
+
specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
|
|
68
|
+
endDate: transaction.endDate,
|
|
69
|
+
id: transaction.id,
|
|
70
|
+
object: {
|
|
71
|
+
...(typeof transaction.object.confirmationNumber === 'string')
|
|
72
|
+
? { confirmationNumber: transaction.object.confirmationNumber }
|
|
73
|
+
: undefined,
|
|
74
|
+
...(typeof transaction.object.orderNumber === 'string')
|
|
75
|
+
? { orderNumber: transaction.object.orderNumber }
|
|
76
|
+
: undefined
|
|
77
|
+
},
|
|
78
|
+
project: transaction.project,
|
|
79
|
+
startDate: transaction.startDate,
|
|
80
|
+
typeOf: transaction.typeOf
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
console.log(
|
|
85
|
+
'saving task...',
|
|
86
|
+
deleteTransactionTask.runsAt, transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
|
|
87
|
+
await taskRepo.createDeleteTransactionTaskIfNotExist(deleteTransactionTask, { emitImmediately: false });
|
|
88
|
+
console.log('task saved', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log(i, 'transactions checked');
|
|
93
|
+
console.log(updateCount, 'transactions updated');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main()
|
|
97
|
+
.then()
|
|
98
|
+
.catch(console.error);
|
|
@@ -31,6 +31,10 @@ export declare class MongoRepository {
|
|
|
31
31
|
id: string;
|
|
32
32
|
}[]>;
|
|
33
33
|
createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* 取引削除タスク冪等作成
|
|
36
|
+
*/
|
|
37
|
+
createDeleteTransactionTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.DeleteTransaction>, options: IOptionOnCreate): Promise<void>;
|
|
34
38
|
executeById(params: {
|
|
35
39
|
id: string;
|
|
36
40
|
executor: {
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -206,6 +206,30 @@ class MongoRepository {
|
|
|
206
206
|
}
|
|
207
207
|
});
|
|
208
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* 取引削除タスク冪等作成
|
|
211
|
+
*/
|
|
212
|
+
createDeleteTransactionTaskIfNotExist(params, options) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
if (params.data.object.specifyingMethod !== factory.task.deleteTransaction.SpecifyingMethod.Id) {
|
|
215
|
+
throw new factory.errors.NotImplemented(`only ${factory.task.deleteTransaction.SpecifyingMethod.Id} implemented`);
|
|
216
|
+
}
|
|
217
|
+
const createdTask = yield this.taskModel.findOneAndUpdate({
|
|
218
|
+
'project.id': { $eq: params.project.id },
|
|
219
|
+
name: { $eq: params.name },
|
|
220
|
+
'data.object.id': { $exists: true, $eq: params.data.object.id }
|
|
221
|
+
}, { $setOnInsert: params }, { new: true, upsert: true })
|
|
222
|
+
.select({ _id: 1 })
|
|
223
|
+
.exec();
|
|
224
|
+
if (options.emitImmediately) {
|
|
225
|
+
task_2.taskEventEmitter.emitTaskStatusChanged({
|
|
226
|
+
id: createdTask.id,
|
|
227
|
+
name: params.name,
|
|
228
|
+
status: factory.taskStatus.Ready
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
}
|
|
209
233
|
executeById(params) {
|
|
210
234
|
return __awaiter(this, void 0, void 0, function* () {
|
|
211
235
|
const doc = yield this.taskModel.findOneAndUpdate({
|
package/package.json
CHANGED