@chevre/domain 26.0.0-alpha.4 → 26.0.0-alpha.6
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/asyncActionLegacy.d.ts +24 -0
- package/lib/chevre/repo/asyncActionLegacy.js +59 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +2 -0
- package/lib/chevre/repo/scheduledTask.d.ts +1 -1
- package/lib/chevre/repo/scheduledTaskMigration.d.ts +21 -0
- package/lib/chevre/repo/scheduledTaskMigration.js +70 -0
- package/lib/chevre/repo/task.d.ts +2 -14
- package/lib/chevre/repo/task.js +11 -47
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +12 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderInTransit.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/createSendEmailMessageTaskIfNotExist.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/processOrder.js +1 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +1 -1
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +8 -4
- package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +55 -103
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -0
- package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +20 -10
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +13 -3
- package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +48 -51
- package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
- package/lib/chevre/service/transaction/returnOrder.js +21 -13
- package/lib/chevre/service/transaction.d.ts +2 -0
- package/lib/chevre/service/transaction.js +0 -2
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
+
import { INextFunction } from '../eventEmitter/task';
|
|
3
|
+
import { factory } from '../factory';
|
|
4
|
+
import { IModel } from './mongoose/schemas/task';
|
|
5
|
+
/**
|
|
6
|
+
* 旧非同期アクション(tasksコレクションにて管理)リポジトリ
|
|
7
|
+
*/
|
|
8
|
+
export declare class AsyncActionLegacyRepo {
|
|
9
|
+
readonly taskModel: IModel;
|
|
10
|
+
constructor(connection: Connection);
|
|
11
|
+
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
|
|
12
|
+
alternateName?: never;
|
|
13
|
+
identifier?: never;
|
|
14
|
+
expires: Date;
|
|
15
|
+
}, next: INextFunction): Promise<{
|
|
16
|
+
id: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
20
|
+
*/
|
|
21
|
+
makeExpiredMany(params: {
|
|
22
|
+
expiresLt: Date;
|
|
23
|
+
}): Promise<UpdateWriteOpResult>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncActionLegacyRepo = void 0;
|
|
4
|
+
const task_1 = require("../eventEmitter/task");
|
|
5
|
+
const factory_1 = require("../factory");
|
|
6
|
+
const task_2 = require("./mongoose/schemas/task");
|
|
7
|
+
/**
|
|
8
|
+
* 旧非同期アクション(tasksコレクションにて管理)リポジトリ
|
|
9
|
+
*/
|
|
10
|
+
class AsyncActionLegacyRepo {
|
|
11
|
+
taskModel;
|
|
12
|
+
constructor(connection) {
|
|
13
|
+
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
14
|
+
}
|
|
15
|
+
async runImmediately(params,
|
|
16
|
+
// support customr function(2025-05-25~)
|
|
17
|
+
next) {
|
|
18
|
+
const { expires } = params;
|
|
19
|
+
if (!(expires instanceof Date)) {
|
|
20
|
+
throw new factory_1.factory.errors.Argument('expires', 'must be Date');
|
|
21
|
+
}
|
|
22
|
+
const savingTask = {
|
|
23
|
+
...params,
|
|
24
|
+
status: factory_1.factory.taskStatus.Ready,
|
|
25
|
+
numberOfTried: 0,
|
|
26
|
+
executionResults: []
|
|
27
|
+
};
|
|
28
|
+
const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
|
|
29
|
+
const id = result.insertedIds?.[0]?.toHexString();
|
|
30
|
+
if (typeof id !== 'string') {
|
|
31
|
+
throw new factory_1.factory.errors.Internal('task not saved');
|
|
32
|
+
}
|
|
33
|
+
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
34
|
+
id,
|
|
35
|
+
status: factory_1.factory.taskStatus.Ready,
|
|
36
|
+
expires // emit expires(2025-03-31~)
|
|
37
|
+
}, next);
|
|
38
|
+
return { id };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
42
|
+
*/
|
|
43
|
+
async makeExpiredMany(params) {
|
|
44
|
+
const { expiresLt } = params;
|
|
45
|
+
if (!(expiresLt instanceof Date)) {
|
|
46
|
+
throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
|
|
47
|
+
}
|
|
48
|
+
return this.taskModel.updateMany({
|
|
49
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
50
|
+
expires: { $exists: true, $lt: expiresLt }
|
|
51
|
+
}, {
|
|
52
|
+
$set: {
|
|
53
|
+
status: factory_1.factory.taskStatus.Expired
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.exec();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.AsyncActionLegacyRepo = AsyncActionLegacyRepo;
|
|
@@ -32,6 +32,8 @@ interface IOnEventChanged {
|
|
|
32
32
|
informEvent2agg?: factory.project.IInformParams[];
|
|
33
33
|
}
|
|
34
34
|
export interface IStorageSettings {
|
|
35
|
+
useScheduledDeleteTransactionTask?: boolean;
|
|
36
|
+
deleteTransactionTaskExpiresInDays?: number;
|
|
35
37
|
/**
|
|
36
38
|
* 取引保管期間(Confirmed)
|
|
37
39
|
* default:365
|
|
@@ -5,7 +5,7 @@ type ICreatingTaskKeys = 'data' | 'executionResults' | 'name' | 'numberOfTried'
|
|
|
5
5
|
/**
|
|
6
6
|
* リトライ可能なタスク作成属性
|
|
7
7
|
*/
|
|
8
|
-
type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys>) & {
|
|
8
|
+
type ICreatingTask = (Pick<factory.task.importEventCapacitiesFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.importEventsFromCOA.IAttributes, ICreatingTaskKeys> | Pick<factory.task.deleteTransaction.IAttributes, ICreatingTaskKeys>) & {
|
|
9
9
|
expires: Date;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* 予定タスク移行リポジトリ
|
|
4
|
+
*/
|
|
5
|
+
export declare class ScheduledTaskMigrationRepo {
|
|
6
|
+
private readonly scheduledTaskModel;
|
|
7
|
+
private readonly taskModel;
|
|
8
|
+
constructor(connection: Connection);
|
|
9
|
+
/**
|
|
10
|
+
* DeleteTransactionタスク移行処理
|
|
11
|
+
*/
|
|
12
|
+
migrateDeleteTransactionTasks(params: {
|
|
13
|
+
limit: number;
|
|
14
|
+
runsAtGte: Date;
|
|
15
|
+
expiresInDays: number;
|
|
16
|
+
}): Promise<(import("mongodb").BulkWriteResult & {
|
|
17
|
+
mongoose?: {
|
|
18
|
+
validationErrors: import("mongoose").Error[];
|
|
19
|
+
} | undefined;
|
|
20
|
+
}) | undefined>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ScheduledTaskMigrationRepo = void 0;
|
|
7
|
+
const moment_1 = __importDefault(require("moment"));
|
|
8
|
+
const factory_1 = require("../factory");
|
|
9
|
+
const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
|
|
10
|
+
const task_1 = require("./mongoose/schemas/task");
|
|
11
|
+
/**
|
|
12
|
+
* 予定タスク移行リポジトリ
|
|
13
|
+
*/
|
|
14
|
+
class ScheduledTaskMigrationRepo {
|
|
15
|
+
scheduledTaskModel;
|
|
16
|
+
taskModel;
|
|
17
|
+
constructor(connection) {
|
|
18
|
+
this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
|
|
19
|
+
this.taskModel = connection.model(task_1.modelName, (0, task_1.createSchema)());
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* DeleteTransactionタスク移行処理
|
|
23
|
+
*/
|
|
24
|
+
async migrateDeleteTransactionTasks(params) {
|
|
25
|
+
const { limit, runsAtGte, expiresInDays } = params;
|
|
26
|
+
// limit件抽出
|
|
27
|
+
const migratingTasks = await this.taskModel.find({
|
|
28
|
+
// _id: { $eq: '6a66e83f9b21f3d4bf5fa232' },
|
|
29
|
+
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
30
|
+
name: { $eq: factory_1.factory.taskName.DeleteTransaction },
|
|
31
|
+
runsAt: { $gte: runsAtGte }
|
|
32
|
+
})
|
|
33
|
+
.limit(limit)
|
|
34
|
+
.lean()
|
|
35
|
+
.exec();
|
|
36
|
+
if (migratingTasks.length === 0) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
;
|
|
40
|
+
const bulkOps = migratingTasks.map((migratingTask) => {
|
|
41
|
+
return {
|
|
42
|
+
updateOne: {
|
|
43
|
+
filter: {
|
|
44
|
+
_id: { $eq: migratingTask._id }
|
|
45
|
+
},
|
|
46
|
+
update: {
|
|
47
|
+
$setOnInsert: {
|
|
48
|
+
...migratingTask,
|
|
49
|
+
expires: (0, moment_1.default)(migratingTask.runsAt)
|
|
50
|
+
.add(expiresInDays, 'days')
|
|
51
|
+
.toDate()
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
upsert: true
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
// 新コレクションへ挿入
|
|
59
|
+
const result = await this.scheduledTaskModel.bulkWrite(bulkOps, { ordered: false });
|
|
60
|
+
// 新コレクションへ書き込めたIDだけを旧DBから削除
|
|
61
|
+
const successfulIds = [];
|
|
62
|
+
migratingTasks.forEach(d => successfulIds.push(d._id));
|
|
63
|
+
if (successfulIds.length > 0) {
|
|
64
|
+
await this.taskModel.deleteMany({ _id: { $in: successfulIds } })
|
|
65
|
+
.exec();
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.ScheduledTaskMigrationRepo = ScheduledTaskMigrationRepo;
|
|
@@ -16,13 +16,6 @@ type ICreatingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | '
|
|
|
16
16
|
export declare class TaskRepo {
|
|
17
17
|
readonly taskModel: IModel;
|
|
18
18
|
constructor(connection: Connection);
|
|
19
|
-
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
|
|
20
|
-
alternateName?: never;
|
|
21
|
-
identifier?: never;
|
|
22
|
-
expires: Date;
|
|
23
|
-
}, next: INextFunction): Promise<{
|
|
24
|
-
id: string;
|
|
25
|
-
}>;
|
|
26
19
|
saveMany(taskAttributes: ICreatingTask[]): Promise<{
|
|
27
20
|
id: string;
|
|
28
21
|
}[]>;
|
|
@@ -42,8 +35,9 @@ export declare class TaskRepo {
|
|
|
42
35
|
/**
|
|
43
36
|
* タスク識別子から冪等作成する
|
|
44
37
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
38
|
+
* reimplement runTaskByIdentifier(2026-08-03~)
|
|
45
39
|
*/
|
|
46
|
-
|
|
40
|
+
runTaskByIdentifier(params: ICreatingTask & {
|
|
47
41
|
alternateName: string;
|
|
48
42
|
identifier: string;
|
|
49
43
|
expires?: never;
|
|
@@ -120,12 +114,6 @@ export declare class TaskRepo {
|
|
|
120
114
|
};
|
|
121
115
|
nameFilterBeforeRunsAt: boolean;
|
|
122
116
|
}): Promise<Pick<factory.task.ITask<factory.taskName>, 'id' | 'name'> | null>;
|
|
123
|
-
/**
|
|
124
|
-
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
125
|
-
*/
|
|
126
|
-
makeExpiredMany(params: {
|
|
127
|
-
expiresLt: Date;
|
|
128
|
-
}): Promise<UpdateWriteOpResult>;
|
|
129
117
|
/**
|
|
130
118
|
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
131
119
|
*/
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -48,31 +48,6 @@ class TaskRepo {
|
|
|
48
48
|
constructor(connection) {
|
|
49
49
|
this.taskModel = connection.model(task_2.modelName, (0, task_2.createSchema)());
|
|
50
50
|
}
|
|
51
|
-
async runImmediately(params,
|
|
52
|
-
// support customr function(2025-05-25~)
|
|
53
|
-
next) {
|
|
54
|
-
const { expires } = params;
|
|
55
|
-
if (!(expires instanceof Date)) {
|
|
56
|
-
throw new factory_1.factory.errors.Argument('expires', 'must be Date');
|
|
57
|
-
}
|
|
58
|
-
const savingTask = {
|
|
59
|
-
...params,
|
|
60
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
61
|
-
numberOfTried: 0,
|
|
62
|
-
executionResults: []
|
|
63
|
-
};
|
|
64
|
-
const result = await this.taskModel.insertMany(savingTask, { rawResult: true });
|
|
65
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
66
|
-
if (typeof id !== 'string') {
|
|
67
|
-
throw new factory_1.factory.errors.Internal('task not saved');
|
|
68
|
-
}
|
|
69
|
-
task_1.taskEventEmitter.emitTaskStatusChanged({
|
|
70
|
-
id,
|
|
71
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
72
|
-
expires // emit expires(2025-03-31~)
|
|
73
|
-
}, next);
|
|
74
|
-
return { id };
|
|
75
|
-
}
|
|
76
51
|
async saveMany(taskAttributes) {
|
|
77
52
|
const emitImmediately = true; // always true(2026-07-30~)
|
|
78
53
|
// const emitImmediately = options?.emitImmediately === true;
|
|
@@ -132,17 +107,24 @@ class TaskRepo {
|
|
|
132
107
|
/**
|
|
133
108
|
* タスク識別子から冪等作成する
|
|
134
109
|
* reimplement createIfNotExistByIdentifier(2025-03-28~)
|
|
110
|
+
* reimplement runTaskByIdentifier(2026-08-03~)
|
|
135
111
|
*/
|
|
136
|
-
async
|
|
112
|
+
async runTaskByIdentifier(params) {
|
|
137
113
|
const emitImmediately = true; // always true(2026-07-30~)
|
|
114
|
+
if (typeof params.identifier !== 'string' || params.identifier.length === 0) {
|
|
115
|
+
throw new factory_1.factory.errors.ArgumentNull('identifier');
|
|
116
|
+
}
|
|
138
117
|
if (typeof params.alternateName !== 'string' || params.alternateName.length === 0) {
|
|
139
118
|
throw new factory_1.factory.errors.ArgumentNull('alternateName');
|
|
140
119
|
}
|
|
120
|
+
if (params.identifier !== params.alternateName) {
|
|
121
|
+
throw new factory_1.factory.errors.Argument('identifier,alternateName not matched');
|
|
122
|
+
}
|
|
141
123
|
let createdTask;
|
|
142
124
|
const filterQuery = {
|
|
143
125
|
'project.id': { $eq: params.project.id },
|
|
144
126
|
name: { $eq: params.name },
|
|
145
|
-
|
|
127
|
+
identifier: { $exists: true, $eq: params.identifier }
|
|
146
128
|
};
|
|
147
129
|
const projection = {
|
|
148
130
|
_id: 0,
|
|
@@ -160,7 +142,7 @@ class TaskRepo {
|
|
|
160
142
|
catch (error) {
|
|
161
143
|
let throwsError = true;
|
|
162
144
|
if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
|
|
163
|
-
// すでに
|
|
145
|
+
// すでにidentifierが存在する場合ok
|
|
164
146
|
throwsError = false;
|
|
165
147
|
createdTask = await this.taskModel.findOne(filterQuery, projection)
|
|
166
148
|
.lean()
|
|
@@ -180,7 +162,7 @@ class TaskRepo {
|
|
|
180
162
|
}
|
|
181
163
|
}
|
|
182
164
|
else {
|
|
183
|
-
throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.
|
|
165
|
+
throw new factory_1.factory.errors.Internal(`falied in creating a task unexpectedly. ${params.identifier}`);
|
|
184
166
|
}
|
|
185
167
|
}
|
|
186
168
|
// /**
|
|
@@ -422,24 +404,6 @@ class TaskRepo {
|
|
|
422
404
|
task_1.taskEventEmitter.emitTaskStatusChanged(changedTask);
|
|
423
405
|
return doc;
|
|
424
406
|
}
|
|
425
|
-
/**
|
|
426
|
-
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
427
|
-
*/
|
|
428
|
-
async makeExpiredMany(params) {
|
|
429
|
-
const { expiresLt } = params;
|
|
430
|
-
if (!(expiresLt instanceof Date)) {
|
|
431
|
-
throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
|
|
432
|
-
}
|
|
433
|
-
return this.taskModel.updateMany({
|
|
434
|
-
status: { $eq: factory_1.factory.taskStatus.Ready },
|
|
435
|
-
expires: { $exists: true, $lt: expiresLt }
|
|
436
|
-
}, {
|
|
437
|
-
$set: {
|
|
438
|
-
status: factory_1.factory.taskStatus.Expired
|
|
439
|
-
}
|
|
440
|
-
})
|
|
441
|
-
.exec();
|
|
442
|
-
}
|
|
443
407
|
/**
|
|
444
408
|
* Runningのまま一定期間超過し、かつ、remainingNumberOfTries>0のタスクをReadyに変更する
|
|
445
409
|
*/
|
|
@@ -16,6 +16,7 @@ import type { CheckThingActionRepo } from './repo/action/checkThing';
|
|
|
16
16
|
import type { PayActionRepo } from './repo/action/pay';
|
|
17
17
|
import type { RefundActionRepo } from './repo/action/refund';
|
|
18
18
|
import type { AsyncActionRepo } from './repo/asyncAction';
|
|
19
|
+
import type { AsyncActionLegacyRepo } from './repo/asyncActionLegacy';
|
|
19
20
|
import type { AdditionalPropertyRepo } from './repo/additionalProperty';
|
|
20
21
|
import type { AdminAsyncActionRepo } from './repo/adminAsyncAction';
|
|
21
22
|
import type { AdminScheduledTaskRepo } from './repo/adminScheduledTask';
|
|
@@ -505,6 +506,10 @@ export type AsyncAction = AsyncActionRepo;
|
|
|
505
506
|
export declare namespace AsyncAction {
|
|
506
507
|
function createInstance(...params: ConstructorParameters<typeof AsyncActionRepo>): Promise<AsyncActionRepo>;
|
|
507
508
|
}
|
|
509
|
+
export type AsyncActionLegacy = AsyncActionLegacyRepo;
|
|
510
|
+
export declare namespace AsyncActionLegacy {
|
|
511
|
+
function createInstance(...params: ConstructorParameters<typeof AsyncActionLegacyRepo>): Promise<AsyncActionLegacyRepo>;
|
|
512
|
+
}
|
|
508
513
|
export type Ticket = TicketRepo;
|
|
509
514
|
export declare namespace Ticket {
|
|
510
515
|
function createInstance(...params: ConstructorParameters<typeof TicketRepo>): Promise<TicketRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateTask = exports.AggregateScheduledTask = exports.AggregateAction = exports.AdminTask = exports.AdminScheduledTask = exports.AdminAsyncAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
|
|
4
|
-
exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = void 0;
|
|
4
|
+
exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncActionLegacy = exports.AsyncAction = exports.Task = exports.ScheduledTask = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = void 0;
|
|
5
5
|
var AcceptedOffer;
|
|
6
6
|
(function (AcceptedOffer) {
|
|
7
7
|
let repo;
|
|
@@ -1066,6 +1066,17 @@ var AsyncAction;
|
|
|
1066
1066
|
}
|
|
1067
1067
|
AsyncAction.createInstance = createInstance;
|
|
1068
1068
|
})(AsyncAction || (exports.AsyncAction = AsyncAction = {}));
|
|
1069
|
+
var AsyncActionLegacy;
|
|
1070
|
+
(function (AsyncActionLegacy) {
|
|
1071
|
+
let repo;
|
|
1072
|
+
async function createInstance(...params) {
|
|
1073
|
+
if (repo === undefined) {
|
|
1074
|
+
repo = (await import('./repo/asyncActionLegacy.js')).AsyncActionLegacyRepo;
|
|
1075
|
+
}
|
|
1076
|
+
return new repo(...params);
|
|
1077
|
+
}
|
|
1078
|
+
AsyncActionLegacy.createInstance = createInstance;
|
|
1079
|
+
})(AsyncActionLegacy || (exports.AsyncActionLegacy = AsyncActionLegacy = {}));
|
|
1069
1080
|
var Ticket;
|
|
1070
1081
|
(function (Ticket) {
|
|
1071
1082
|
let repo;
|
|
@@ -75,7 +75,7 @@ function createSendOrderTaskIfNotExist(params) {
|
|
|
75
75
|
};
|
|
76
76
|
debug('processing createSendOrderTaskIfNotExist...', sendOrderTask);
|
|
77
77
|
// await repos.task.createSendOrderTaskIfNotExist(sendOrderTask);
|
|
78
|
-
await repos.task.
|
|
78
|
+
await repos.task.runTaskByIdentifier(sendOrderTask);
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
function createOnAuthorizationCreatedTask(order) {
|
|
@@ -107,7 +107,7 @@ function createOnAuthorizationCreatedTask(order) {
|
|
|
107
107
|
},
|
|
108
108
|
project: { id: order.project.id, typeOf: factory_1.factory.organizationType.Project }
|
|
109
109
|
};
|
|
110
|
-
await repos.task.
|
|
110
|
+
await repos.task.runTaskByIdentifier(task);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
}
|
|
@@ -64,7 +64,7 @@ function createConfirmPayTransactionTasks(order, simpleOrder) {
|
|
|
64
64
|
executionResults: [],
|
|
65
65
|
data
|
|
66
66
|
};
|
|
67
|
-
await repos.task.
|
|
67
|
+
await repos.task.runTaskByIdentifier(confirmPayTransactionTask);
|
|
68
68
|
// 冗長なタスク作成を回避
|
|
69
69
|
// const existingTasks = await repos.task.projectFields(
|
|
70
70
|
// {
|
|
@@ -59,7 +59,7 @@ function createSendEmailMessageTaskIfNotExist(params) {
|
|
|
59
59
|
executionResults: [],
|
|
60
60
|
data: { actionAttributes }
|
|
61
61
|
};
|
|
62
|
-
await repos.task.
|
|
62
|
+
await repos.task.runTaskByIdentifier(sendEmailMessageTask);
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
@@ -61,7 +61,7 @@ function createConfirmReserveTransactionTasksIfNotExist(order, simpleOrder, opti
|
|
|
61
61
|
executionResults: [],
|
|
62
62
|
data
|
|
63
63
|
};
|
|
64
|
-
await repos.task.
|
|
64
|
+
await repos.task.runTaskByIdentifier(confirmReserveTransactionTask);
|
|
65
65
|
if (options.force === true) {
|
|
66
66
|
const existingTask = await repos.task.findByIdentifier({
|
|
67
67
|
identifier: taskIdentifier,
|
|
@@ -37,7 +37,7 @@ function onOrderProcessing(params) {
|
|
|
37
37
|
await repos.task.saveMany(tasks);
|
|
38
38
|
// uniqueness of CheckResource task(2025-03-29~)
|
|
39
39
|
if (creatingCheckResourceTask !== undefined) {
|
|
40
|
-
await repos.task.
|
|
40
|
+
await repos.task.runTaskByIdentifier(creatingCheckResourceTask);
|
|
41
41
|
}
|
|
42
42
|
switch (params.order.orderStatus) {
|
|
43
43
|
case factory_1.factory.orderStatus.OrderProcessing:
|
|
@@ -137,7 +137,7 @@ function onReservationConfirmed(confirmedReservations, reserveAction) {
|
|
|
137
137
|
await repos.task.saveMany(taskAttributes);
|
|
138
138
|
}
|
|
139
139
|
if (onAuthorizationCreatedTask !== undefined) {
|
|
140
|
-
await repos.task.
|
|
140
|
+
await repos.task.runTaskByIdentifier(onAuthorizationCreatedTask);
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { factory } from '../../../../factory';
|
|
2
2
|
import type { ISetting } from '../../../../repo/setting';
|
|
3
|
-
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.
|
|
3
|
+
type IPlaceOrderPotentialTask = factory.task.IAttributes<factory.taskName.PlaceOrder> | factory.task.IAttributes<factory.taskName.VoidPayTransaction> | factory.task.voidReserveTransaction.IAttributes;
|
|
4
4
|
/**
|
|
5
5
|
* 取引のタスクを作成する
|
|
6
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
6
7
|
*/
|
|
7
|
-
export declare function
|
|
8
|
+
export declare function createImmediateTasks(params: {
|
|
8
9
|
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
|
|
9
|
-
|
|
10
|
-
}
|
|
10
|
+
taskRunsAt: Date;
|
|
11
|
+
}): IPlaceOrderPotentialTask[];
|
|
12
|
+
export declare function createScheduledTasks(params: {
|
|
13
|
+
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'status' | 'typeOf'>;
|
|
14
|
+
}, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
|
|
11
15
|
export {};
|
|
@@ -3,114 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createImmediateTasks = createImmediateTasks;
|
|
7
|
+
exports.createScheduledTasks = createScheduledTasks;
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
9
|
const factory_1 = require("../../../../factory");
|
|
9
10
|
/**
|
|
10
11
|
* 取引のタスクを作成する
|
|
12
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
11
13
|
*/
|
|
12
|
-
function
|
|
14
|
+
function createImmediateTasks(params) {
|
|
13
15
|
const taskAttributes = [];
|
|
14
16
|
const transaction = params.transaction;
|
|
15
|
-
const taskRunsAt = params.
|
|
17
|
+
const taskRunsAt = params.taskRunsAt;
|
|
16
18
|
// 取引通知は廃止(2026-06-29~)
|
|
17
|
-
// const informTransaction = setting?.onTransactionStatusChanged?.informTransaction;
|
|
18
|
-
// const transactionWebhookUrls = (Array.isArray(informTransaction)) ? informTransaction : [];
|
|
19
|
-
// const triggerWebhookTaskAttributes: factory.task.IAttributes<factory.taskName.TriggerWebhook>[] = [];
|
|
20
|
-
// transactionWebhookUrls.forEach(({ recipient }) => {
|
|
21
|
-
// if (typeof recipient?.url === 'string') {
|
|
22
|
-
// const informObject: factory.notification.transaction.IPlaceOrderAsNotification = {
|
|
23
|
-
// id: transaction.id,
|
|
24
|
-
// typeOf: transaction.typeOf,
|
|
25
|
-
// project: transaction.project,
|
|
26
|
-
// seller: transaction.seller,
|
|
27
|
-
// startDate: transaction.startDate,
|
|
28
|
-
// status: transaction.status,
|
|
29
|
-
// ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
|
|
30
|
-
// };
|
|
31
|
-
// const data: factory.task.triggerWebhook.IInformAnyResourceAction = {
|
|
32
|
-
// object: informObject,
|
|
33
|
-
// recipient: {
|
|
34
|
-
// id: (typeof recipient?.id === 'string') ? recipient.id : '',
|
|
35
|
-
// name: recipient?.name,
|
|
36
|
-
// typeOf: factory.creativeWorkType.WebApplication
|
|
37
|
-
// // url: recipient.url // discontinue(2025-02-13~)
|
|
38
|
-
// },
|
|
39
|
-
// target: {
|
|
40
|
-
// httpMethod: 'POST',
|
|
41
|
-
// encodingType: factory.encodingFormat.Application.json,
|
|
42
|
-
// typeOf: 'EntryPoint',
|
|
43
|
-
// urlTemplate: recipient.url
|
|
44
|
-
// }
|
|
45
|
-
// };
|
|
46
|
-
// triggerWebhookTaskAttributes.push({
|
|
47
|
-
// project: transaction.project,
|
|
48
|
-
// name: factory.taskName.TriggerWebhook,
|
|
49
|
-
// status: factory.taskStatus.Ready,
|
|
50
|
-
// runsAt: taskRunsAt,
|
|
51
|
-
// remainingNumberOfTries: 3,
|
|
52
|
-
// numberOfTried: 0,
|
|
53
|
-
// executionResults: [],
|
|
54
|
-
// data
|
|
55
|
-
// });
|
|
56
|
-
// }
|
|
57
|
-
// });
|
|
58
|
-
const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
|
|
59
|
-
const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
|
|
60
|
-
if (typeof confirmedStoragePeriodInDays !== 'number') {
|
|
61
|
-
throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
|
|
62
|
-
}
|
|
63
|
-
if (typeof canceledStoragePeriodInDays !== 'number') {
|
|
64
|
-
throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
|
|
65
|
-
}
|
|
66
|
-
// 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
|
|
67
|
-
// let deleteAt = moment(transaction.endDate)
|
|
68
|
-
// .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
|
|
69
|
-
// .toDate();
|
|
70
|
-
let deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
71
|
-
.add(confirmedStoragePeriodInDays, 'days')
|
|
72
|
-
.toDate();
|
|
73
|
-
switch (transaction.status) {
|
|
74
|
-
case factory_1.factory.transactionStatusType.Confirmed:
|
|
75
|
-
break;
|
|
76
|
-
case factory_1.factory.transactionStatusType.Canceled:
|
|
77
|
-
case factory_1.factory.transactionStatusType.Expired:
|
|
78
|
-
// deleteAt = moment(transaction.endDate)
|
|
79
|
-
// .add(settings.transaction.canceledStoragePeriodInDays, 'days')
|
|
80
|
-
// .toDate();
|
|
81
|
-
deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
82
|
-
.add(canceledStoragePeriodInDays, 'days')
|
|
83
|
-
.toDate();
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
}
|
|
87
|
-
const deleteTransactionTask = {
|
|
88
|
-
project: transaction.project,
|
|
89
|
-
name: factory_1.factory.taskName.DeleteTransaction,
|
|
90
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
91
|
-
runsAt: deleteAt,
|
|
92
|
-
remainingNumberOfTries: 3,
|
|
93
|
-
numberOfTried: 0,
|
|
94
|
-
executionResults: [],
|
|
95
|
-
data: {
|
|
96
|
-
object: {
|
|
97
|
-
specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
|
|
98
|
-
id: transaction.id,
|
|
99
|
-
object: {
|
|
100
|
-
...(typeof transaction.object.confirmationNumber === 'string')
|
|
101
|
-
? { confirmationNumber: transaction.object.confirmationNumber }
|
|
102
|
-
: undefined,
|
|
103
|
-
...(typeof transaction.object.orderNumber === 'string')
|
|
104
|
-
? { orderNumber: transaction.object.orderNumber }
|
|
105
|
-
: undefined
|
|
106
|
-
},
|
|
107
|
-
// project: transaction.project,
|
|
108
|
-
// startDate: transaction.startDate,
|
|
109
|
-
typeOf: transaction.typeOf,
|
|
110
|
-
// ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
19
|
// 確定取引にも興行オファー承認中止タスクを追加(2023-05-09~)
|
|
115
20
|
const voidReserveTaskAttributes = {
|
|
116
21
|
project: transaction.project,
|
|
@@ -121,7 +26,6 @@ function createTasks(params, setting) {
|
|
|
121
26
|
numberOfTried: 0,
|
|
122
27
|
executionResults: [],
|
|
123
28
|
data: {
|
|
124
|
-
// project: transaction.project, // discontinue(2025-03-12~)
|
|
125
29
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
126
30
|
}
|
|
127
31
|
};
|
|
@@ -135,11 +39,9 @@ function createTasks(params, setting) {
|
|
|
135
39
|
numberOfTried: 0,
|
|
136
40
|
executionResults: [],
|
|
137
41
|
data: {
|
|
138
|
-
// project: transaction.project, // discontinue(2025-03-12~)
|
|
139
42
|
purpose: { typeOf: transaction.typeOf, id: transaction.id }
|
|
140
43
|
}
|
|
141
44
|
};
|
|
142
|
-
taskAttributes.push(deleteTransactionTask);
|
|
143
45
|
switch (transaction.status) {
|
|
144
46
|
case factory_1.factory.transactionStatusType.Confirmed: {
|
|
145
47
|
taskAttributes.push(voidReserveTaskAttributes, voidPaymentTaskAttributes);
|
|
@@ -188,3 +90,53 @@ function createTasks(params, setting) {
|
|
|
188
90
|
}
|
|
189
91
|
return taskAttributes;
|
|
190
92
|
}
|
|
93
|
+
function createScheduledTasks(params, setting) {
|
|
94
|
+
const transaction = params.transaction;
|
|
95
|
+
const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
|
|
96
|
+
const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
|
|
97
|
+
if (typeof confirmedStoragePeriodInDays !== 'number') {
|
|
98
|
+
throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
|
|
99
|
+
}
|
|
100
|
+
if (typeof canceledStoragePeriodInDays !== 'number') {
|
|
101
|
+
throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
|
|
102
|
+
}
|
|
103
|
+
// 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
|
|
104
|
+
let deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
105
|
+
.add(confirmedStoragePeriodInDays, 'days')
|
|
106
|
+
.toDate();
|
|
107
|
+
switch (transaction.status) {
|
|
108
|
+
case factory_1.factory.transactionStatusType.Confirmed:
|
|
109
|
+
break;
|
|
110
|
+
case factory_1.factory.transactionStatusType.Canceled:
|
|
111
|
+
case factory_1.factory.transactionStatusType.Expired:
|
|
112
|
+
deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
113
|
+
.add(canceledStoragePeriodInDays, 'days')
|
|
114
|
+
.toDate();
|
|
115
|
+
break;
|
|
116
|
+
default:
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
project: transaction.project,
|
|
120
|
+
name: factory_1.factory.taskName.DeleteTransaction,
|
|
121
|
+
status: factory_1.factory.taskStatus.Ready,
|
|
122
|
+
runsAt: deleteAt,
|
|
123
|
+
remainingNumberOfTries: 3,
|
|
124
|
+
numberOfTried: 0,
|
|
125
|
+
executionResults: [],
|
|
126
|
+
data: {
|
|
127
|
+
object: {
|
|
128
|
+
specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
|
|
129
|
+
id: transaction.id,
|
|
130
|
+
object: {
|
|
131
|
+
...(typeof transaction.object.confirmationNumber === 'string')
|
|
132
|
+
? { confirmationNumber: transaction.object.confirmationNumber }
|
|
133
|
+
: undefined,
|
|
134
|
+
...(typeof transaction.object.orderNumber === 'string')
|
|
135
|
+
? { orderNumber: transaction.object.orderNumber }
|
|
136
|
+
: undefined
|
|
137
|
+
},
|
|
138
|
+
typeOf: transaction.typeOf,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { SettingRepo } from '../../../repo/setting';
|
|
2
|
+
import type { ScheduledTaskRepo } from '../../../repo/scheduledTask';
|
|
2
3
|
import type { TaskRepo } from '../../../repo/task';
|
|
3
4
|
import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
4
5
|
interface IExportTasksByIdRepos {
|
|
5
6
|
setting: SettingRepo;
|
|
7
|
+
scheduledTask: ScheduledTaskRepo;
|
|
6
8
|
task: TaskRepo;
|
|
7
9
|
placeOrder: PlaceOrderRepo;
|
|
8
10
|
}
|
|
@@ -11,9 +11,7 @@ const factory_2 = require("./exportTasks/factory");
|
|
|
11
11
|
* 取引のタスクを出力します
|
|
12
12
|
*/
|
|
13
13
|
function exportTasksById(params) {
|
|
14
|
-
return async (repos
|
|
15
|
-
// settings: Settings
|
|
16
|
-
) => {
|
|
14
|
+
return async (repos) => {
|
|
17
15
|
const transaction = await repos.placeOrder.findPlaceOrderById({
|
|
18
16
|
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
19
17
|
id: params.id
|
|
@@ -27,12 +25,24 @@ function exportTasksById(params) {
|
|
|
27
25
|
}
|
|
28
26
|
// search settings
|
|
29
27
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
|
|
29
|
+
const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
|
|
30
|
+
const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
|
|
31
|
+
if (useScheduledDeleteTransactionTask && typeof deleteTransactionTaskExpiresInDays === 'number' && deleteTransactionTaskExpiresInDays > 0) {
|
|
32
|
+
// support scheduledTask(2026-08-02~)
|
|
33
|
+
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
34
|
+
await repos.scheduledTask.addScheduledTasks([{
|
|
35
|
+
...deleteTask,
|
|
36
|
+
expires: (0, moment_1.default)(deleteTask.runsAt)
|
|
37
|
+
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
38
|
+
.toDate()
|
|
39
|
+
}]);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
await repos.task.saveMany([
|
|
43
|
+
...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
|
|
44
|
+
deleteTask
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
37
47
|
};
|
|
38
48
|
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { ISetting } from '../../../../repo/setting';
|
|
2
2
|
import { factory } from '../../../../factory';
|
|
3
|
+
type IReturnOrderPotentialTask = factory.task.IAttributes<factory.taskName.ReturnOrder>;
|
|
3
4
|
/**
|
|
4
5
|
* 取引のタスクを作成する
|
|
6
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
5
7
|
*/
|
|
6
|
-
export declare function
|
|
8
|
+
export declare function createImmediateTasks(params: {
|
|
7
9
|
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'startDate' | 'object' | 'potentialActions'>;
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
+
taskRunsAt: Date;
|
|
11
|
+
}): IReturnOrderPotentialTask[];
|
|
12
|
+
/**
|
|
13
|
+
* 取引のタスクを作成する
|
|
14
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
15
|
+
*/
|
|
16
|
+
export declare function createScheduledTasks(params: {
|
|
17
|
+
transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'object'>;
|
|
18
|
+
}, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
|
|
19
|
+
export {};
|
|
@@ -3,18 +3,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createImmediateTasks = createImmediateTasks;
|
|
7
|
+
exports.createScheduledTasks = createScheduledTasks;
|
|
7
8
|
const moment_1 = __importDefault(require("moment"));
|
|
8
9
|
const factory_1 = require("../../../../factory");
|
|
9
10
|
/**
|
|
10
11
|
* 取引のタスクを作成する
|
|
12
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
11
13
|
*/
|
|
12
|
-
function
|
|
13
|
-
// settings: Settings
|
|
14
|
-
) {
|
|
14
|
+
function createImmediateTasks(params) {
|
|
15
15
|
const taskAttributes = [];
|
|
16
16
|
const transaction = params.transaction;
|
|
17
|
-
const taskRunsAt = params.
|
|
17
|
+
const taskRunsAt = params.taskRunsAt;
|
|
18
|
+
switch (transaction.status) {
|
|
19
|
+
case factory_1.factory.transactionStatusType.Confirmed: {
|
|
20
|
+
const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
|
|
21
|
+
if (Array.isArray(returnOrderPotentialActions)) {
|
|
22
|
+
// 返品タスク
|
|
23
|
+
const returnOrderTask = returnOrderPotentialActions.map((r) => {
|
|
24
|
+
// data最適化(2023-08-22~)
|
|
25
|
+
const returnOrderTaskData = {
|
|
26
|
+
agent: r.agent,
|
|
27
|
+
object: r.object,
|
|
28
|
+
project: transaction.project,
|
|
29
|
+
typeOf: r.typeOf
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
project: transaction.project,
|
|
33
|
+
name: factory_1.factory.taskName.ReturnOrder,
|
|
34
|
+
status: factory_1.factory.taskStatus.Ready,
|
|
35
|
+
runsAt: taskRunsAt,
|
|
36
|
+
remainingNumberOfTries: 10,
|
|
37
|
+
numberOfTried: 0,
|
|
38
|
+
executionResults: [],
|
|
39
|
+
data: returnOrderTaskData
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
taskAttributes.push(...returnOrderTask);
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case factory_1.factory.transactionStatusType.Expired:
|
|
47
|
+
// 特にタスクなし
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
51
|
+
}
|
|
52
|
+
return taskAttributes;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 取引のタスクを作成する
|
|
56
|
+
* 取引削除タスクを分離(2026-08-02~)
|
|
57
|
+
*/
|
|
58
|
+
function createScheduledTasks(params, setting) {
|
|
59
|
+
const transaction = params.transaction;
|
|
18
60
|
const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
|
|
19
61
|
const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
|
|
20
62
|
if (typeof confirmedStoragePeriodInDays !== 'number') {
|
|
@@ -24,9 +66,6 @@ function createTasks(params, setting
|
|
|
24
66
|
throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
|
|
25
67
|
}
|
|
26
68
|
// 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
|
|
27
|
-
// let deleteAt = moment(transaction.endDate)
|
|
28
|
-
// .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
|
|
29
|
-
// .toDate();
|
|
30
69
|
let deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
31
70
|
.add(confirmedStoragePeriodInDays, 'days')
|
|
32
71
|
.toDate();
|
|
@@ -35,16 +74,13 @@ function createTasks(params, setting
|
|
|
35
74
|
break;
|
|
36
75
|
case factory_1.factory.transactionStatusType.Canceled:
|
|
37
76
|
case factory_1.factory.transactionStatusType.Expired:
|
|
38
|
-
// deleteAt = moment(transaction.endDate)
|
|
39
|
-
// .add(settings.transaction.canceledStoragePeriodInDays, 'days')
|
|
40
|
-
// .toDate();
|
|
41
77
|
deleteAt = (0, moment_1.default)(transaction.endDate)
|
|
42
78
|
.add(canceledStoragePeriodInDays, 'days')
|
|
43
79
|
.toDate();
|
|
44
80
|
break;
|
|
45
81
|
default:
|
|
46
82
|
}
|
|
47
|
-
|
|
83
|
+
return {
|
|
48
84
|
project: transaction.project,
|
|
49
85
|
name: factory_1.factory.taskName.DeleteTransaction,
|
|
50
86
|
status: factory_1.factory.taskStatus.Ready,
|
|
@@ -59,47 +95,8 @@ function createTasks(params, setting
|
|
|
59
95
|
object: {
|
|
60
96
|
order: transaction.object.order
|
|
61
97
|
},
|
|
62
|
-
// project: transaction.project,
|
|
63
|
-
// startDate: transaction.startDate,
|
|
64
98
|
typeOf: transaction.typeOf,
|
|
65
|
-
// ...(transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined
|
|
66
99
|
}
|
|
67
100
|
}
|
|
68
101
|
};
|
|
69
|
-
taskAttributes.push(deleteTransactionTask);
|
|
70
|
-
switch (transaction.status) {
|
|
71
|
-
case factory_1.factory.transactionStatusType.Confirmed: {
|
|
72
|
-
const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
|
|
73
|
-
if (Array.isArray(returnOrderPotentialActions)) {
|
|
74
|
-
// 返品タスク
|
|
75
|
-
const returnOrderTask = returnOrderPotentialActions.map((r) => {
|
|
76
|
-
// data最適化(2023-08-22~)
|
|
77
|
-
const returnOrderTaskData = {
|
|
78
|
-
agent: r.agent,
|
|
79
|
-
object: r.object,
|
|
80
|
-
project: transaction.project,
|
|
81
|
-
typeOf: r.typeOf
|
|
82
|
-
};
|
|
83
|
-
return {
|
|
84
|
-
project: transaction.project,
|
|
85
|
-
name: factory_1.factory.taskName.ReturnOrder,
|
|
86
|
-
status: factory_1.factory.taskStatus.Ready,
|
|
87
|
-
runsAt: taskRunsAt,
|
|
88
|
-
remainingNumberOfTries: 10,
|
|
89
|
-
numberOfTried: 0,
|
|
90
|
-
executionResults: [],
|
|
91
|
-
data: returnOrderTaskData
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
taskAttributes.push(...returnOrderTask);
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
case factory_1.factory.transactionStatusType.Expired:
|
|
99
|
-
// 特にタスクなし
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
|
|
103
|
-
}
|
|
104
|
-
return taskAttributes;
|
|
105
102
|
}
|
|
@@ -11,6 +11,7 @@ import type { ReservationRepo } from '../../repo/reservation';
|
|
|
11
11
|
import type { SellerRepo } from '../../repo/seller';
|
|
12
12
|
import type { SellerReturnPolicyRepo } from '../../repo/sellerReturnPolicy';
|
|
13
13
|
import type { SettingRepo } from '../../repo/setting';
|
|
14
|
+
import type { ScheduledTaskRepo } from '../../repo/scheduledTask';
|
|
14
15
|
import type { TaskRepo } from '../../repo/task';
|
|
15
16
|
import type { IStartedTransaction, ReturnOrderRepo } from '../../repo/transaction/returnOrder';
|
|
16
17
|
import { preStart } from './returnOrder/preStart';
|
|
@@ -30,6 +31,7 @@ interface IStartOperationRepos {
|
|
|
30
31
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
31
32
|
interface IExportTasksByIdRepos {
|
|
32
33
|
setting: SettingRepo;
|
|
34
|
+
scheduledTask: ScheduledTaskRepo;
|
|
33
35
|
task: TaskRepo;
|
|
34
36
|
returnOrder: ReturnOrderRepo;
|
|
35
37
|
}
|
|
@@ -79,9 +79,7 @@ function saveMessagesIfNeeded(params) {
|
|
|
79
79
|
* 取引確定
|
|
80
80
|
*/
|
|
81
81
|
function confirm(params) {
|
|
82
|
-
return async (repos
|
|
83
|
-
// settings: Settings
|
|
84
|
-
) => {
|
|
82
|
+
return async (repos) => {
|
|
85
83
|
const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result']);
|
|
86
84
|
if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
|
|
87
85
|
// すでに確定済の場合
|
|
@@ -158,9 +156,7 @@ function confirm(params) {
|
|
|
158
156
|
* この関数では、取引のタスクエクスポートステータスは見ません
|
|
159
157
|
*/
|
|
160
158
|
function exportTasksById(params) {
|
|
161
|
-
return async (repos
|
|
162
|
-
// settings: Settings
|
|
163
|
-
) => {
|
|
159
|
+
return async (repos) => {
|
|
164
160
|
const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
|
|
165
161
|
// タスク実行日時バッファの指定があれば調整
|
|
166
162
|
let taskRunsAt = new Date();
|
|
@@ -171,12 +167,24 @@ function exportTasksById(params) {
|
|
|
171
167
|
}
|
|
172
168
|
// search settings
|
|
173
169
|
const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
170
|
+
const useScheduledDeleteTransactionTask = setting?.storage?.useScheduledDeleteTransactionTask === true;
|
|
171
|
+
const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
|
|
172
|
+
const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
|
|
173
|
+
if (useScheduledDeleteTransactionTask && typeof deleteTransactionTaskExpiresInDays === 'number' && deleteTransactionTaskExpiresInDays > 0) {
|
|
174
|
+
// support scheduledTask(2026-08-02~)
|
|
175
|
+
await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
|
|
176
|
+
await repos.scheduledTask.addScheduledTasks([{
|
|
177
|
+
...deleteTask,
|
|
178
|
+
expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
|
|
179
|
+
.add(deleteTransactionTaskExpiresInDays, 'days')
|
|
180
|
+
.toDate()
|
|
181
|
+
}]);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
await repos.task.saveMany([
|
|
185
|
+
...(0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }),
|
|
186
|
+
deleteTask
|
|
187
|
+
]);
|
|
188
|
+
}
|
|
181
189
|
};
|
|
182
190
|
}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { factory } from '../factory';
|
|
5
5
|
import type { SettingRepo } from '../repo/setting';
|
|
6
|
+
import type { ScheduledTaskRepo } from '../repo/scheduledTask';
|
|
6
7
|
import type { TaskRepo } from '../repo/task';
|
|
7
8
|
import type { TransactionRepo } from '../repo/transaction';
|
|
8
9
|
import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
|
|
@@ -18,6 +19,7 @@ export import returnOrder = ReturnOrderTransactionService;
|
|
|
18
19
|
export { deleteTransaction };
|
|
19
20
|
export type IExportTasksOperation<T> = (repos: {
|
|
20
21
|
setting: SettingRepo;
|
|
22
|
+
scheduledTask: ScheduledTaskRepo;
|
|
21
23
|
task: TaskRepo;
|
|
22
24
|
placeOrder: PlaceOrderRepo;
|
|
23
25
|
returnOrder: ReturnOrderRepo;
|
|
@@ -52,7 +52,6 @@ function exportOneTransactionTasksIfExists(params) {
|
|
|
52
52
|
agent: { name: params.tasksExportAction.agent.name }
|
|
53
53
|
},
|
|
54
54
|
endDate: { $lt: params.endDate.$lt },
|
|
55
|
-
// ...(params.typeOf !== undefined) ? { typeOf: params.typeOf } : undefined,
|
|
56
55
|
...(typeof params.id === 'string') ? { id: params.id } : undefined,
|
|
57
56
|
...(typeof params.status?.$eq === 'string') ? { status: params.status } : undefined,
|
|
58
57
|
...(params.sort !== undefined) ? { sort: params.sort } : undefined
|
|
@@ -65,7 +64,6 @@ function exportOneTransactionTasksIfExists(params) {
|
|
|
65
64
|
case factory_1.factory.transactionType.PlaceOrder:
|
|
66
65
|
await PlaceOrderTransactionService.exportTasksById({
|
|
67
66
|
id: transaction.id,
|
|
68
|
-
// optimizeRedundantTasks: params.optimizeRedundantTasks === true,
|
|
69
67
|
...(typeof params.runsTasksAfterInSeconds === 'number')
|
|
70
68
|
? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
|
|
71
69
|
: undefined
|
package/package.json
CHANGED