@chevre/domain 26.0.0 → 26.1.0-alpha.1

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.
Files changed (53) hide show
  1. package/lib/chevre/repo/action/acceptCOAOffer.d.ts +8 -0
  2. package/lib/chevre/repo/action/acceptCOAOffer.js +17 -0
  3. package/lib/chevre/repo/action/acceptPay.d.ts +8 -0
  4. package/lib/chevre/repo/action/acceptPay.js +19 -2
  5. package/lib/chevre/repo/action/anyAction/actionProcess.d.ts +12 -21
  6. package/lib/chevre/repo/action/anyAction/actionProcess.js +4 -360
  7. package/lib/chevre/repo/action/anyAction/actionRecipe.d.ts +1 -1
  8. package/lib/chevre/repo/action/authorizeInvoice.js +1 -1
  9. package/lib/chevre/repo/action/authorizeOffer.js +1 -5
  10. package/lib/chevre/repo/action/authorizePaymentMethod.d.ts +8 -0
  11. package/lib/chevre/repo/action/authorizePaymentMethod.js +18 -1
  12. package/lib/chevre/repo/action/checkMovieTicket.d.ts +46 -53
  13. package/lib/chevre/repo/action/checkMovieTicket.js +85 -63
  14. package/lib/chevre/repo/action/dedicatedAction/dedicatedActionProcess.d.ts +46 -0
  15. package/lib/chevre/repo/action/dedicatedAction/dedicatedActionProcess.js +92 -0
  16. package/lib/chevre/repo/action/inform.d.ts +2 -1
  17. package/lib/chevre/repo/action/inform.js +14 -45
  18. package/lib/chevre/repo/action/pay.js +1 -1
  19. package/lib/chevre/repo/action/update.d.ts +8 -6
  20. package/lib/chevre/repo/action/update.js +14 -51
  21. package/lib/chevre/repo/action/use.d.ts +2 -1
  22. package/lib/chevre/repo/action/use.js +14 -45
  23. package/lib/chevre/repo/adminAction.d.ts +1 -1
  24. package/lib/chevre/repo/adminAction.js +27 -1
  25. package/lib/chevre/repo/factory/action/createMongoConditions.d.ts +4 -0
  26. package/lib/chevre/repo/factory/action/createMongoConditions.js +335 -0
  27. package/lib/chevre/repo/mongoose/schemas/action/abstractAction.d.ts +5 -0
  28. package/lib/chevre/repo/mongoose/schemas/action/abstractAction.js +2 -0
  29. package/lib/chevre/repo/mongoose/schemas/action/checkMovieTicket.d.ts +11 -0
  30. package/lib/chevre/repo/mongoose/schemas/action/checkMovieTicket.js +108 -0
  31. package/lib/chevre/service/assetTransaction/pay/check.d.ts +3 -1
  32. package/lib/chevre/service/assetTransaction/pay/start/processAuthorize.d.ts +1 -1
  33. package/lib/chevre/service/assetTransaction/pay/start/processAuthorizeMovieTicket.d.ts +1 -1
  34. package/lib/chevre/service/assetTransaction/pay/start.d.ts +1 -1
  35. package/lib/chevre/service/offer/eventServiceByCOA/findAcceptAction.js +4 -5
  36. package/lib/chevre/service/payment/any/authorize.d.ts +1 -1
  37. package/lib/chevre/service/payment/any/findAcceptAction.js +4 -5
  38. package/lib/chevre/service/payment/any/findAuthorizeAction.js +4 -5
  39. package/lib/chevre/service/payment/any/findCheckAction.d.ts +3 -1
  40. package/lib/chevre/service/payment/any/findCheckAction.js +5 -6
  41. package/lib/chevre/service/payment/movieTicket/authorize.d.ts +1 -1
  42. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.d.ts +3 -1
  43. package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +3 -3
  44. package/lib/chevre/service/payment/movieTicket/validation.d.ts +3 -1
  45. package/lib/chevre/service/payment/movieTicket/validation.js +13 -43
  46. package/lib/chevre/service/task/acceptCOAOffer.js +4 -5
  47. package/lib/chevre/service/task/authorizePayment.js +5 -6
  48. package/lib/chevre/service/task/checkMovieTicket.js +7 -6
  49. package/lib/chevre/service/task/pay.js +3 -2
  50. package/lib/chevre/service/task/payment/payByTask.d.ts +3 -1
  51. package/lib/chevre/service/task/payment/payByTask.js +1 -1
  52. package/lib/chevre/service/task/publishPaymentUrl.js +4 -5
  53. package/package.json +1 -1
