@chevre/domain 25.2.0-alpha.50 → 25.2.0-alpha.51
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Connection } from 'mongoose';
|
|
1
|
+
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
3
|
import { IModel, IDocType } from './mongoose/schemas/asyncAction';
|
|
4
4
|
import type { IExecutableTask } from '../taskSettings';
|
|
@@ -7,12 +7,17 @@ type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'data' | 'ex
|
|
|
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>;
|
|
10
|
+
type IFindParams = Pick<factory.task.ISearchConditions, 'id' | 'name' | 'project' | 'runsFrom' | 'runsThrough' | 'status' | 'limit' | 'page' | 'sort'>;
|
|
10
11
|
/**
|
|
11
12
|
* 非同期アクションリポジトリ
|
|
12
13
|
*/
|
|
13
14
|
export declare class AsyncActionRepo {
|
|
14
15
|
readonly asyncActionModel: IModel;
|
|
15
16
|
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/deleteTransaction").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 | import("@chevre/factory/lib/chevre/task/voidReserveTransaction").ITask>[];
|
|
18
|
+
findAsyncActions(params: IFindParams, inclusion: IKeyOfProjection[]): Promise<(IDocType & {
|
|
19
|
+
id: string;
|
|
20
|
+
})[]>;
|
|
16
21
|
/**
|
|
17
22
|
* Readyタスクをひとつ追加する
|
|
18
23
|
*/
|
|
@@ -35,6 +35,65 @@ 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
|
+
}
|
|
38
97
|
/**
|
|
39
98
|
* Readyタスクをひとつ追加する
|
|
40
99
|
*/
|
package/package.json
CHANGED