@chevre/domain 26.0.0 → 26.1.0-alpha.0
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/acceptCOAOffer.d.ts +8 -0
- package/lib/chevre/repo/action/acceptCOAOffer.js +17 -0
- package/lib/chevre/repo/action/acceptPay.d.ts +8 -0
- package/lib/chevre/repo/action/acceptPay.js +19 -2
- package/lib/chevre/repo/action/anyAction/actionProcess.d.ts +12 -21
- package/lib/chevre/repo/action/anyAction/actionProcess.js +4 -360
- package/lib/chevre/repo/action/anyAction/actionRecipe.d.ts +1 -1
- package/lib/chevre/repo/action/authorizeInvoice.js +1 -1
- package/lib/chevre/repo/action/authorizeOffer.js +1 -5
- package/lib/chevre/repo/action/authorizePaymentMethod.d.ts +8 -0
- package/lib/chevre/repo/action/authorizePaymentMethod.js +18 -1
- package/lib/chevre/repo/action/checkMovieTicket.d.ts +8 -0
- package/lib/chevre/repo/action/checkMovieTicket.js +17 -0
- package/lib/chevre/repo/action/dedicatedAction/dedicatedActionProcess.d.ts +46 -0
- package/lib/chevre/repo/action/dedicatedAction/dedicatedActionProcess.js +92 -0
- package/lib/chevre/repo/action/inform.d.ts +2 -1
- package/lib/chevre/repo/action/inform.js +14 -45
- package/lib/chevre/repo/action/pay.js +1 -1
- package/lib/chevre/repo/action/update.d.ts +8 -6
- package/lib/chevre/repo/action/update.js +14 -51
- package/lib/chevre/repo/action/use.d.ts +2 -1
- package/lib/chevre/repo/action/use.js +14 -45
- package/lib/chevre/repo/adminAction.d.ts +1 -1
- package/lib/chevre/repo/adminAction.js +27 -1
- package/lib/chevre/repo/factory/action/createMongoConditions.d.ts +4 -0
- package/lib/chevre/repo/factory/action/createMongoConditions.js +335 -0
- package/lib/chevre/repo/mongoose/schemas/action/abstractAction.d.ts +5 -0
- package/lib/chevre/repo/mongoose/schemas/action/abstractAction.js +2 -0
- package/lib/chevre/service/assetTransaction/pay/check.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/pay/start.d.ts +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +4 -5
- package/lib/chevre/service/payment/any/authorize.d.ts +1 -1
- package/lib/chevre/service/payment/any/findAcceptAction.js +4 -5
- package/lib/chevre/service/payment/any/findAuthorizeAction.js +4 -5
- package/lib/chevre/service/payment/any/findCheckAction.d.ts +3 -1
- package/lib/chevre/service/payment/any/findCheckAction.js +5 -6
- package/lib/chevre/service/payment/movieTicket/authorize.d.ts +1 -1
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.d.ts +3 -1
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
- package/lib/chevre/service/payment/movieTicket/validation.d.ts +3 -1
- package/lib/chevre/service/payment/movieTicket/validation.js +2 -2
- package/lib/chevre/service/task/acceptCOAOffer.js +4 -5
- package/lib/chevre/service/task/authorizePayment.js +5 -6
- package/lib/chevre/service/task/checkMovieTicket.js +7 -6
- package/lib/chevre/service/task/pay.js +3 -2
- package/lib/chevre/service/task/payment/payByTask.d.ts +3 -1
- package/lib/chevre/service/task/payment/payByTask.js +1 -1
- package/lib/chevre/service/task/publishPaymentUrl.js +4 -5
- package/package.json +1 -1
|
@@ -15,6 +15,23 @@ class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
|
|
|
15
15
|
recipeExpireAfterSeconds: EXPIRE_AFTER_SECONDS
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
+
async findActionBySameAs(params) {
|
|
19
|
+
return this.actionModel.findOne({
|
|
20
|
+
typeOf: { $eq: factory_1.factory.actionType.CheckAction }, // 1taskから複数actionが発生する可能性があるので、typeOf指定が必須
|
|
21
|
+
'sameAs.id': { $exists: true, $eq: params.sameAs.id },
|
|
22
|
+
...(typeof params.purpose?.id === 'string')
|
|
23
|
+
? { 'purpose.id': { $exists: true, $eq: params.purpose.id } }
|
|
24
|
+
: undefined
|
|
25
|
+
}, {
|
|
26
|
+
_id: 0,
|
|
27
|
+
id: { $toString: '$_id' },
|
|
28
|
+
actionStatus: 1,
|
|
29
|
+
error: 1,
|
|
30
|
+
purpose: 1
|
|
31
|
+
})
|
|
32
|
+
.lean()
|
|
33
|
+
.exec();
|
|
34
|
+
}
|
|
18
35
|
/**
|
|
19
36
|
* アクションIDからレシピのafterMediaを参照する
|
|
20
37
|
*/
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Connection } from 'mongoose';
|
|
2
|
+
import { factory } from '../../../factory';
|
|
3
|
+
import type { IAbstractActionModel } from '../../mongoose/schemas/action/abstractAction';
|
|
4
|
+
import { ActionRecipeRepo, IActionRecipe, IRecipeAsActionAttributes } from '../anyAction/actionRecipe';
|
|
5
|
+
type AvailableActionType = factory.actionType.InformAction | factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction | factory.actionType.UseAction;
|
|
6
|
+
type IAction<T extends AvailableActionType> = T extends factory.actionType.InformAction ? factory.action.interact.inform.IAction : T extends factory.actionType.AddAction ? factory.action.update.add.IAction : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAction : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAction : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAction : T extends factory.actionType.UseAction ? factory.action.consume.use.reservation.IAction : never;
|
|
7
|
+
type IActionAttributes<T extends AvailableActionType> = T extends factory.actionType.InformAction ? factory.action.interact.inform.IAttributes : T extends factory.actionType.AddAction ? factory.action.update.add.IAttributes : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAttributes : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAttributes : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAttributes : T extends factory.actionType.UseAction ? factory.action.consume.use.reservation.IAttributes : never;
|
|
8
|
+
type IResult<T extends AvailableActionType> = T extends factory.actionType.InformAction ? factory.action.interact.inform.IResult : T extends factory.actionType.AddAction ? factory.action.update.add.IResult : T extends factory.actionType.UpdateAction ? factory.action.update.update.IResult : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IResult : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IResult : T extends factory.actionType.UseAction ? factory.action.consume.use.reservation.IResult : never;
|
|
9
|
+
interface IOptions {
|
|
10
|
+
expireAfterSeconds: number;
|
|
11
|
+
recipeExpireAfterSeconds: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 専用アクション状態管理リポジトリ
|
|
15
|
+
* mongoose modelは継承クラスから指定される前提
|
|
16
|
+
*/
|
|
17
|
+
export declare class DedicatedActionProcessRepo<TActionType extends AvailableActionType, TActionRecipe extends IActionRecipe<factory.recipe.RecipeCategory>> extends ActionRecipeRepo<TActionRecipe> {
|
|
18
|
+
private readonly actionModel;
|
|
19
|
+
private options;
|
|
20
|
+
protected constructor(params: {
|
|
21
|
+
connection: Connection;
|
|
22
|
+
actionModel: IAbstractActionModel;
|
|
23
|
+
}, options: IOptions);
|
|
24
|
+
/**
|
|
25
|
+
* アクション開始
|
|
26
|
+
*/
|
|
27
|
+
protected startAction<T extends TActionType>(attributes: IActionAttributes<T>, options?: {
|
|
28
|
+
recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
|
|
29
|
+
}): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
|
|
30
|
+
protected completeAction<T extends TActionType>(params: {
|
|
31
|
+
typeOf: T;
|
|
32
|
+
id: string;
|
|
33
|
+
result?: IResult<T>;
|
|
34
|
+
recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
|
|
35
|
+
}): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* アクション失敗
|
|
38
|
+
*/
|
|
39
|
+
protected giveUpAction<T extends TActionType>(params: {
|
|
40
|
+
typeOf: T;
|
|
41
|
+
id: string;
|
|
42
|
+
error: Error | Error[] | unknown;
|
|
43
|
+
recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DedicatedActionProcessRepo = void 0;
|
|
4
|
+
const factory_1 = require("../../../factory");
|
|
5
|
+
const unknown2actionError_1 = require("../unknown2actionError");
|
|
6
|
+
const actionRecipe_1 = require("../anyAction/actionRecipe");
|
|
7
|
+
/**
|
|
8
|
+
* 専用アクション状態管理リポジトリ
|
|
9
|
+
* mongoose modelは継承クラスから指定される前提
|
|
10
|
+
*/
|
|
11
|
+
class DedicatedActionProcessRepo extends actionRecipe_1.ActionRecipeRepo {
|
|
12
|
+
actionModel;
|
|
13
|
+
options;
|
|
14
|
+
constructor(params, options) {
|
|
15
|
+
super(params, options);
|
|
16
|
+
this.actionModel = params.actionModel;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* アクション開始
|
|
21
|
+
*/
|
|
22
|
+
async startAction(attributes, options) {
|
|
23
|
+
const startDate = new Date();
|
|
24
|
+
const expires = new Date(startDate.getTime() + this.options.expireAfterSeconds * 1000);
|
|
25
|
+
const creatingAction = {
|
|
26
|
+
...attributes,
|
|
27
|
+
actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
|
|
28
|
+
startDate,
|
|
29
|
+
expires
|
|
30
|
+
};
|
|
31
|
+
const result = await this.actionModel.insertMany(creatingAction, { rawResult: true });
|
|
32
|
+
const id = result.insertedIds?.[0]?.toHexString();
|
|
33
|
+
if (typeof id !== 'string') {
|
|
34
|
+
throw new factory_1.factory.errors.Internal('action not saved');
|
|
35
|
+
}
|
|
36
|
+
// add recipe
|
|
37
|
+
const savingRecipe = options?.recipe;
|
|
38
|
+
if (savingRecipe?.typeOf === 'Recipe') {
|
|
39
|
+
await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf } });
|
|
40
|
+
}
|
|
41
|
+
return { id, startDate, typeOf: creatingAction.typeOf };
|
|
42
|
+
}
|
|
43
|
+
async completeAction(params) {
|
|
44
|
+
const endDate = new Date();
|
|
45
|
+
if (params.recipe?.typeOf === 'Recipe') {
|
|
46
|
+
await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
|
|
47
|
+
}
|
|
48
|
+
const doc = await this.actionModel.findOneAndUpdate({
|
|
49
|
+
_id: { $eq: params.id },
|
|
50
|
+
actionStatus: { $eq: factory_1.factory.actionStatusType.ActiveActionStatus }
|
|
51
|
+
}, {
|
|
52
|
+
$set: {
|
|
53
|
+
actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
|
|
54
|
+
endDate,
|
|
55
|
+
...((params.result !== undefined) && { result: params.result })
|
|
56
|
+
}
|
|
57
|
+
}, { new: false, projection: { _id: 1 } })
|
|
58
|
+
.lean()
|
|
59
|
+
.exec();
|
|
60
|
+
if (doc === null) {
|
|
61
|
+
throw new factory_1.factory.errors.NotFound(this.actionModel.modelName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* アクション失敗
|
|
66
|
+
*/
|
|
67
|
+
async giveUpAction(params) {
|
|
68
|
+
const endDate = new Date();
|
|
69
|
+
const actionError = Array.isArray(params.error)
|
|
70
|
+
? params.error.map(unknown2actionError_1.unknown2actionError)
|
|
71
|
+
: (0, unknown2actionError_1.unknown2actionError)(params.error);
|
|
72
|
+
if (params.recipe?.typeOf === 'Recipe') {
|
|
73
|
+
await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
|
|
74
|
+
}
|
|
75
|
+
const doc = await this.actionModel.findOneAndUpdate({
|
|
76
|
+
_id: { $eq: params.id },
|
|
77
|
+
actionStatus: { $eq: factory_1.factory.actionStatusType.ActiveActionStatus }
|
|
78
|
+
}, {
|
|
79
|
+
$set: {
|
|
80
|
+
actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
|
|
81
|
+
error: actionError,
|
|
82
|
+
endDate
|
|
83
|
+
}
|
|
84
|
+
}, { new: false, projection: { _id: 1 } })
|
|
85
|
+
.lean()
|
|
86
|
+
.exec();
|
|
87
|
+
if (doc === null) {
|
|
88
|
+
throw new factory_1.factory.errors.NotFound(this.actionModel.modelName);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.DedicatedActionProcessRepo = DedicatedActionProcessRepo;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../../factory';
|
|
3
3
|
import { IDocType } from '../mongoose/schemas/action/inform';
|
|
4
|
+
import { DedicatedActionProcessRepo } from './dedicatedAction/dedicatedActionProcess';
|
|
4
5
|
type StartableActionType = factory.actionType.InformAction;
|
|
5
6
|
type IAction = IDocType & {
|
|
6
7
|
id: string;
|
|
@@ -12,7 +13,7 @@ type IFindParams = Pick<factory.action.ISearchConditions, 'limit' | 'page' | 'pr
|
|
|
12
13
|
/**
|
|
13
14
|
* 通知アクションリポジトリ
|
|
14
15
|
*/
|
|
15
|
-
export declare class InformActionRepo {
|
|
16
|
+
export declare class InformActionRepo extends DedicatedActionProcessRepo<StartableActionType, never> {
|
|
16
17
|
private readonly informActionModel;
|
|
17
18
|
constructor(connection: Connection);
|
|
18
19
|
static CREATE_MONGO_CONDITIONS(params: IFindParams): FilterQuery<IDocType>[];
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InformActionRepo = void 0;
|
|
4
|
-
const factory_1 = require("../../factory");
|
|
5
4
|
const settings_1 = require("../../settings");
|
|
6
5
|
const inform_1 = require("../mongoose/schemas/action/inform");
|
|
7
|
-
const
|
|
6
|
+
const dedicatedActionProcess_1 = require("./dedicatedAction/dedicatedActionProcess");
|
|
8
7
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
9
8
|
'project',
|
|
10
9
|
'actionStatus',
|
|
@@ -25,10 +24,18 @@ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
|
|
|
25
24
|
/**
|
|
26
25
|
* 通知アクションリポジトリ
|
|
27
26
|
*/
|
|
28
|
-
class InformActionRepo {
|
|
27
|
+
class InformActionRepo extends dedicatedActionProcess_1.DedicatedActionProcessRepo {
|
|
29
28
|
informActionModel;
|
|
30
29
|
constructor(connection) {
|
|
31
|
-
|
|
30
|
+
const informActionModel = connection.model(inform_1.modelName, (0, inform_1.createSchema)());
|
|
31
|
+
super({
|
|
32
|
+
connection,
|
|
33
|
+
actionModel: informActionModel
|
|
34
|
+
}, {
|
|
35
|
+
expireAfterSeconds: EXPIRE_AFTER_SECONDS,
|
|
36
|
+
recipeExpireAfterSeconds: EXPIRE_AFTER_SECONDS
|
|
37
|
+
});
|
|
38
|
+
this.informActionModel = informActionModel;
|
|
32
39
|
}
|
|
33
40
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
34
41
|
const andConditions = [];
|
|
@@ -66,54 +73,16 @@ class InformActionRepo {
|
|
|
66
73
|
* アクション開始
|
|
67
74
|
*/
|
|
68
75
|
async startInformAction(attributes) {
|
|
69
|
-
|
|
70
|
-
const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
|
|
71
|
-
const creatingAction = {
|
|
72
|
-
...attributes,
|
|
73
|
-
actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
|
|
74
|
-
startDate,
|
|
75
|
-
expires
|
|
76
|
-
};
|
|
77
|
-
const result = await this.informActionModel.insertMany(creatingAction, { rawResult: true });
|
|
78
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
79
|
-
if (typeof id !== 'string') {
|
|
80
|
-
throw new factory_1.factory.errors.Internal('action not saved');
|
|
81
|
-
}
|
|
82
|
-
return { id, startDate, typeOf: creatingAction.typeOf };
|
|
76
|
+
return this.startAction(attributes);
|
|
83
77
|
}
|
|
84
78
|
async completeInformAction(params) {
|
|
85
|
-
|
|
86
|
-
$set: {
|
|
87
|
-
actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
|
|
88
|
-
result: params.result,
|
|
89
|
-
endDate: new Date()
|
|
90
|
-
}
|
|
91
|
-
}, { new: false, projection: { _id: 1 } })
|
|
92
|
-
.lean()
|
|
93
|
-
.exec();
|
|
94
|
-
if (doc === null) {
|
|
95
|
-
throw new factory_1.factory.errors.NotFound(this.informActionModel.modelName);
|
|
96
|
-
}
|
|
79
|
+
await this.completeAction(params);
|
|
97
80
|
}
|
|
98
81
|
/**
|
|
99
82
|
* アクション失敗
|
|
100
83
|
*/
|
|
101
84
|
async giveUpInformAction(params) {
|
|
102
|
-
|
|
103
|
-
? params.error.map(unknown2actionError_1.unknown2actionError)
|
|
104
|
-
: (0, unknown2actionError_1.unknown2actionError)(params.error);
|
|
105
|
-
const doc = await this.informActionModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
|
|
106
|
-
$set: {
|
|
107
|
-
actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
|
|
108
|
-
error: actionError,
|
|
109
|
-
endDate: new Date()
|
|
110
|
-
}
|
|
111
|
-
}, { new: true, projection: { _id: 1 } })
|
|
112
|
-
.lean()
|
|
113
|
-
.exec();
|
|
114
|
-
if (doc === null) {
|
|
115
|
-
throw new factory_1.factory.errors.NotFound(this.informActionModel.modelName);
|
|
116
|
-
}
|
|
85
|
+
await this.giveUpAction(params);
|
|
117
86
|
}
|
|
118
87
|
async findInformActions(params, inclusion) {
|
|
119
88
|
const conditions = InformActionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
@@ -18,7 +18,7 @@ class PayActionRepo extends actionProcess_1.ActionProcessRepo {
|
|
|
18
18
|
* デフォルトでCompletedActionStatusのみ参照
|
|
19
19
|
*/
|
|
20
20
|
async findPayActionByPaymentMethodId(params) {
|
|
21
|
-
const payActions = await this.
|
|
21
|
+
const payActions = await this.findAnyActionsLegacy({
|
|
22
22
|
limit: 1,
|
|
23
23
|
page: 1,
|
|
24
24
|
actionStatus: (Array.isArray(params.actionStatus?.$in))
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../../factory';
|
|
3
3
|
import { IDocType } from '../mongoose/schemas/action/update';
|
|
4
|
+
import { DedicatedActionProcessRepo } from './dedicatedAction/dedicatedActionProcess';
|
|
4
5
|
type StartableActionType = factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction;
|
|
5
6
|
type IAction<T extends StartableActionType> = 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.DeleteAction ? factory.action.update.deleteAction.IAction : never;
|
|
6
7
|
type IActionAttributes<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IAttributes : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IAttributes : T extends factory.actionType.UpdateAction ? factory.action.update.update.IAttributes : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IAttributes : never;
|
|
8
|
+
type IResult<T extends StartableActionType> = T extends factory.actionType.AddAction ? factory.action.update.add.IResult : T extends factory.actionType.UpdateAction ? factory.action.update.update.IResult : T extends factory.actionType.ReplaceAction ? factory.action.update.replace.IResult : T extends factory.actionType.DeleteAction ? factory.action.update.deleteAction.IResult : never;
|
|
7
9
|
type IKeyOfProjection = keyof IDocType;
|
|
8
10
|
type IFindParams = factory.action.update.update.IFindParams;
|
|
9
11
|
/**
|
|
10
12
|
* リソース編集アクションリポジトリ
|
|
11
13
|
*/
|
|
12
|
-
export declare class UpdateActionRepo {
|
|
14
|
+
export declare class UpdateActionRepo extends DedicatedActionProcessRepo<StartableActionType, never> {
|
|
13
15
|
private readonly updateActionModel;
|
|
14
16
|
constructor(connection: Connection);
|
|
15
17
|
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'id' | 'object' | 'project' | 'result' | 'startFrom' | 'startThrough' | 'typeOf'>): FilterQuery<IDocType>[];
|
|
@@ -17,16 +19,16 @@ export declare class UpdateActionRepo {
|
|
|
17
19
|
* アクション開始
|
|
18
20
|
*/
|
|
19
21
|
startUpdateAction<T extends StartableActionType>(attributes: IActionAttributes<T>): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
|
|
20
|
-
completeUpdateAction(params: {
|
|
21
|
-
typeOf:
|
|
22
|
+
completeUpdateAction<T extends StartableActionType>(params: {
|
|
23
|
+
typeOf: T;
|
|
22
24
|
id: string;
|
|
23
|
-
result:
|
|
25
|
+
result: IResult<T>;
|
|
24
26
|
}): Promise<void>;
|
|
25
27
|
/**
|
|
26
28
|
* アクション失敗
|
|
27
29
|
*/
|
|
28
|
-
giveUpUpdateAction(params: {
|
|
29
|
-
typeOf:
|
|
30
|
+
giveUpUpdateAction<T extends StartableActionType>(params: {
|
|
31
|
+
typeOf: T;
|
|
30
32
|
id: string;
|
|
31
33
|
error: Error | Error[] | unknown;
|
|
32
34
|
}): Promise<void>;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UpdateActionRepo = void 0;
|
|
4
|
-
const factory_1 = require("../../factory");
|
|
5
4
|
const settings_1 = require("../../settings");
|
|
6
5
|
const update_1 = require("../mongoose/schemas/action/update");
|
|
7
|
-
const
|
|
6
|
+
const dedicatedActionProcess_1 = require("./dedicatedAction/dedicatedActionProcess");
|
|
8
7
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
9
8
|
'project',
|
|
10
9
|
'actionStatus',
|
|
@@ -24,10 +23,18 @@ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
|
|
|
24
23
|
/**
|
|
25
24
|
* リソース編集アクションリポジトリ
|
|
26
25
|
*/
|
|
27
|
-
class UpdateActionRepo {
|
|
26
|
+
class UpdateActionRepo extends dedicatedActionProcess_1.DedicatedActionProcessRepo {
|
|
28
27
|
updateActionModel;
|
|
29
28
|
constructor(connection) {
|
|
30
|
-
|
|
29
|
+
const updateActionModel = connection.model(update_1.modelName, (0, update_1.createSchema)());
|
|
30
|
+
super({
|
|
31
|
+
connection,
|
|
32
|
+
actionModel: updateActionModel
|
|
33
|
+
}, {
|
|
34
|
+
expireAfterSeconds: EXPIRE_AFTER_SECONDS,
|
|
35
|
+
recipeExpireAfterSeconds: EXPIRE_AFTER_SECONDS
|
|
36
|
+
});
|
|
37
|
+
this.updateActionModel = updateActionModel;
|
|
31
38
|
}
|
|
32
39
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
33
40
|
const andConditions = [];
|
|
@@ -64,60 +71,16 @@ class UpdateActionRepo {
|
|
|
64
71
|
* アクション開始
|
|
65
72
|
*/
|
|
66
73
|
async startUpdateAction(attributes) {
|
|
67
|
-
|
|
68
|
-
const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
|
|
69
|
-
const creatingAction = {
|
|
70
|
-
...attributes,
|
|
71
|
-
actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
|
|
72
|
-
startDate,
|
|
73
|
-
expires
|
|
74
|
-
};
|
|
75
|
-
const result = await this.updateActionModel.insertMany(creatingAction, { rawResult: true });
|
|
76
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
77
|
-
if (typeof id !== 'string') {
|
|
78
|
-
throw new factory_1.factory.errors.Internal('action not saved');
|
|
79
|
-
}
|
|
80
|
-
return { id, startDate, typeOf: creatingAction.typeOf };
|
|
74
|
+
return this.startAction(attributes); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
81
75
|
}
|
|
82
76
|
async completeUpdateAction(params) {
|
|
83
|
-
|
|
84
|
-
_id: { $eq: params.id },
|
|
85
|
-
typeOf: { $eq: params.typeOf }
|
|
86
|
-
}, {
|
|
87
|
-
$set: {
|
|
88
|
-
actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
|
|
89
|
-
result: params.result,
|
|
90
|
-
endDate: new Date()
|
|
91
|
-
}
|
|
92
|
-
}, { new: false, projection: { _id: 1 } })
|
|
93
|
-
.lean()
|
|
94
|
-
.exec();
|
|
95
|
-
if (doc === null) {
|
|
96
|
-
throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
|
|
97
|
-
}
|
|
77
|
+
await this.completeAction(params);
|
|
98
78
|
}
|
|
99
79
|
/**
|
|
100
80
|
* アクション失敗
|
|
101
81
|
*/
|
|
102
82
|
async giveUpUpdateAction(params) {
|
|
103
|
-
|
|
104
|
-
? params.error.map(unknown2actionError_1.unknown2actionError)
|
|
105
|
-
: (0, unknown2actionError_1.unknown2actionError)(params.error);
|
|
106
|
-
const doc = await this.updateActionModel.findOneAndUpdate({
|
|
107
|
-
typeOf: { $eq: params.typeOf },
|
|
108
|
-
_id: { $eq: params.id }
|
|
109
|
-
}, {
|
|
110
|
-
$set: {
|
|
111
|
-
actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
|
|
112
|
-
error: actionError,
|
|
113
|
-
endDate: new Date()
|
|
114
|
-
}
|
|
115
|
-
}, { new: true, projection: { _id: 1 } })
|
|
116
|
-
.lean()
|
|
117
|
-
.exec();
|
|
118
|
-
if (doc === null) {
|
|
119
|
-
throw new factory_1.factory.errors.NotFound(this.updateActionModel.modelName);
|
|
120
|
-
}
|
|
83
|
+
await this.giveUpAction(params);
|
|
121
84
|
}
|
|
122
85
|
async findUpdateActions(params, inclusion) {
|
|
123
86
|
const conditions = UpdateActionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Connection, FilterQuery } from 'mongoose';
|
|
2
2
|
import { factory } from '../../factory';
|
|
3
3
|
import { IDocType } from '../mongoose/schemas/action/use';
|
|
4
|
+
import { DedicatedActionProcessRepo } from './dedicatedAction/dedicatedActionProcess';
|
|
4
5
|
type StartableActionType = factory.actionType.UseAction;
|
|
5
6
|
type IAction = IDocType & {
|
|
6
7
|
id: string;
|
|
@@ -10,7 +11,7 @@ type IFindParams = factory.action.consume.use.reservation.IFindParams;
|
|
|
10
11
|
/**
|
|
11
12
|
* 予約使用アクションリポジトリ
|
|
12
13
|
*/
|
|
13
|
-
export declare class UseActionRepo {
|
|
14
|
+
export declare class UseActionRepo extends DedicatedActionProcessRepo<StartableActionType, never> {
|
|
14
15
|
private readonly useActionModel;
|
|
15
16
|
constructor(connection: Connection);
|
|
16
17
|
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'actionStatus' | 'id' | 'object' | 'project' | 'startFrom' | 'startThrough'>): FilterQuery<IDocType>[];
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UseActionRepo = void 0;
|
|
4
|
-
const factory_1 = require("../../factory");
|
|
5
4
|
const settings_1 = require("../../settings");
|
|
6
5
|
const use_1 = require("../mongoose/schemas/action/use");
|
|
7
|
-
const
|
|
6
|
+
const dedicatedActionProcess_1 = require("./dedicatedAction/dedicatedActionProcess");
|
|
8
7
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
9
8
|
'project',
|
|
10
9
|
'actionStatus',
|
|
@@ -22,10 +21,18 @@ const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
|
|
|
22
21
|
/**
|
|
23
22
|
* 予約使用アクションリポジトリ
|
|
24
23
|
*/
|
|
25
|
-
class UseActionRepo {
|
|
24
|
+
class UseActionRepo extends dedicatedActionProcess_1.DedicatedActionProcessRepo {
|
|
26
25
|
useActionModel;
|
|
27
26
|
constructor(connection) {
|
|
28
|
-
|
|
27
|
+
const useActionModel = connection.model(use_1.modelName, (0, use_1.createSchema)());
|
|
28
|
+
super({
|
|
29
|
+
connection,
|
|
30
|
+
actionModel: useActionModel
|
|
31
|
+
}, {
|
|
32
|
+
expireAfterSeconds: EXPIRE_AFTER_SECONDS,
|
|
33
|
+
recipeExpireAfterSeconds: EXPIRE_AFTER_SECONDS
|
|
34
|
+
});
|
|
35
|
+
this.useActionModel = useActionModel;
|
|
29
36
|
}
|
|
30
37
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
31
38
|
const andConditions = [];
|
|
@@ -59,54 +66,16 @@ class UseActionRepo {
|
|
|
59
66
|
* アクション開始
|
|
60
67
|
*/
|
|
61
68
|
async startUseAction(attributes) {
|
|
62
|
-
|
|
63
|
-
const expires = new Date(startDate.getTime() + EXPIRE_AFTER_SECONDS * 1000);
|
|
64
|
-
const creatingAction = {
|
|
65
|
-
...attributes,
|
|
66
|
-
actionStatus: factory_1.factory.actionStatusType.ActiveActionStatus,
|
|
67
|
-
startDate,
|
|
68
|
-
expires
|
|
69
|
-
};
|
|
70
|
-
const result = await this.useActionModel.insertMany(creatingAction, { rawResult: true });
|
|
71
|
-
const id = result.insertedIds?.[0]?.toHexString();
|
|
72
|
-
if (typeof id !== 'string') {
|
|
73
|
-
throw new factory_1.factory.errors.Internal('action not saved');
|
|
74
|
-
}
|
|
75
|
-
return { id, startDate, typeOf: creatingAction.typeOf };
|
|
69
|
+
return this.startAction(attributes);
|
|
76
70
|
}
|
|
77
71
|
async completeUseAction(params) {
|
|
78
|
-
|
|
79
|
-
$set: {
|
|
80
|
-
actionStatus: factory_1.factory.actionStatusType.CompletedActionStatus,
|
|
81
|
-
// result: params.result,
|
|
82
|
-
endDate: new Date()
|
|
83
|
-
}
|
|
84
|
-
}, { new: false, projection: { _id: 1 } })
|
|
85
|
-
.lean()
|
|
86
|
-
.exec();
|
|
87
|
-
if (doc === null) {
|
|
88
|
-
throw new factory_1.factory.errors.NotFound(this.useActionModel.modelName);
|
|
89
|
-
}
|
|
72
|
+
await this.completeAction(params);
|
|
90
73
|
}
|
|
91
74
|
/**
|
|
92
75
|
* アクション失敗
|
|
93
76
|
*/
|
|
94
77
|
async giveUpUseAction(params) {
|
|
95
|
-
|
|
96
|
-
? params.error.map(unknown2actionError_1.unknown2actionError)
|
|
97
|
-
: (0, unknown2actionError_1.unknown2actionError)(params.error);
|
|
98
|
-
const doc = await this.useActionModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
|
|
99
|
-
$set: {
|
|
100
|
-
actionStatus: factory_1.factory.actionStatusType.FailedActionStatus,
|
|
101
|
-
error: actionError,
|
|
102
|
-
endDate: new Date()
|
|
103
|
-
}
|
|
104
|
-
}, { new: true, projection: { _id: 1 } })
|
|
105
|
-
.lean()
|
|
106
|
-
.exec();
|
|
107
|
-
if (doc === null) {
|
|
108
|
-
throw new factory_1.factory.errors.NotFound(this.useActionModel.modelName);
|
|
109
|
-
}
|
|
78
|
+
await this.giveUpAction(params);
|
|
110
79
|
}
|
|
111
80
|
async findUseActions(params, inclusion) {
|
|
112
81
|
const conditions = UseActionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
@@ -17,7 +17,7 @@ export declare class AdminActionRepo extends ActionProcessRepo<IAction<Startable
|
|
|
17
17
|
/**
|
|
18
18
|
* 汎用アクション検索
|
|
19
19
|
*/
|
|
20
|
-
adminFindAnyActions(params: factory.action.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IAction<
|
|
20
|
+
adminFindAnyActions(params: factory.action.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IAction<StartableActionType>[]>;
|
|
21
21
|
/**
|
|
22
22
|
* 取引に対するアクションを検索する
|
|
23
23
|
*/
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AdminActionRepo = void 0;
|
|
4
4
|
const factory_1 = require("../factory");
|
|
5
|
+
const settings_1 = require("../settings");
|
|
5
6
|
const actionProcess_1 = require("./action/anyAction/actionProcess");
|
|
7
|
+
const createMongoConditions_1 = require("./factory/action/createMongoConditions");
|
|
6
8
|
/**
|
|
7
9
|
* アクション管理リポジトリ
|
|
8
10
|
*/
|
|
@@ -17,7 +19,31 @@ class AdminActionRepo extends actionProcess_1.ActionProcessRepo {
|
|
|
17
19
|
* 汎用アクション検索
|
|
18
20
|
*/
|
|
19
21
|
async adminFindAnyActions(params, inclusion) {
|
|
20
|
-
|
|
22
|
+
const conditions = (0, createMongoConditions_1.createMongoConditions)(params);
|
|
23
|
+
let positiveProjectionFields = actionProcess_1.AVAILABLE_PROJECT_FIELDS;
|
|
24
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
25
|
+
positiveProjectionFields = inclusion.filter((key) => actionProcess_1.AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
26
|
+
}
|
|
27
|
+
const projection = {
|
|
28
|
+
_id: 0,
|
|
29
|
+
id: { $toString: '$_id' },
|
|
30
|
+
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
31
|
+
};
|
|
32
|
+
const query = this.actionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
33
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
34
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
35
|
+
query.limit(params.limit)
|
|
36
|
+
.skip(params.limit * (page - 1));
|
|
37
|
+
}
|
|
38
|
+
/* istanbul ignore else */
|
|
39
|
+
if (params.sort?.startDate !== undefined) {
|
|
40
|
+
query.sort({ startDate: params.sort.startDate });
|
|
41
|
+
}
|
|
42
|
+
// const explainResult = await (<any>query).explain();
|
|
43
|
+
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
44
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
45
|
+
.lean()
|
|
46
|
+
.exec();
|
|
21
47
|
}
|
|
22
48
|
/**
|
|
23
49
|
* 取引に対するアクションを検索する
|