@@ -1,67 +1,48 @@
1
- import { Surfrock } from '@surfrock/sdk';
1
+ import type { Surfrock } from '@surfrock/sdk';
2
2
  import type { Connection } from 'mongoose';
3
3
  import { factory } from '../../factory';
4
- import { ActionProcessRepo, IActionRecipe } from './anyAction/actionProcess';
4
+ import { DedicatedActionProcessRepo, IActionRecipe, IRecipeAsActionAttributes } from './dedicatedAction/dedicatedActionProcess';
5
5
  export type IMinimizedPurchaseNumberAuthResult = Pick<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberAuthResult, 'mkknmiNumSum' | 'resultInfo' | 'ykknmiNumSum'> & {
6
6
  knyknrNoInfoOut: Omit<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberInfo, 'ykknInfo' | 'mkknInfo'>[] | null;
7
7
  };
8
+ type StartableActionType = factory.actionType.CheckAction;
9
+ export type ICheckMovieTicketAction = factory.action.check.paymentMethod.movieTicket.IAction;
8
10
  /**
9
- * アクションIDで参照、あるいは、決済カードコード+イベントIDで参照
11
+ * 決済カード認証アクションリポジトリ
10
12
  */
11
- type IFindCompletedCheckActionsParams = ({
13
+ export declare class CheckMovieTicketActionRepo extends DedicatedActionProcessRepo<StartableActionType, IActionRecipe<factory.recipe.RecipeCategory.checkMovieTicket>> {
12
14
  /**
13
- * アクションID
15
+ * 専用アクションモデル
14
16
  */
15
- id?: string;
16
- purpose?: {
17
- /**
18
- * 注文取引ID
19
- */
20
- id?: string;
21
- };
22
- object?: never;
23
- sort?: never;
24
- }) | (Pick<factory.action.ISearchConditions, 'sort'> & {
25
- purpose?: {
26
- /**
27
- * 注文取引ID
28
- */
29
- id?: string;
30
- };
31
- object?: {
32
- /**
33
- * 決済サービス
34
- */
35
- id?: {
36
- $eq?: string;
37
- };
38
- movieTickets?: {
39
- identifier?: {
40
- $eq?: string;
41
- };
42
- serviceOutput?: {
43
- reservationFor?: {
44
- id?: {
45
- $eq?: string;
46
- };
47
- };
48
- };
49
- };
50
- typeOf?: {
51
- $eq?: factory.service.paymentService.PaymentServiceType.MovieTicket;
52
- };
53
- };
17
+ private readonly checkMovieTicketActionModel;
54
18
  /**
55
- * アクションID
19
+ * 旧汎用アクションモデル
56
20
  */
57
- id?: never;
58
- });
59
- export type ICheckMovieTicketAction = factory.action.check.paymentMethod.movieTicket.IAction;
60
- /**
61
- * 決済カード認証アクションリポジトリ
62
- */
63
- export declare class CheckMovieTicketActionRepo extends ActionProcessRepo<ICheckMovieTicketAction, IActionRecipe<factory.recipe.RecipeCategory.checkMovieTicket>> {
21
+ private readonly legacyActionModel;
64
22
  constructor(connection: Connection);
23
+ startCheckMovieTicketAction(attributes: factory.action.check.paymentMethod.movieTicket.IAttributes, options?: {
24
+ recipe?: IRecipeAsActionAttributes<factory.recipe.RecipeCategory.checkMovieTicket>;
25
+ }): Promise<Pick<ICheckMovieTicketAction, 'id' | 'typeOf' | 'startDate'>>;
26
+ completeCheckMovieTicketAction(params: {
27
+ typeOf: StartableActionType;
28
+ id: string;
29
+ result: factory.action.check.paymentMethod.movieTicket.IResult;
30
+ recipe?: IRecipeAsActionAttributes<factory.recipe.RecipeCategory.checkMovieTicket>;
31
+ }): Promise<void>;
32
+ giveUpCheckMovieTicketAction(params: {
33
+ typeOf: StartableActionType;
34
+ id: string;
35
+ error: Error | Error[] | unknown;
36
+ recipe?: IRecipeAsActionAttributes<factory.recipe.RecipeCategory.checkMovieTicket>;
37
+ }): Promise<void>;
38
+ findActionBySameAs(params: {
39
+ sameAs: {
40
+ id: string;
41
+ };
42
+ purpose?: {
43
+ id: string;
44
+ };
45
+ }): Promise<Pick<import("@chevre/factory/lib/chevre/action/check/paymentMethod/movieTicket").IAction, "error" | "id" | "purpose" | "actionStatus"> | null>;
65
46
  /**
66
47
  * アクションIDからレシピのafterMediaを参照する
67
48
  */
@@ -73,6 +54,7 @@ export declare class CheckMovieTicketActionRepo extends ActionProcessRepo<ICheck
73
54
  id: string;
74
55
  };
75
56
  }): Promise<IMinimizedPurchaseNumberAuthResult | undefined>;
