@chevre/domain 22.14.0-alpha.5 → 22.14.0-alpha.8
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/repo/action.d.ts +1 -1
- package/lib/chevre/repo/task.js +2 -2
- package/lib/chevre/service/event.js +10 -2
- package/lib/chevre/service/task/deletePerson.js +11 -10
- package/lib/chevre/service/transaction/deleteTransaction.js +9 -9
- package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +1 -1
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +1 -1
- package/package.json +2 -2
- package/example/src/chevre/migrateDeleteTransactionTasks.ts +0 -132
- package/example/src/chevre/optimizeDeleteTransactionTasks.ts +0 -119
|
@@ -2,7 +2,7 @@ import { factory as surfrockFactory } from '@surfrock/sdk';
|
|
|
2
2
|
import { Connection, FilterQuery, UpdateQuery } from 'mongoose';
|
|
3
3
|
import * as factory from '../factory';
|
|
4
4
|
export type IAction4transaction<T extends factory.actionType.AcceptAction | factory.actionType.AuthorizeAction> = T extends factory.actionType.AcceptAction ? factory.action.accept.coaOffer.IAction | factory.action.accept.pay.IAction : T extends factory.actionType.AuthorizeAction ? (factory.action.authorize.offer.eventService.IAction | factory.action.authorize.offer.moneyTransfer.IAction | factory.action.authorize.offer.product.IAction | factory.action.authorize.paymentMethod.any.IAction) : never;
|
|
5
|
-
export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? (factory.action.check.paymentMethod.movieTicket.IAction | factory.action.check.token.IAction) : T extends factory.actionType.MoneyTransfer ? factory.action.transfer.moneyTransfer.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction
|
|
5
|
+
export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? (factory.action.check.paymentMethod.movieTicket.IAction | factory.action.check.token.IAction) : T extends factory.actionType.MoneyTransfer ? factory.action.transfer.moneyTransfer.IAction : T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.InformAction ? factory.action.interact.inform.IAction<factory.action.interact.inform.IAttributes<factory.action.interact.inform.IObject>> & {
|
|
6
6
|
error?: any;
|
|
7
7
|
purpose?: never;
|
|
8
8
|
} : factory.action.IAction<factory.action.IAttributes<T, any, any>>;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -306,8 +306,8 @@ class TaskRepo {
|
|
|
306
306
|
// resolve uniqueness of identifier(2025-03-27~)
|
|
307
307
|
params, options) {
|
|
308
308
|
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
-
if (params.data.object.specifyingMethod !== factory.
|
|
310
|
-
throw new factory.errors.NotImplemented(`only ${factory.
|
|
309
|
+
if (params.data.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
|
|
310
|
+
throw new factory.errors.NotImplemented(`only ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id} implemented`);
|
|
311
311
|
}
|
|
312
312
|
const createdTask = yield this.taskModel.findOneAndUpdate({
|
|
313
313
|
'project.id': { $eq: params.project.id },
|
|
@@ -63,7 +63,8 @@ function importFromCOA(params) {
|
|
|
63
63
|
object: Object.assign(Object.assign({}, params), { startDate: `${moment(targetImportFrom) // debug(2024-04-26~)
|
|
64
64
|
.toISOString()}/${moment(targetImportThrough)
|
|
65
65
|
.toISOString()}`, superEvent: { location: { branchCode: params.locationBranchCode } }, typeOf: factory.eventType.ScreeningEvent }),
|
|
66
|
-
instrument
|
|
66
|
+
instrument,
|
|
67
|
+
targetCollection: { typeOf: factory.eventType.ScreeningEvent }
|
|
67
68
|
};
|
|
68
69
|
const action = yield repos.action.start(actionAttributes);
|
|
69
70
|
let savedScreeningEventsCount = 0;
|
|
@@ -150,7 +151,8 @@ function processUpdateMovieTheater(params) {
|
|
|
150
151
|
theaterCode: params.locationBranchCode,
|
|
151
152
|
typeOf: 'WebAPI',
|
|
152
153
|
identifier: factory.service.webAPI.Identifier.COA
|
|
153
|
-
}
|
|
154
|
+
},
|
|
155
|
+
targetCollection: { typeOf: factory.placeType.MovieTheater }
|
|
154
156
|
};
|
|
155
157
|
const action = yield repos.action.start(actionAttributes);
|
|
156
158
|
let seller;
|
|
@@ -345,6 +347,12 @@ function createScreeningEvents(params) {
|
|
|
345
347
|
// tslint:disable-next-line:max-func-body-length
|
|
346
348
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
347
349
|
const project = params.project;
|
|
350
|
+
if (typeof params.instrument.begin !== 'string') {
|
|
351
|
+
throw new factory.errors.ArgumentNull('instrument.begin');
|
|
352
|
+
}
|
|
353
|
+
if (typeof params.instrument.end !== 'string') {
|
|
354
|
+
throw new factory.errors.ArgumentNull('instrument.end');
|
|
355
|
+
}
|
|
348
356
|
// COAからイベント取得;
|
|
349
357
|
const schedulesFromCOA = yield repos.masterService.schedule({
|
|
350
358
|
theaterCode: params.instrument.theaterCode,
|
|
@@ -95,17 +95,18 @@ function deleteById(params, setting) {
|
|
|
95
95
|
// tslint:disable-next-line:max-func-body-length
|
|
96
96
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
97
97
|
var _a;
|
|
98
|
+
const deleteObject = {
|
|
99
|
+
id: params.id,
|
|
100
|
+
typeOf: factory.personType.Person,
|
|
101
|
+
migrate: params.migrate,
|
|
102
|
+
physically: params.physically
|
|
103
|
+
// discontinue(2025-03-29~)
|
|
104
|
+
// ...(typeof params.migratePersonRecipientUrl === 'string')
|
|
105
|
+
// ? { migratePersonRecipientUrl: params.migratePersonRecipientUrl } : undefined
|
|
106
|
+
};
|
|
98
107
|
const deleteMemberAction = {
|
|
99
108
|
agent: params.agent,
|
|
100
|
-
object:
|
|
101
|
-
id: params.id,
|
|
102
|
-
typeOf: factory.personType.Person,
|
|
103
|
-
migrate: params.migrate,
|
|
104
|
-
physically: params.physically
|
|
105
|
-
// discontinue(2025-03-29~)
|
|
106
|
-
// ...(typeof params.migratePersonRecipientUrl === 'string')
|
|
107
|
-
// ? { migratePersonRecipientUrl: params.migratePersonRecipientUrl } : undefined
|
|
108
|
-
},
|
|
109
|
+
object: deleteObject,
|
|
109
110
|
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
110
111
|
typeOf: factory.actionType.DeleteAction
|
|
111
112
|
};
|
|
@@ -386,7 +387,7 @@ function createDeleteTransactionTask(params) {
|
|
|
386
387
|
executionResults: [],
|
|
387
388
|
data: {
|
|
388
389
|
object: {
|
|
389
|
-
specifyingMethod: factory.
|
|
390
|
+
specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.AgentId,
|
|
390
391
|
agent: { id: params.id },
|
|
391
392
|
project: { id: params.project.id },
|
|
392
393
|
typeOf: transactionType
|
|
@@ -19,7 +19,7 @@ const deleteOrder_1 = require("../order/deleteOrder");
|
|
|
19
19
|
function deleteTransaction(params) {
|
|
20
20
|
// tslint:disable-next-line:max-func-body-length
|
|
21
21
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
if (params.object.specifyingMethod === factory.
|
|
22
|
+
if (params.object.specifyingMethod === factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.AgentId) {
|
|
23
23
|
// transaction.agent.id指定による取引削除に対応(2023-06-30~)
|
|
24
24
|
yield createDeleteTransactionTasksByAgentId(params)(repos);
|
|
25
25
|
}
|
|
@@ -31,8 +31,8 @@ function deleteTransaction(params) {
|
|
|
31
31
|
function createDeleteTransactionTasksByAgentId(params) {
|
|
32
32
|
// tslint:disable-next-line:max-func-body-length
|
|
33
33
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
if (params.object.specifyingMethod !== factory.
|
|
35
|
-
throw new factory.errors.Argument('object.specifyingMethod', `must be ${factory.
|
|
34
|
+
if (params.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.AgentId) {
|
|
35
|
+
throw new factory.errors.Argument('object.specifyingMethod', `must be ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.AgentId}`);
|
|
36
36
|
}
|
|
37
37
|
const agentIdSpecified = params.object.agent.id;
|
|
38
38
|
// agentIdによる全取引についてDeleteTransactionタスクを作成する
|
|
@@ -61,7 +61,7 @@ function createDeleteTransactionTasksByAgentId(params) {
|
|
|
61
61
|
numberOfTried: 0,
|
|
62
62
|
executionResults: [],
|
|
63
63
|
data: {
|
|
64
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
64
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: Object.assign(Object.assign({}, (typeof transaction.object.confirmationNumber === 'string')
|
|
65
65
|
? { confirmationNumber: transaction.object.confirmationNumber }
|
|
66
66
|
: undefined), (typeof transaction.object.orderNumber === 'string')
|
|
67
67
|
? { orderNumber: transaction.object.orderNumber }
|
|
@@ -81,7 +81,7 @@ function createDeleteTransactionTasksByAgentId(params) {
|
|
|
81
81
|
numberOfTried: 0,
|
|
82
82
|
executionResults: [],
|
|
83
83
|
data: {
|
|
84
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
84
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: {
|
|
85
85
|
order: transaction.object.order
|
|
86
86
|
}, project: transaction.project, startDate: transaction.startDate, typeOf: transaction.typeOf }, (transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined)
|
|
87
87
|
}
|
|
@@ -99,7 +99,7 @@ function createDeleteTransactionTasksByAgentId(params) {
|
|
|
99
99
|
numberOfTried: 0,
|
|
100
100
|
executionResults: [],
|
|
101
101
|
data: {
|
|
102
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
102
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: Object.assign({}, (transaction.object.pendingTransaction !== undefined)
|
|
103
103
|
? { pendingTransaction: transaction.object.pendingTransaction }
|
|
104
104
|
: undefined), project: transaction.project, startDate: transaction.startDate, typeOf: transaction.typeOf }, (transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined)
|
|
105
105
|
}
|
|
@@ -120,8 +120,8 @@ function deleteTransactionById(params) {
|
|
|
120
120
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
121
121
|
var _a;
|
|
122
122
|
if (typeof params.object.specifyingMethod === 'string'
|
|
123
|
-
&& params.object.specifyingMethod !== factory.
|
|
124
|
-
throw new factory.errors.Argument('object.specifyingMethod', `must be ${factory.
|
|
123
|
+
&& params.object.specifyingMethod !== factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
|
|
124
|
+
throw new factory.errors.Argument('object.specifyingMethod', `must be ${factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id}`);
|
|
125
125
|
}
|
|
126
126
|
const deletingTransactionId = params.object.id;
|
|
127
127
|
if (typeof deletingTransactionId !== 'string' || deletingTransactionId.length === 0) {
|
|
@@ -364,7 +364,7 @@ function deleteMessagesByPlaceOrder(params) {
|
|
|
364
364
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
365
365
|
let deleteResult;
|
|
366
366
|
if (params.transaction.typeOf === factory.transactionType.PlaceOrder
|
|
367
|
-
&& params.transaction.specifyingMethod === factory.
|
|
367
|
+
&& params.transaction.specifyingMethod === factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
|
|
368
368
|
const orderNumber = params.transaction.object.orderNumber;
|
|
369
369
|
if (typeof orderNumber === 'string' && orderNumber.length > 0) {
|
|
370
370
|
const deleteReservationsResult = yield repos.message.deleteByMainEntityOrderNumber({
|
|
@@ -53,7 +53,7 @@ function createTasks(params, setting
|
|
|
53
53
|
numberOfTried: 0,
|
|
54
54
|
executionResults: [],
|
|
55
55
|
data: {
|
|
56
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
56
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: Object.assign({}, (transaction.object.pendingTransaction !== undefined)
|
|
57
57
|
? { pendingTransaction: transaction.object.pendingTransaction }
|
|
58
58
|
: undefined), project: transaction.project, startDate: transaction.startDate, typeOf: transaction.typeOf }, (transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined)
|
|
59
59
|
}
|
|
@@ -87,7 +87,7 @@ function createTasks(params, setting
|
|
|
87
87
|
numberOfTried: 0,
|
|
88
88
|
executionResults: [],
|
|
89
89
|
data: {
|
|
90
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
90
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: Object.assign(Object.assign({}, (typeof transaction.object.confirmationNumber === 'string')
|
|
91
91
|
? { confirmationNumber: transaction.object.confirmationNumber }
|
|
92
92
|
: undefined), (typeof transaction.object.orderNumber === 'string')
|
|
93
93
|
? { orderNumber: transaction.object.orderNumber }
|
|
@@ -53,7 +53,7 @@ function createTasks(params, setting
|
|
|
53
53
|
numberOfTried: 0,
|
|
54
54
|
executionResults: [],
|
|
55
55
|
data: {
|
|
56
|
-
object: Object.assign({ specifyingMethod: factory.
|
|
56
|
+
object: Object.assign({ specifyingMethod: factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id, id: transaction.id, object: {
|
|
57
57
|
order: transaction.object.order
|
|
58
58
|
}, project: transaction.project, startDate: transaction.startDate, typeOf: transaction.typeOf }, (transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined)
|
|
59
59
|
}
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "4.399.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.399.0-alpha.8",
|
|
15
15
|
"@cinerino/sdk": "12.2.0",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.4.0-alpha.1",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "22.14.0-alpha.
|
|
118
|
+
"version": "22.14.0-alpha.8"
|
|
119
119
|
}
|
|
@@ -1,132 +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
|
-
const STORAGE_PERIOD_IN_DAYS = 30;
|
|
9
|
-
|
|
10
|
-
// tslint:disable-next-line:max-func-body-length
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
-
|
|
14
|
-
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
15
|
-
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
16
|
-
|
|
17
|
-
const cursor = taskRepo.getCursor(
|
|
18
|
-
{
|
|
19
|
-
name: { $eq: chevre.factory.taskName.DeleteTransaction },
|
|
20
|
-
status: { $eq: chevre.factory.taskStatus.Ready }
|
|
21
|
-
// runsAt: {
|
|
22
|
-
// $gte: moment()
|
|
23
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
24
|
-
// .add(29, 'days')
|
|
25
|
-
// .toDate(),
|
|
26
|
-
// $lte: moment()
|
|
27
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
28
|
-
// .add(365, 'days')
|
|
29
|
-
// .toDate()
|
|
30
|
-
// },
|
|
31
|
-
// _id: { $eq: '6440d8cf9e4983c32ade65de' }
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
_id: 1,
|
|
35
|
-
project: 1,
|
|
36
|
-
data: 1,
|
|
37
|
-
status: 1,
|
|
38
|
-
name: 1,
|
|
39
|
-
runsAt: 1
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
console.log('tasks found');
|
|
43
|
-
|
|
44
|
-
let i = 0;
|
|
45
|
-
let updateCount = 0;
|
|
46
|
-
await cursor.eachAsync(async (doc) => {
|
|
47
|
-
i += 1;
|
|
48
|
-
const deleteTransactionTask: Pick<
|
|
49
|
-
chevre.factory.task.deleteTransaction.ITask,
|
|
50
|
-
'id' | 'project' | 'data' | 'status' | 'name' | 'runsAt'
|
|
51
|
-
> = doc.toObject();
|
|
52
|
-
|
|
53
|
-
let placeOrderTransactionId: string | undefined;
|
|
54
|
-
if (deleteTransactionTask.data.object.typeOf === chevre.factory.transactionType.PlaceOrder) {
|
|
55
|
-
if (
|
|
56
|
-
(typeof deleteTransactionTask.data.object.specifyingMethod !== 'string')
|
|
57
|
-
|| (deleteTransactionTask.data.object.specifyingMethod === chevre.factory.task.deleteTransaction.SpecifyingMethod.Id)
|
|
58
|
-
) {
|
|
59
|
-
placeOrderTransactionId = deleteTransactionTask.data.object.id;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
let alreadyMigrated = true;
|
|
64
|
-
let runsAtExpected: moment.Moment | undefined;
|
|
65
|
-
if (typeof placeOrderTransactionId === 'string') {
|
|
66
|
-
console.log(
|
|
67
|
-
'checking transaction...',
|
|
68
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
69
|
-
placeOrderTransactionId
|
|
70
|
-
);
|
|
71
|
-
const placeOrderTransaction = (await transactionRepo.projectFields({
|
|
72
|
-
limit: 1,
|
|
73
|
-
page: 1,
|
|
74
|
-
typeOf: chevre.factory.transactionType.PlaceOrder,
|
|
75
|
-
ids: [placeOrderTransactionId],
|
|
76
|
-
inclusion: ['endDate', 'status']
|
|
77
|
-
})).shift();
|
|
78
|
-
if (placeOrderTransaction !== undefined) {
|
|
79
|
-
const { endDate, status } = placeOrderTransaction;
|
|
80
|
-
runsAtExpected = moment(endDate)
|
|
81
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
82
|
-
.add(STORAGE_PERIOD_IN_DAYS, 'days');
|
|
83
|
-
|
|
84
|
-
// if (status !== chevre.factory.transactionStatusType.Confirmed) {
|
|
85
|
-
const taskRunsTooLate = moment(deleteTransactionTask.runsAt)
|
|
86
|
-
.isAfter(runsAtExpected);
|
|
87
|
-
const diff = moment(deleteTransactionTask.runsAt)
|
|
88
|
-
.diff(moment(endDate));
|
|
89
|
-
console.log('taskRunsTooLate?:', taskRunsTooLate, placeOrderTransactionId, endDate, status, diff.toLocaleString());
|
|
90
|
-
if (taskRunsTooLate) {
|
|
91
|
-
alreadyMigrated = false;
|
|
92
|
-
}
|
|
93
|
-
// }
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (alreadyMigrated) {
|
|
98
|
-
console.log(
|
|
99
|
-
'already migrated.',
|
|
100
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
101
|
-
i, updateCount);
|
|
102
|
-
} else {
|
|
103
|
-
console.log(
|
|
104
|
-
'updating...',
|
|
105
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
106
|
-
i, updateCount, runsAtExpected);
|
|
107
|
-
if (runsAtExpected !== undefined) {
|
|
108
|
-
await taskRepo.taskModel.findByIdAndUpdate(
|
|
109
|
-
deleteTransactionTask.id,
|
|
110
|
-
{
|
|
111
|
-
$set: {
|
|
112
|
-
runsAt: runsAtExpected.toDate()
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
)
|
|
116
|
-
.exec();
|
|
117
|
-
}
|
|
118
|
-
updateCount += 1;
|
|
119
|
-
console.log(
|
|
120
|
-
'updated.',
|
|
121
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
122
|
-
i, updateCount, runsAtExpected);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
console.log(i, 'tasks checked');
|
|
127
|
-
console.log(updateCount, 'tasks updated');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
main()
|
|
131
|
-
.then()
|
|
132
|
-
.catch(console.error);
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
-
|
|
8
|
-
// tslint:disable-next-line:max-func-body-length
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const cursor = taskRepo.getCursor(
|
|
15
|
-
{
|
|
16
|
-
name: { $eq: chevre.factory.taskName.DeleteTransaction },
|
|
17
|
-
status: { $eq: chevre.factory.taskStatus.Ready }
|
|
18
|
-
// runsAt: {
|
|
19
|
-
// $gte: moment()
|
|
20
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
21
|
-
// .add(29, 'days')
|
|
22
|
-
// .toDate(),
|
|
23
|
-
// $lte: moment()
|
|
24
|
-
// // tslint:disable-next-line:no-magic-numbers
|
|
25
|
-
// .add(365, 'days')
|
|
26
|
-
// .toDate()
|
|
27
|
-
// },
|
|
28
|
-
// _id: { $eq: '6441bcf04014af2c7d39f6aa' }
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
_id: 1,
|
|
32
|
-
project: 1,
|
|
33
|
-
data: 1,
|
|
34
|
-
status: 1,
|
|
35
|
-
name: 1,
|
|
36
|
-
runsAt: 1
|
|
37
|
-
}
|
|
38
|
-
);
|
|
39
|
-
console.log('tasks found');
|
|
40
|
-
|
|
41
|
-
let i = 0;
|
|
42
|
-
let updateCount = 0;
|
|
43
|
-
await cursor.eachAsync(async (doc) => {
|
|
44
|
-
i += 1;
|
|
45
|
-
const deleteTransactionTask: Pick<
|
|
46
|
-
chevre.factory.task.deleteTransaction.ITask,
|
|
47
|
-
'id' | 'project' | 'data' | 'status' | 'name' | 'runsAt'
|
|
48
|
-
> = doc.toObject();
|
|
49
|
-
|
|
50
|
-
let dataObject: chevre.factory.task.deleteTransaction.IObjectAsPlaceOrder | undefined;
|
|
51
|
-
if (deleteTransactionTask.data.object.typeOf === chevre.factory.transactionType.PlaceOrder) {
|
|
52
|
-
if (
|
|
53
|
-
(typeof deleteTransactionTask.data.object.specifyingMethod !== 'string')
|
|
54
|
-
|| (deleteTransactionTask.data.object.specifyingMethod === chevre.factory.task.deleteTransaction.SpecifyingMethod.Id)
|
|
55
|
-
) {
|
|
56
|
-
const existingDataObject = deleteTransactionTask.data.object;
|
|
57
|
-
if ((<any>existingDataObject).agent !== undefined) {
|
|
58
|
-
dataObject = {
|
|
59
|
-
specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
|
|
60
|
-
id: existingDataObject.id,
|
|
61
|
-
object: {
|
|
62
|
-
...(typeof existingDataObject.object.confirmationNumber === 'string')
|
|
63
|
-
? { confirmationNumber: existingDataObject.object.confirmationNumber }
|
|
64
|
-
: undefined,
|
|
65
|
-
...(typeof existingDataObject.object.orderNumber === 'string')
|
|
66
|
-
? { orderNumber: existingDataObject.object.orderNumber }
|
|
67
|
-
: undefined
|
|
68
|
-
},
|
|
69
|
-
project: existingDataObject.project,
|
|
70
|
-
startDate: existingDataObject.startDate,
|
|
71
|
-
typeOf: existingDataObject.typeOf,
|
|
72
|
-
...(existingDataObject.endDate !== undefined) ? { endDate: existingDataObject.endDate } : undefined
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
let alreadyMigrated = true;
|
|
79
|
-
if (typeof dataObject?.id === 'string') {
|
|
80
|
-
alreadyMigrated = false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (alreadyMigrated) {
|
|
84
|
-
console.log(
|
|
85
|
-
'already migrated.',
|
|
86
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
87
|
-
i, updateCount);
|
|
88
|
-
} else {
|
|
89
|
-
console.log(
|
|
90
|
-
'updating...',
|
|
91
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
92
|
-
i, updateCount, dataObject);
|
|
93
|
-
if (dataObject !== undefined) {
|
|
94
|
-
await taskRepo.taskModel.findByIdAndUpdate(
|
|
95
|
-
deleteTransactionTask.id,
|
|
96
|
-
{
|
|
97
|
-
$set: {
|
|
98
|
-
'data.object': dataObject
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{ timestamps: false }
|
|
102
|
-
)
|
|
103
|
-
.exec();
|
|
104
|
-
}
|
|
105
|
-
updateCount += 1;
|
|
106
|
-
console.log(
|
|
107
|
-
'updated.',
|
|
108
|
-
deleteTransactionTask.project.id, deleteTransactionTask.name, deleteTransactionTask.id, deleteTransactionTask.runsAt,
|
|
109
|
-
i, updateCount);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
console.log(i, 'tasks checked');
|
|
114
|
-
console.log(updateCount, 'tasks updated');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
main()
|
|
118
|
-
.then()
|
|
119
|
-
.catch(console.error);
|