@chevre/domain 26.0.0-alpha.1 → 26.0.0-alpha.11
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/adminAsyncAction.d.ts +19 -0
- package/lib/chevre/repo/adminAsyncAction.js +86 -0
- package/lib/chevre/repo/aggregateScheduledTask.d.ts +32 -0
- package/lib/chevre/repo/aggregateScheduledTask.js +136 -0
- package/lib/chevre/repo/asyncAction.d.ts +3 -8
- package/lib/chevre/repo/asyncAction.js +0 -108
- package/lib/chevre/repo/asyncActionLegacy.d.ts +23 -0
- package/lib/chevre/repo/asyncActionLegacy.js +59 -0
- package/lib/chevre/repo/mongoose/schemas/setting.d.ts +2 -4
- package/lib/chevre/repo/orderInTransaction.d.ts +0 -3
- package/lib/chevre/repo/orderInTransaction.js +30 -22
- package/lib/chevre/repo/scheduledTask.d.ts +1 -1
- package/lib/chevre/repo/scheduledTaskLegacy.d.ts +39 -0
- package/lib/chevre/repo/scheduledTaskLegacy.js +96 -0
- package/lib/chevre/repo/scheduledTaskMigration.d.ts +21 -0
- package/lib/chevre/repo/scheduledTaskMigration.js +70 -0
- package/lib/chevre/repo/task.d.ts +35 -68
- package/lib/chevre/repo/task.js +257 -177
- package/lib/chevre/repository.d.ts +20 -0
- package/lib/chevre/repository.js +46 -2
- package/lib/chevre/service/aggregation/system.d.ts +10 -2
- package/lib/chevre/service/aggregation/system.js +42 -0
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +5 -25
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +19 -19
- 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/payment/any/findAcceptAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAcceptAction.js +19 -19
- package/lib/chevre/service/payment/any/findAuthorizeAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +19 -19
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +0 -4
- package/lib/chevre/service/payment/any/findCheckAction.js +19 -19
- package/lib/chevre/service/payment/any/publishPaymentUrl.d.ts +0 -2
- package/lib/chevre/service/payment/any/publishPaymentUrl.js +2 -2
- package/lib/chevre/service/reserve/confirmReservation.js +19 -26
- package/lib/chevre/service/reserve/factory.d.ts +0 -3
- package/lib/chevre/service/reserve/factory.js +0 -4
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.d.ts +4 -13
- package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +21 -61
- package/lib/chevre/service/task/importEventCapacitiesFromCOA.js +4 -1
- package/lib/chevre/service/task/importEventsFromCOA.js +4 -1
- package/lib/chevre/service/task/importOffersFromCOA.js +5 -5
- package/lib/chevre/service/task/publishPaymentUrl.js +1 -3
- package/lib/chevre/service/task.d.ts +1 -20
- package/lib/chevre/service/task.js +0 -28
- package/lib/chevre/service/taskHandler.js +0 -34
- 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 +2 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
import { IDocType } from './mongoose/schemas/asyncAction';
|
|
4
|
+
import type { IExecutableTask } from '../taskSettings';
|
|
5
|
+
export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
|
|
6
|
+
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
|
|
7
|
+
type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
|
|
8
|
+
/**
|
|
9
|
+
* 非同期アクション管理リポジトリ
|
|
10
|
+
*/
|
|
11
|
+
export declare class AdminAsyncActionRepo {
|
|
12
|
+
private readonly asyncActionModel;
|
|
13
|
+
constructor(connection: Connection);
|
|
14
|
+
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
|
|
15
|
+
findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
|
|
16
|
+
id: string;
|
|
17
|
+
})[]>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AdminAsyncActionRepo = void 0;
|
|
4
|
+
const settings_1 = require("../settings");
|
|
5
|
+
const asyncAction_1 = require("./mongoose/schemas/asyncAction");
|
|
6
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
7
|
+
'project',
|
|
8
|
+
'name',
|
|
9
|
+
'status',
|
|
10
|
+
'runsAt',
|
|
11
|
+
'lastTriedAt',
|
|
12
|
+
'executionResults',
|
|
13
|
+
'executor',
|
|
14
|
+
'data',
|
|
15
|
+
'dateAborted',
|
|
16
|
+
'expires'
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* 非同期アクション管理リポジトリ
|
|
20
|
+
*/
|
|
21
|
+
class AdminAsyncActionRepo {
|
|
22
|
+
asyncActionModel;
|
|
23
|
+
constructor(connection) {
|
|
24
|
+
this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
|
|
25
|
+
}
|
|
26
|
+
static CREATE_MONGO_CONDITIONS(params) {
|
|
27
|
+
const andConditions = [];
|
|
28
|
+
const idEq = params.id?.$eq;
|
|
29
|
+
if (typeof idEq === 'string') {
|
|
30
|
+
andConditions.push({ _id: { $eq: idEq } });
|
|
31
|
+
}
|
|
32
|
+
const projectIdEq = params.project?.id?.$eq;
|
|
33
|
+
if (typeof projectIdEq === 'string') {
|
|
34
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
35
|
+
}
|
|
36
|
+
if (typeof params.name === 'string') {
|
|
37
|
+
andConditions.push({ name: { $eq: params.name } });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const nameIn = params.name?.$in;
|
|
41
|
+
if (Array.isArray(nameIn)) {
|
|
42
|
+
andConditions.push({ name: { $in: nameIn } });
|
|
43
|
+
}
|
|
44
|
+
const nameNin = params.name?.$nin;
|
|
45
|
+
if (Array.isArray(nameNin)) {
|
|
46
|
+
andConditions.push({ name: { $nin: nameNin } });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const statusEq = params.status?.$eq;
|
|
50
|
+
if (typeof statusEq === 'string') {
|
|
51
|
+
andConditions.push({ status: { $eq: statusEq } });
|
|
52
|
+
}
|
|
53
|
+
if (params.runsFrom instanceof Date) {
|
|
54
|
+
andConditions.push({ runsAt: { $gte: params.runsFrom } });
|
|
55
|
+
}
|
|
56
|
+
if (params.runsThrough instanceof Date) {
|
|
57
|
+
andConditions.push({ runsAt: { $lte: params.runsThrough } });
|
|
58
|
+
}
|
|
59
|
+
return andConditions;
|
|
60
|
+
}
|
|
61
|
+
async findAsyncActions(params, inclusion) {
|
|
62
|
+
const conditions = AdminAsyncActionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
63
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
64
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
65
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
66
|
+
}
|
|
67
|
+
const projection = {
|
|
68
|
+
_id: 0,
|
|
69
|
+
id: { $toString: '$_id' },
|
|
70
|
+
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
71
|
+
};
|
|
72
|
+
const query = this.asyncActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
73
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
74
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
75
|
+
query.limit(params.limit)
|
|
76
|
+
.skip(params.limit * (page - 1));
|
|
77
|
+
}
|
|
78
|
+
if (params.sort?.runsAt !== undefined) {
|
|
79
|
+
query.sort({ runsAt: params.sort.runsAt });
|
|
80
|
+
}
|
|
81
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
82
|
+
.lean()
|
|
83
|
+
.exec();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.AdminAsyncActionRepo = AdminAsyncActionRepo;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../factory';
|
|
3
|
+
interface IAggregationByStatus {
|
|
4
|
+
taskCount: number;
|
|
5
|
+
avgLatency: number;
|
|
6
|
+
maxLatency: number;
|
|
7
|
+
minLatency: number;
|
|
8
|
+
percentilesLatency: {
|
|
9
|
+
name: string;
|
|
10
|
+
value: number;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
interface IStatus {
|
|
14
|
+
status: factory.taskStatus;
|
|
15
|
+
aggregation: IAggregationByStatus;
|
|
16
|
+
}
|
|
17
|
+
interface IAggregateTask {
|
|
18
|
+
statuses: IStatus[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 予定タスク集計リポジトリ
|
|
22
|
+
*/
|
|
23
|
+
export declare class AggregateScheduledTaskRepo {
|
|
24
|
+
private readonly scheduledTaskModel;
|
|
25
|
+
constructor(connection: Connection);
|
|
26
|
+
aggregateScheduledTask(params: {
|
|
27
|
+
runsFrom: Date;
|
|
28
|
+
runsThrough: Date;
|
|
29
|
+
}): Promise<IAggregateTask>;
|
|
30
|
+
private agggregateByStatus;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AggregateScheduledTaskRepo = void 0;
|
|
4
|
+
const factory_1 = require("../factory");
|
|
5
|
+
const scheduledTasks_1 = require("./mongoose/schemas/scheduledTasks");
|
|
6
|
+
/**
|
|
7
|
+
* 予定タスク集計リポジトリ
|
|
8
|
+
*/
|
|
9
|
+
class AggregateScheduledTaskRepo {
|
|
10
|
+
scheduledTaskModel;
|
|
11
|
+
constructor(connection) {
|
|
12
|
+
this.scheduledTaskModel = connection.model(scheduledTasks_1.modelName, (0, scheduledTasks_1.createSchema)());
|
|
13
|
+
}
|
|
14
|
+
async aggregateScheduledTask(params) {
|
|
15
|
+
const statuses = await Promise.all([
|
|
16
|
+
factory_1.factory.taskStatus.Executed,
|
|
17
|
+
factory_1.factory.taskStatus.Aborted
|
|
18
|
+
].map(async (taskStatus) => {
|
|
19
|
+
const matchConditions = {
|
|
20
|
+
status: { $eq: taskStatus },
|
|
21
|
+
runsAt: {
|
|
22
|
+
$gte: params.runsFrom,
|
|
23
|
+
$lte: params.runsThrough
|
|
24
|
+
},
|
|
25
|
+
// ...(typeof params.project?.id?.$ne === 'string')
|
|
26
|
+
// ? { 'project.id': { $ne: params.project.id.$ne } }
|
|
27
|
+
// : undefined
|
|
28
|
+
};
|
|
29
|
+
return this.agggregateByStatus({ matchConditions, status: taskStatus });
|
|
30
|
+
}));
|
|
31
|
+
return { statuses };
|
|
32
|
+
}
|
|
33
|
+
async agggregateByStatus(params) {
|
|
34
|
+
const matchConditions = params.matchConditions;
|
|
35
|
+
const taskStatus = params.status;
|
|
36
|
+
const aggregate1 = this.scheduledTaskModel.aggregate([
|
|
37
|
+
{
|
|
38
|
+
$match: matchConditions
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
$project: {
|
|
42
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
43
|
+
status: '$status',
|
|
44
|
+
runsAt: '$runsAt',
|
|
45
|
+
lastTriedAt: '$lastTriedAt'
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
$group: {
|
|
50
|
+
_id: '$status',
|
|
51
|
+
taskCount: { $sum: 1 },
|
|
52
|
+
maxLatency: { $max: '$latency' },
|
|
53
|
+
minLatency: { $min: '$latency' },
|
|
54
|
+
avgLatency: { $avg: '$latency' }
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
$project: {
|
|
59
|
+
_id: 0,
|
|
60
|
+
taskCount: '$taskCount',
|
|
61
|
+
avgLatency: '$avgLatency',
|
|
62
|
+
maxLatency: '$maxLatency',
|
|
63
|
+
minLatency: '$minLatency'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
]);
|
|
67
|
+
// const explainResult = await aggregate1.explain();
|
|
68
|
+
// console.dir(explainResult, { depth: null });
|
|
69
|
+
// return;
|
|
70
|
+
const aggregations = await aggregate1.exec();
|
|
71
|
+
const percents = [50, 95, 99];
|
|
72
|
+
if (aggregations.length === 0) {
|
|
73
|
+
return {
|
|
74
|
+
status: taskStatus,
|
|
75
|
+
aggregation: {
|
|
76
|
+
taskCount: 0,
|
|
77
|
+
avgLatency: 0,
|
|
78
|
+
maxLatency: 0,
|
|
79
|
+
minLatency: 0,
|
|
80
|
+
percentilesLatency: percents.map((percent) => {
|
|
81
|
+
return {
|
|
82
|
+
name: String(percent),
|
|
83
|
+
value: 0
|
|
84
|
+
};
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const ranks4percentile = percents.map((percentile) => {
|
|
90
|
+
return {
|
|
91
|
+
percentile,
|
|
92
|
+
rank: Math.floor(aggregations[0].taskCount * percentile / 100)
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const aggregate2 = this.scheduledTaskModel.aggregate([
|
|
96
|
+
{
|
|
97
|
+
$match: matchConditions
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
$project: {
|
|
101
|
+
latency: { $subtract: ['$lastTriedAt', '$runsAt'] },
|
|
102
|
+
status: '$status',
|
|
103
|
+
runsAt: '$runsAt',
|
|
104
|
+
lastTriedAt: '$lastTriedAt'
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
{ $sort: { latency: 1 } },
|
|
108
|
+
{
|
|
109
|
+
$group: {
|
|
110
|
+
_id: '$status',
|
|
111
|
+
latencies: { $push: '$latency' }
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
$project: {
|
|
116
|
+
_id: 0,
|
|
117
|
+
percentilesLatency: ranks4percentile.map((rank) => {
|
|
118
|
+
return {
|
|
119
|
+
name: String(rank.percentile),
|
|
120
|
+
value: { $arrayElemAt: ['$latencies', rank.rank] }
|
|
121
|
+
};
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
]);
|
|
126
|
+
const aggregations2 = await aggregate2.exec();
|
|
127
|
+
return {
|
|
128
|
+
status: taskStatus,
|
|
129
|
+
aggregation: {
|
|
130
|
+
...aggregations[0],
|
|
131
|
+
...aggregations2[0]
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.AggregateScheduledTaskRepo = AggregateScheduledTaskRepo;
|
|
@@ -1,23 +1,18 @@
|
|
|
1
|
-
import type { Connection
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
|
-
import {
|
|
3
|
+
import { IDocType } from './mongoose/schemas/asyncAction';
|
|
4
4
|
import type { IExecutableTask } from '../taskSettings';
|
|
5
5
|
type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'executionResults' | 'name' | 'project' | 'runsAt' | 'status'> & {
|
|
6
6
|
expires: Date;
|
|
7
7
|
};
|
|
8
8
|
export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
|
|
9
9
|
type IKeyOfProjection = keyof factory.task.ITask<factory.taskName> | 'expires';
|
|
10
|
-
type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
|
|
11
10
|
/**
|
|
12
11
|
* 非同期アクションリポジトリ
|
|
13
12
|
*/
|
|
14
13
|
export declare class AsyncActionRepo {
|
|
15
|
-
readonly asyncActionModel
|
|
14
|
+
private readonly asyncActionModel;
|
|
16
15
|
constructor(connection: Connection);
|
|
17
|
-
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status'>): FilterQuery<import("@chevre/factory/lib/chevre/task").ITask | import("@chevre/factory/lib/chevre/task/confirmPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/confirmReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/createAccountingReport").ITask | import("@chevre/factory/lib/chevre/task/onAssetTransactionStatusChanged").ITask | import("@chevre/factory/lib/chevre/task/onAuthorizationCreated").ITask | import("@chevre/factory/lib/chevre/task/onEventChanged").ITask | import("@chevre/factory/lib/chevre/task/onResourceDeleted").ITask | import("@chevre/factory/lib/chevre/task/onResourceUpdated").ITask | import("@chevre/factory/lib/chevre/task/onOrderPaymentCompleted").ITask | import("@chevre/factory/lib/chevre/task/placeOrder").ITask | import("@chevre/factory/lib/chevre/task/returnOrder").ITask | import("@chevre/factory/lib/chevre/task/returnPayTransaction").ITask | import("@chevre/factory/lib/chevre/task/returnReserveTransaction").ITask | import("@chevre/factory/lib/chevre/task/sendEmailMessage").ITask | import("@chevre/factory/lib/chevre/task/sendOrder").ITask | import("@chevre/factory/lib/chevre/task/triggerWebhook").ITask | import("@chevre/factory/lib/chevre/task/useReservation").ITask | import("@chevre/factory/lib/chevre/task/voidPayTransaction").ITask>[];
|
|
18
|
-
findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
|
|
19
|
-
id: string;
|
|
20
|
-
})[]>;
|
|
21
16
|
/**
|
|
22
17
|
* Readyタスクをひとつ追加する
|
|
23
18
|
*/
|
|
@@ -35,65 +35,6 @@ class AsyncActionRepo {
|
|
|
35
35
|
constructor(connection) {
|
|
36
36
|
this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
|
|
37
37
|
}
|
|
38
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
39
|
-
const andConditions = [];
|
|
40
|
-
const idEq = params.id?.$eq;
|
|
41
|
-
if (typeof idEq === 'string') {
|
|
42
|
-
andConditions.push({ _id: { $eq: idEq } });
|
|
43
|
-
}
|
|
44
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
45
|
-
if (typeof projectIdEq === 'string') {
|
|
46
|
-
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
47
|
-
}
|
|
48
|
-
if (typeof params.name === 'string') {
|
|
49
|
-
andConditions.push({ name: { $eq: params.name } });
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
const nameIn = params.name?.$in;
|
|
53
|
-
if (Array.isArray(nameIn)) {
|
|
54
|
-
andConditions.push({ name: { $in: nameIn } });
|
|
55
|
-
}
|
|
56
|
-
const nameNin = params.name?.$nin;
|
|
57
|
-
if (Array.isArray(nameNin)) {
|
|
58
|
-
andConditions.push({ name: { $nin: nameNin } });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const statusEq = params.status?.$eq;
|
|
62
|
-
if (typeof statusEq === 'string') {
|
|
63
|
-
andConditions.push({ status: { $eq: statusEq } });
|
|
64
|
-
}
|
|
65
|
-
if (params.runsFrom instanceof Date) {
|
|
66
|
-
andConditions.push({ runsAt: { $gte: params.runsFrom } });
|
|
67
|
-
}
|
|
68
|
-
if (params.runsThrough instanceof Date) {
|
|
69
|
-
andConditions.push({ runsAt: { $lte: params.runsThrough } });
|
|
70
|
-
}
|
|
71
|
-
return andConditions;
|
|
72
|
-
}
|
|
73
|
-
async findAsyncActions(params, inclusion) {
|
|
74
|
-
const conditions = AsyncActionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
75
|
-
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
76
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
77
|
-
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
78
|
-
}
|
|
79
|
-
const projection = {
|
|
80
|
-
_id: 0,
|
|
81
|
-
id: { $toString: '$_id' },
|
|
82
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
83
|
-
};
|
|
84
|
-
const query = this.asyncActionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
85
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
86
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
87
|
-
query.limit(params.limit)
|
|
88
|
-
.skip(params.limit * (page - 1));
|
|
89
|
-
}
|
|
90
|
-
if (params.sort?.runsAt !== undefined) {
|
|
91
|
-
query.sort({ runsAt: params.sort.runsAt });
|
|
92
|
-
}
|
|
93
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
94
|
-
.lean()
|
|
95
|
-
.exec();
|
|
96
|
-
}
|
|
97
38
|
/**
|
|
98
39
|
* Readyタスクをひとつ追加する
|
|
99
40
|
*/
|
|
@@ -168,55 +109,6 @@ class AsyncActionRepo {
|
|
|
168
109
|
}
|
|
169
110
|
return doc;
|
|
170
111
|
}
|
|
171
|
-
// /**
|
|
172
|
-
// * Readyのままで期限切れのタスクをExpiredに変更する
|
|
173
|
-
// */
|
|
174
|
-
// public async makeExpiredMany(params: {
|
|
175
|
-
// expiresLt: Date;
|
|
176
|
-
// }): Promise<UpdateWriteOpResult> {
|
|
177
|
-
// const { expiresLt } = params;
|
|
178
|
-
// if (!(expiresLt instanceof Date)) {
|
|
179
|
-
// throw new factory.errors.Argument('expiresLt', 'must be Date');
|
|
180
|
-
// }
|
|
181
|
-
// return this.asyncActionModel.updateMany(
|
|
182
|
-
// {
|
|
183
|
-
// status: { $eq: factory.taskStatus.Ready },
|
|
184
|
-
// expires: { $lt: expiresLt }
|
|
185
|
-
// },
|
|
186
|
-
// {
|
|
187
|
-
// $set: {
|
|
188
|
-
// status: factory.taskStatus.Expired
|
|
189
|
-
// }
|
|
190
|
-
// }
|
|
191
|
-
// )
|
|
192
|
-
// .exec();
|
|
193
|
-
// }
|
|
194
|
-
// /**
|
|
195
|
-
// * taskNameに関わらず、Runningのまま放置された非同期アクションをAbortedに変更する
|
|
196
|
-
// */
|
|
197
|
-
// public async abortMany(params: {
|
|
198
|
-
// intervalInMinutes: number;
|
|
199
|
-
// }): Promise<UpdateWriteOpResult> {
|
|
200
|
-
// const lastTriedAtShoudBeLessThan = moment()
|
|
201
|
-
// .add(-params.intervalInMinutes, 'minutes')
|
|
202
|
-
// .toDate();
|
|
203
|
-
// return this.asyncActionModel.updateMany(
|
|
204
|
-
// {
|
|
205
|
-
// status: { $eq: factory.taskStatus.Running },
|
|
206
|
-
// lastTriedAt: {
|
|
207
|
-
// $exists: true,
|
|
208
|
-
// $lt: lastTriedAtShoudBeLessThan
|
|
209
|
-
// }
|
|
210
|
-
// },
|
|
211
|
-
// {
|
|
212
|
-
// $set: {
|
|
213
|
-
// status: factory.taskStatus.Aborted,
|
|
214
|
-
// dateAborted: new Date()
|
|
215
|
-
// }
|
|
216
|
-
// }
|
|
217
|
-
// )
|
|
218
|
-
// .exec();
|
|
219
|
-
// }
|
|
220
112
|
/**
|
|
221
113
|
* タスクIDから実行結果とステータスを保管する
|
|
222
114
|
* Abortedの場合、dateAbortedもセットする
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Connection, UpdateWriteOpResult } from 'mongoose';
|
|
2
|
+
import { INextFunction } from '../eventEmitter/task';
|
|
3
|
+
import { factory } from '../factory';
|
|
4
|
+
/**
|
|
5
|
+
* 旧非同期アクション(tasksコレクションにて管理)リポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class AsyncActionLegacyRepo {
|
|
8
|
+
private readonly taskModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
runImmediately(params: Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'name' | 'project' | 'remainingNumberOfTries' | 'runsAt'> & {
|
|
11
|
+
alternateName?: never;
|
|
12
|
+
identifier?: never;
|
|
13
|
+
expires: Date;
|
|
14
|
+
}, next: INextFunction): Promise<{
|
|
15
|
+
id: string;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Readyのままで期限切れのタスクをExpiredに変更する
|
|
19
|
+
*/
|
|
20
|
+
makeExpiredMany(params: {
|
|
21
|
+
expiresLt: Date;
|
|
22
|
+
}): Promise<UpdateWriteOpResult>;
|
|
23
|
+
}
|
|
@@ -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;
|
|
@@ -13,10 +13,6 @@ interface IOnReservationStatusChanged {
|
|
|
13
13
|
* AggService通知先
|
|
14
14
|
*/
|
|
15
15
|
informReservation?: factory.project.IInformParams[];
|
|
16
|
-
/**
|
|
17
|
-
* 確定予約最小化をサポート(2026-07-14~)
|
|
18
|
-
*/
|
|
19
|
-
minimizeReservation?: boolean;
|
|
20
16
|
}
|
|
21
17
|
interface IOnTaskStatusChanged {
|
|
22
18
|
/**
|
|
@@ -36,6 +32,8 @@ interface IOnEventChanged {
|
|
|
36
32
|
informEvent2agg?: factory.project.IInformParams[];
|
|
37
33
|
}
|
|
38
34
|
export interface IStorageSettings {
|
|
35
|
+
useScheduledDeleteTransactionTask?: boolean;
|
|
36
|
+
deleteTransactionTaskExpiresInDays?: number;
|
|
39
37
|
/**
|
|
40
38
|
* 取引保管期間(Confirmed)
|
|
41
39
|
* default:365
|
|
@@ -79,7 +79,6 @@ export interface IPaymentMethodByPaymentUrl {
|
|
|
79
79
|
*/
|
|
80
80
|
export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
81
81
|
private readonly orderModel;
|
|
82
|
-
private readonly transactionModel;
|
|
83
82
|
constructor(connection: Connection);
|
|
84
83
|
createPlaceOrderIfNotExists(params: Pick<IOrderInTransaction, 'orderNumber' | 'project' | 'identifier' | 'broker' | 'seller' | 'customer'>): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
85
84
|
/**
|
|
@@ -177,8 +176,6 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
|
177
176
|
savePaymentMethodId(params: {
|
|
178
177
|
id: string;
|
|
179
178
|
paymentMethod: IPaymentMethodByPaymentUrl;
|
|
180
|
-
}, options: {
|
|
181
|
-
savePaymentMethodIdInTransaction: boolean;
|
|
182
179
|
}): Promise<void>;
|
|
183
180
|
/**
|
|
184
181
|
* 進行中取引に保管された採用済決済方法を検索する
|
|
@@ -5,7 +5,11 @@ exports.OrderInTransactionRepo = void 0;
|
|
|
5
5
|
const errorHandler_1 = require("../errorHandler");
|
|
6
6
|
const factory_1 = require("../factory");
|
|
7
7
|
const order_1 = require("./mongoose/schemas/order");
|
|
8
|
-
|
|
8
|
+
// import {
|
|
9
|
+
// createSchema as createTransactionSchema,
|
|
10
|
+
// IModel as ITransactionModel, modelName as transactionModelName,
|
|
11
|
+
// IDocType as ITransactionDocType
|
|
12
|
+
// } from './mongoose/schemas/transaction';
|
|
9
13
|
const acceptedOfferInReserve_1 = require("./acceptedOfferInReserve");
|
|
10
14
|
// const debug = createDebug('chevre-domain:repo:orderInTransaction');
|
|
11
15
|
/**
|
|
@@ -13,11 +17,11 @@ const acceptedOfferInReserve_1 = require("./acceptedOfferInReserve");
|
|
|
13
17
|
*/
|
|
14
18
|
class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInReserveRepo {
|
|
15
19
|
orderModel;
|
|
16
|
-
transactionModel;
|
|
20
|
+
// private readonly transactionModel: ITransactionModel;
|
|
17
21
|
constructor(connection) {
|
|
18
22
|
super(connection);
|
|
19
23
|
this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
|
|
20
|
-
this.transactionModel = connection.model
|
|
24
|
+
// this.transactionModel = connection.model<ITransactionDocType, ITransactionModel>(transactionModelName, createTransactionSchema());
|
|
21
25
|
}
|
|
22
26
|
async createPlaceOrderIfNotExists(params) {
|
|
23
27
|
const { orderNumber, project, identifier, broker, seller, customer } = params;
|
|
@@ -284,29 +288,33 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
284
288
|
* 特定の進行中取引の決済方法IDを保管する
|
|
285
289
|
* transactionsへの保管としてひとまず定義(2026-07-11~)
|
|
286
290
|
*/
|
|
287
|
-
async savePaymentMethodId(params
|
|
288
|
-
const { savePaymentMethodIdInTransaction } = options;
|
|
291
|
+
async savePaymentMethodId(params) {
|
|
289
292
|
const { paymentMethodId } = params.paymentMethod;
|
|
290
293
|
if (typeof paymentMethodId !== 'string' || paymentMethodId === '') {
|
|
291
294
|
throw new factory_1.factory.errors.ArgumentNull('paymentMethod.paymentMethodId');
|
|
292
295
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
296
|
+
// savePaymentMethodIdInTransactionは廃止(2026-08-04~)
|
|
297
|
+
// if (savePaymentMethodIdInTransaction) {
|
|
298
|
+
// await this.transactionModel.findOneAndUpdate(
|
|
299
|
+
// {
|
|
300
|
+
// _id: { $eq: params.id },
|
|
301
|
+
// status: { $eq: factory.transactionStatusType.InProgress }
|
|
302
|
+
// },
|
|
303
|
+
// {
|
|
304
|
+
// $set: { 'object.paymentMethods': { paymentMethodId } }
|
|
305
|
+
// },
|
|
306
|
+
// {
|
|
307
|
+
// projection: { _id: 1 }
|
|
308
|
+
// }
|
|
309
|
+
// )
|
|
310
|
+
// .lean<{ _id: ObjectId }>()
|
|
311
|
+
// .exec()
|
|
312
|
+
// .then((doc) => {
|
|
313
|
+
// if (doc === null) {
|
|
314
|
+
// throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
|
|
315
|
+
// }
|
|
316
|
+
// });
|
|
317
|
+
// }
|
|
310
318
|
// 注文ドキュメントにも保管する(2026-07-12~)
|
|
311
319
|
await this.orderModel.findOneAndUpdate({
|
|
312
320
|
identifier: { $eq: params.id },
|
|
@@ -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
|
/**
|