57
+ private completedCheckMovieTicketActionExistsById;
76
58
  searchYkknInfoByCheckRecipe(filter: {
77
59
  limit: number;
78
60
  page: number;
@@ -108,6 +90,17 @@ export declare class CheckMovieTicketActionRepo extends ActionProcessRepo<ICheck
108
90
  /**
109
91
  * 認証済アクション参照
110
92
  */
111
- findCompletedCheckActions(params: IFindCompletedCheckActionsParams): Promise<Pick<ICheckMovieTicketAction, 'id'>[]>;
93
+ findCompletedCheckMovieTicketAction(params: {
94
+ /**
95
+ * 認証アクションID
96
+ */
97
+ id: string;
98
+ purpose: {
99
+ /**
100
+ * 注文取引ID
101
+ */
102
+ id: string;
103
+ };
104
+ }): Promise<Pick<import("@chevre/factory/lib/chevre/action/check/paymentMethod/movieTicket").IAction, "id"> | null>;
112
105
  }
113
106
  export {};
@@ -3,22 +3,75 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CheckMovieTicketActionRepo = void 0;
4
4
  const factory_1 = require("../../factory");
5
5
  const settings_1 = require("../../settings");
6
- const actionProcess_1 = require("./anyAction/actionProcess");
6
+ const checkMovieTicket_1 = require("../mongoose/schemas/action/checkMovieTicket");
7
+ const action_1 = require("../mongoose/schemas/action");
8
+ const dedicatedActionProcess_1 = require("./dedicatedAction/dedicatedActionProcess");
7
9
  const EXPIRE_AFTER_SECONDS = 2592000; // 30 days
8
10
  /**
9
11
  * 決済カード認証アクションリポジトリ
10
12
  */
11
- class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
13
+ class CheckMovieTicketActionRepo extends dedicatedActionProcess_1.DedicatedActionProcessRepo {
14
+ /**
15
+ * 専用アクションモデル
16
+ */
17
+ checkMovieTicketActionModel;
18
+ /**
19
+ * 旧汎用アクションモデル
20
+ */
21
+ legacyActionModel;
12
22
  constructor(connection) {
13
- super({ connection }, {
23
+ const checkMovieTicketActionModel = connection.model(checkMovieTicket_1.modelName, (0, checkMovieTicket_1.createSchema)());
24
+ const legacyActionModel = connection.model(action_1.modelName, (0, action_1.createSchema)());
25
+ super({
26
+ connection,
27
+ actionModel: checkMovieTicketActionModel
28
+ }, {
14
29
  expireAfterSeconds: EXPIRE_AFTER_SECONDS,
15
30
  recipeExpireAfterSeconds: EXPIRE_AFTER_SECONDS
16
31
  });
32
+ this.checkMovieTicketActionModel = checkMovieTicketActionModel;
33
+ this.legacyActionModel = legacyActionModel;
34
+ }
35
+ async startCheckMovieTicketAction(attributes, options) {
36
+ return this.startAction(attributes, options);
37
+ }
38
+ async completeCheckMovieTicketAction(params) {
39
+ await this.completeAction(params);
40
+ }
41
+ async giveUpCheckMovieTicketAction(params) {
42
+ await this.giveUpAction(params);
43
+ }
44
+ async findActionBySameAs(params) {
45
+ const filter = {
46
+ typeOf: { $eq: factory_1.factory.actionType.CheckAction }, // 1taskから複数actionが発生する可能性があるので、typeOf指定が必須
47
+ 'sameAs.id': { $exists: true, $eq: params.sameAs.id },
48
+ ...(typeof params.purpose?.id === 'string')
49
+ ? { 'purpose.id': { $exists: true, $eq: params.purpose.id } }
50
+ : undefined
51
+ };
52
+ const projection = {
53
+ _id: 0,
54
+ id: { $toString: '$_id' },
55
+ actionStatus: 1,
56
+ error: 1,
57
+ purpose: 1
58
+ };
59
+ const doc = await this.checkMovieTicketActionModel.findOne(filter, projection)
60
+ .lean()
61
+ .exec();
62
+ if (doc === null) {
63
+ // コレクション移行の互換性維持対応(2026-08-20~)
64
+ return this.legacyActionModel.findOne(filter, projection)
65
+ .lean()
66
+ .exec();
67
+ }
68
+ return doc;
17
69
  }
18
70
  /**
19
71
  * アクションIDからレシピのafterMediaを参照する
20
72
  */
21
73
  async findIMinimizedPurchaseNumberAuthResultByCheckMovieTicketRecipe(params) {
74
+ // レシピのみ参照のため互換性維持対応は不要
22
75
  const recipe = await this.actionRecipeModel.findOne({
23
76
  'project.id': { $eq: params.project.id },
24
77
  'recipeFor.id': { $eq: params.recipeFor.id }
@@ -35,7 +88,7 @@ class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
35
88
  .exec();
36
89
  return recipe?.step[0]?.itemListElement[0]?.itemListElement[0]?.afterMedia;
37
90
  }
38
- async searchYkknInfoByCheckRecipe(filter) {
91
+ async completedCheckMovieTicketActionExistsById(filter) {
39
92
  const filterQuery = {
40
93
  _id: { $eq: filter.id },
41
94
  'project.id': { $eq: filter.project.id },
@@ -43,11 +96,19 @@ class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
43
96
  typeOf: { $eq: factory_1.factory.actionType.CheckAction },
44
97
  actionStatus: { $eq: factory_1.factory.actionStatusType.CompletedActionStatus }
45
98
  };
46
- const actionDoc = await this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
99
+ const actionDoc = await this.checkMovieTicketActionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
47
100
  .exec();
48
101
  if (actionDoc === null) {
49
- throw new factory_1.factory.errors.NotFound(this.actionModel.modelName);
102
+ // コレクション移行の互換性維持対応(2026-08-20~)
103
+ const legacyActionDoc = await this.legacyActionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
104
+ .exec();
105
+ if (legacyActionDoc === null) {
106
+ throw new factory_1.factory.errors.NotFound(this.checkMovieTicketActionModel.modelName);
107
+ }
50
108
  }
109
+ }
110
+ async searchYkknInfoByCheckRecipe(filter) {
111
+ await this.completedCheckMovieTicketActionExistsById(filter);
51
112
  const filterQuery4recipe = {
52
113
  'recipeFor.id': { $eq: filter.id }
53
114
  };
@@ -79,18 +140,7 @@ class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
79
140
  .exec();
80
141
  }
81
142
  async searchMkknInfoByCheckRecipe(filter) {
82
- const filterQuery = {
83
- _id: { $eq: filter.id },
84
- 'project.id': { $eq: filter.project.id },
85
- 'purpose.id': { $exists: true, $eq: filter.purpose.id },
86
- typeOf: { $eq: factory_1.factory.actionType.CheckAction },
87
- actionStatus: { $eq: factory_1.factory.actionStatusType.CompletedActionStatus }
88
- };
89
- const actionDoc = this.actionModel.findOne(filterQuery, { _id: 1 }, { lean: true })
90
- .exec();
91
- if (actionDoc === null) {
92
- throw new factory_1.factory.errors.NotFound(this.actionModel.modelName);
93
- }
143
+ await this.completedCheckMovieTicketActionExistsById(filter);
94
144
  const filterQuery4recipe = {
95
145
  'recipeFor.id': { $eq: filter.id }
96
146
  };
@@ -128,57 +178,29 @@ class CheckMovieTicketActionRepo extends actionProcess_1.ActionProcessRepo {
128
178
  /**
129
179
  * 認証済アクション参照
130
180
  */
131
- async findCompletedCheckActions(params) {
132
- const andConditions = [
133
- ...(typeof params.id === 'string') ? [{ _id: { $eq: params.id } }] : [],
134
- { typeOf: { $eq: factory_1.factory.actionType.CheckAction } },
135
- { actionStatus: { $eq: factory_1.factory.actionStatusType.CompletedActionStatus } }
136
- ];
137
- const objectMovieTicketsIdentifierEq = params.object?.movieTickets?.identifier?.$eq;
138
- if (typeof objectMovieTicketsIdentifierEq === 'string') {
139
- andConditions.push({
140
- 'object.movieTickets.identifier': { $exists: true, $eq: objectMovieTicketsIdentifierEq }
141
- });
142
- }
143
- const objectMovieTicketsServiceOutputReservationForIdEq = params.object?.movieTickets?.serviceOutput?.reservationFor?.id?.$eq;
144
- if (typeof objectMovieTicketsServiceOutputReservationForIdEq === 'string') {
145
- andConditions.push({
146
- 'object.movieTickets.serviceOutput.reservationFor.id': { $exists: true, $eq: objectMovieTicketsServiceOutputReservationForIdEq }
147
- });
148
- }
149
- const objectTypeOfEq = params.object?.typeOf?.$eq;
150
- if (typeof objectTypeOfEq === 'string') {
151
- andConditions.push({
152
- 'object.typeOf': { $exists: true, $eq: objectTypeOfEq }
153
- });
154
- }
155
- const objectIdEq = params.object?.id?.$eq;
156
- if (typeof objectIdEq === 'string') {
157
- andConditions.push({
158
- 'object.id': { $exists: true, $eq: objectIdEq }
159
- });
160
- }
161
- const purposeIdEq = params.purpose?.id;
162
- if (typeof purposeIdEq === 'string') {
163
- andConditions.push({
164
- 'purpose.id': { $exists: true, $eq: purposeIdEq }
165
- });
166
- }
181
+ async findCompletedCheckMovieTicketAction(params) {
182
+ const filter = {
183
+ _id: { $eq: params.id },
184
+ typeOf: { $eq: factory_1.factory.actionType.CheckAction },
185
+ actionStatus: { $eq: factory_1.factory.actionStatusType.CompletedActionStatus },
186
+ 'purpose.id': { $exists: true, $eq: params.purpose.id }
187
+ };
167
188
  const projection = {
168
189
  _id: 0,
169
190
  id: { $toString: '$_id' },
170
191
  };
171
- const query = this.actionModel.find({ $and: andConditions }, projection);
172
- query.limit(1);
173
- /* istanbul ignore else */
174
- if (params.sort?.startDate !== undefined) {
175
- query.sort({ startDate: params.sort.startDate });
176
- }
177
- // const explainResult = await (<any>query).explain();
178
- // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
179
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
192
+ const doc = await this.checkMovieTicketActionModel.findOne(filter, projection)
193
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
180
194
  .lean()
181
195
  .exec();
196
+ if (doc === null) {
197
+ // コレクション移行の互換性維持対応(2026-08-20~)
198
+ return this.legacyActionModel.findOne(filter, projection)
199
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
200
+ .lean()
201
+ .exec();
202
+ }
203
+ return doc;
182
204
  }
183
205
  }
184
206
  exports.CheckMovieTicketActionRepo = CheckMovieTicketActionRepo;
@@ -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
+ export { IActionRecipe, IRecipeAsActionAttributes };
6
+ type AvailableActionType = factory.actionType.InformAction | factory.actionType.AddAction | factory.actionType.UpdateAction | factory.actionType.ReplaceAction | factory.actionType.DeleteAction | factory.actionType.UseAction | factory.actionType.CheckAction;
7
+ 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 : T extends factory.actionType.CheckAction ? factory.action.check.paymentMethod.movieTicket.IAction : never;
8
+ 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 : T extends factory.actionType.CheckAction ? factory.action.check.paymentMethod.movieTicket.IAttributes : never;
9
+ 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 : T extends factory.actionType.CheckAction ? factory.action.check.paymentMethod.movieTicket.IResult : never;
10
+ interface IOptions {
11
+ expireAfterSeconds: number;
12
+ recipeExpireAfterSeconds: number;
13
+ }
14
+ /**
15
+ * 専用アクション状態管理リポジトリ
16
+ * mongoose modelは継承クラスから指定される前提
17
+ */
18
+ export declare class DedicatedActionProcessRepo<TActionType extends AvailableActionType, TActionRecipe extends IActionRecipe<factory.recipe.RecipeCategory>> extends ActionRecipeRepo<TActionRecipe> {
19
+ private readonly actionModel;
20
+ private options;
21
+ protected constructor(params: {
22
+ connection: Connection;
23
+ actionModel: IAbstractActionModel;
24
+ }, options: IOptions);
25
+ /**
26
+ * アクション開始
27
+ */
28
+ protected startAction<T extends TActionType>(attributes: IActionAttributes<T>, options?: {
29
+ recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
30
+ }): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
31
+ protected completeAction<T extends TActionType>(params: {
32
+ typeOf: T;
33
+ id: string;
34
+ result?: IResult<T>;
35
+ recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
36
+ }): Promise<void>;
37
+ /**
38
+ * アクション失敗
39
+ */
40
+ protected giveUpAction<T extends TActionType>(params: {
41
+ typeOf: T;
42
+ id: string;
43
+ error: Error | Error[] | unknown;
44
+ recipe?: IRecipeAsActionAttributes<TActionRecipe['recipeCategory']>;
45
+ }): Promise<void>;
46
+ }
@@ -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 unknown2actionError_1 = require("./unknown2actionError");
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
- this.informActionModel = connection.model(inform_1.modelName, (0, inform_1.createSchema)());
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
- const startDate = new Date();
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
- const doc = await this.informActionModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
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
- const actionError = Array.isArray(params.error)
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.findAnyActions({
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: StartableActionType;
22
+ completeUpdateAction<T extends StartableActionType>(params: {
23
+ typeOf: T;
22
24
  id: string;
23
- result: any;
25
+ result: IResult<T>;
24
26
  }): Promise<void>;
25
27
  /**
26
28
  * アクション失敗
27
29
  */
28
- giveUpUpdateAction(params: {
29
- typeOf: StartableActionType;
30
+ giveUpUpdateAction<T extends StartableActionType>(params: {
31
+ typeOf: T;
30
32
  id: string;
31
33
  error: Error | Error[] | unknown;
32
34
  }): Promise<void>;