@chevre/domain 24.0.0-alpha.15 → 24.0.0-alpha.17

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 (28) hide show
  1. package/lib/chevre/repo/action/acceptCOAOffer.d.ts +23 -0
  2. package/lib/chevre/repo/action/acceptCOAOffer.js +64 -0
  3. package/lib/chevre/repo/action/actionProcess.d.ts +97 -0
  4. package/lib/chevre/repo/action/actionProcess.js +270 -0
  5. package/lib/chevre/repo/action/authorizeOffer.d.ts +21 -0
  6. package/lib/chevre/repo/action/authorizeOffer.js +85 -0
  7. package/lib/chevre/repo/action.d.ts +3 -163
  8. package/lib/chevre/repo/action.js +308 -580
  9. package/lib/chevre/repo/aggregateAction.d.ts +102 -0
  10. package/lib/chevre/repo/aggregateAction.js +379 -0
  11. package/lib/chevre/repo/transaction/moneyTransfer.d.ts +61 -0
  12. package/lib/chevre/repo/transaction/moneyTransfer.js +379 -0
  13. package/lib/chevre/repo/transaction.d.ts +1 -52
  14. package/lib/chevre/repo/transaction.js +442 -409
  15. package/lib/chevre/repository.d.ts +22 -0
  16. package/lib/chevre/repository.js +49 -2
  17. package/lib/chevre/service/aggregation/system.d.ts +10 -10
  18. package/lib/chevre/service/aggregation/system.js +9 -9
  19. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +4 -2
  20. package/lib/chevre/service/offer/eventServiceByCOA/authorizeByAcceptAction.js +20 -12
  21. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +16 -7
  22. package/lib/chevre/service/task/deleteTransaction.js +3 -1
  23. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  24. package/lib/chevre/service/transaction/deleteTransaction.js +2 -2
  25. package/lib/chevre/service/transaction/moneyTransfer.d.ts +5 -5
  26. package/lib/chevre/service/transaction/moneyTransfer.js +5 -5
  27. package/lib/chevre/service/transaction.d.ts +2 -0
  28. package/package.json +1 -1
@@ -0,0 +1,23 @@
1
+ import * as factory from '../../factory';
2
+ import { IKeyOfProjection, ActionProcessRepo } from './actionProcess';
3
+ export type IAcceptCOAOfferAction = factory.action.accept.coaOffer.IAction;
4
+ /**
5
+ * COAオファー採用リポジトリ
6
+ */
7
+ export declare class AcceptCOAOfferActionRepo extends ActionProcessRepo<IAcceptCOAOfferAction> {
8
+ /**
9
+ * 完了済の採用アクションを参照する
10
+ */
11
+ findCompletedById(params: {
12
+ project: {
13
+ id: string;
14
+ };
15
+ /**
16
+ * アクションID
17
+ */
18
+ id: string;
19
+ purpose: {
20
+ id: string;
21
+ };
22
+ }, inclusion: IKeyOfProjection[]): Promise<IAcceptCOAOfferAction>;
23
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AcceptCOAOfferActionRepo = void 0;
27
+ const factory = __importStar(require("../../factory"));
28
+ // import { MONGO_MAX_TIME_MS } from '../settings';
29
+ // import { createSchema, IModel as IActionModel, modelName } from './mongoose/schemas/action';
30
+ // import { createSchema as createRecipeSchema, IModel as IActionRecipeModel, modelName as recipeModelName } from './mongoose/schemas/actionRecipe';
31
+ const actionProcess_1 = require("./actionProcess");
32
+ /**
33
+ * COAオファー採用リポジトリ
34
+ */
35
+ class AcceptCOAOfferActionRepo extends actionProcess_1.ActionProcessRepo {
36
+ /**
37
+ * 完了済の採用アクションを参照する
38
+ */
39
+ async findCompletedById(params, inclusion) {
40
+ let positiveProjectionFields = actionProcess_1.AVAILABLE_PROJECT_FIELDS;
41
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
42
+ positiveProjectionFields = inclusion.filter((key) => actionProcess_1.AVAILABLE_PROJECT_FIELDS.includes(key));
43
+ }
44
+ const projection = {
45
+ _id: 0,
46
+ id: { $toString: '$_id' },
47
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
48
+ };
49
+ const doc = await this.actionModel.findOne({
50
+ _id: { $eq: params.id },
51
+ typeOf: { $eq: factory.actionType.AcceptAction },
52
+ 'project.id': { $eq: params.project.id },
53
+ 'purpose.id': { $exists: true, $eq: params.purpose.id },
54
+ actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] }
55
+ }, projection)
56
+ .lean()
57
+ .exec();
58
+ if (doc === null) {
59
+ throw new factory.errors.NotFound(this.actionModel.modelName);
60
+ }
61
+ return doc;
62
+ }
63
+ }
64
+ exports.AcceptCOAOfferActionRepo = AcceptCOAOfferActionRepo;
@@ -0,0 +1,97 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../../factory';
3
+ import { IModel as IActionModel } from '../mongoose/schemas/action';
4
+ import { IModel as IActionRecipeModel } from '../mongoose/schemas/actionRecipe';
5
+ export type IAction4transaction<T extends factory.actionType.AcceptAction | factory.actionType.AuthorizeAction> = T extends factory.actionType.AcceptAction ? factory.action.accept.coaOffer.IAction | factory.action.accept.pay.IAction : T extends factory.actionType.AuthorizeAction ? (factory.action.authorize.offer.eventService.IAction | factory.action.authorize.offer.moneyTransfer.IAction | factory.action.authorize.offer.product.IAction | factory.action.authorize.paymentMethod.any.IAction) : never;
6
+ export type IAction<T extends factory.actionType> = T extends factory.actionType.OrderAction ? factory.action.trade.order.IAction : T extends factory.actionType.AcceptAction ? IAction4transaction<factory.actionType.AcceptAction> : T extends factory.actionType.AuthorizeAction ? factory.action.authorize.IAction<factory.action.authorize.IAttributes<any, any>> : T extends factory.actionType.CheckAction ? (factory.action.check.paymentMethod.movieTicket.IAction | factory.action.check.thing.IAction) : T extends factory.actionType.CreateAction ? factory.action.create.IAction : T extends factory.actionType.MoneyTransfer ? factory.action.transfer.moneyTransfer.IAction : 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.InformAction ? factory.action.interact.inform.IAction<factory.action.interact.inform.IAttributes<factory.action.interact.inform.IObject>> & {
7
+ error?: any;
8
+ purpose?: never;
9
+ } : factory.action.IAction<factory.action.IAttributes<T, any, any>>;
10
+ export interface ICancelActionAction {
11
+ typeOf: factory.actionType.CancelAction;
12
+ agent: factory.action.IParticipantAsPerson | factory.action.IParticipantAsProject | factory.action.IParticipantAsWebApplication;
13
+ endTime: Date;
14
+ startTime: Date;
15
+ sameAs?: {
16
+ id: string;
17
+ typeOf: 'Task';
18
+ };
19
+ }
20
+ export type IActionRecipe<T extends factory.recipe.RecipeCategory> = T extends factory.recipe.RecipeCategory.checkMovieTicket ? factory.action.check.paymentMethod.movieTicket.IRecipe : T extends factory.recipe.RecipeCategory.payCreditCard ? factory.action.trade.pay.IPayCreditCardRecipe : T extends factory.recipe.RecipeCategory.payMovieTicket ? factory.action.trade.pay.IPayMovieTicketRecipe : T extends factory.recipe.RecipeCategory.publishPaymentUrl ? factory.action.accept.pay.IRecipe : T extends factory.recipe.RecipeCategory.refundCreditCard ? factory.action.trade.refund.IRefundCreditCardRecipe : T extends factory.recipe.RecipeCategory.refundMovieTicket ? factory.action.trade.refund.IRefundMovieTicketRecipe : T extends factory.recipe.RecipeCategory.acceptCOAOffer ? factory.action.accept.coaOffer.IRecipe : T extends factory.recipe.RecipeCategory.confirmCOAReserve ? factory.action.interact.confirm.reservation.IConfirmCOAReserveRecipe : never;
21
+ export type IRecipeAsDocument = factory.recipe.IRecipe & {
22
+ recipeFor: {
23
+ id: string;
24
+ typeOf: factory.actionType;
25
+ };
26
+ dateCreated: Date;
27
+ dateModified?: Date;
28
+ };
29
+ export type IRecipeAsActionAttributes = Pick<factory.recipe.IRecipe, 'project' | 'recipeCategory' | 'step' | 'typeOf'>;
30
+ export type IMinimizedPurchaseNumberAuthResult = Pick<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberAuthResult, 'mkknmiNumSum' | 'resultInfo' | 'ykknmiNumSum'> & {
31
+ knyknrNoInfoOut: Omit<factory.action.check.paymentMethod.movieTicket.IPurchaseNumberInfo, 'ykknInfo' | 'mkknInfo'>[] | null;
32
+ };
33
+ export type IKeyOfProjection = keyof IAction<factory.actionType> | keyof IAction<factory.actionType.AuthorizeAction> | keyof IAction<factory.actionType.MoneyTransfer> | keyof IAction<factory.actionType.ReplaceAction> | 'identifier';
34
+ export declare const AVAILABLE_PROJECT_FIELDS: IKeyOfProjection[];
35
+ /**
36
+ * アクション状態管理リポジトリ
37
+ */
38
+ export declare class ActionProcessRepo<TAction extends factory.action.IAction<factory.action.IAttributes<factory.actionType, any, any>>> {
39
+ protected readonly actionModel: IActionModel;
40
+ protected readonly actionRecipeModel: IActionRecipeModel;
41
+ constructor(connection: Connection);
42
+ /**
43
+ * アクション開始
44
+ */
45
+ start<T extends TAction['typeOf']>(attributes: factory.action.IAttributes<T, any, any>, options?: {
46
+ recipe?: IRecipeAsActionAttributes;
47
+ }): Promise<Pick<IAction<T>, 'id' | 'typeOf' | 'startDate'>>;
48
+ completeWithVoid(params: {
49
+ typeOf: TAction['typeOf'];
50
+ id: string;
51
+ result: any;
52
+ recipe?: IRecipeAsActionAttributes;
53
+ }): Promise<void>;
54
+ /**
55
+ * アクション取消
56
+ */
57
+ cancelWithVoid(params: {
58
+ typeOf: factory.actionType.AcceptAction | factory.actionType.AuthorizeAction;
59
+ id: string;
60
+ cancelAction?: Pick<ICancelActionAction, 'agent' | 'sameAs' | 'startTime'>;
61
+ }): Promise<void>;
62
+ /**
63
+ * アクション失敗
64
+ */
65
+ giveUp(params: {
66
+ typeOf: TAction['typeOf'];
67
+ id: string;
68
+ error: Error | Error[];
69
+ recipe?: IRecipeAsActionAttributes;
70
+ }): Promise<void>;
71
+ /**
72
+ * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
73
+ */
74
+ giveUpStartDatePassedCertainPeriod(params: {
75
+ id?: {
76
+ $eq?: string;
77
+ };
78
+ error: any;
79
+ startDate: {
80
+ $lt: Date;
81
+ };
82
+ }): Promise<any>;
83
+ findRecipeByAction<T extends factory.recipe.RecipeCategory>(params: {
84
+ project: {
85
+ id: string;
86
+ };
87
+ recipeFor: {
88
+ id: string;
89
+ };
90
+ }): Promise<Pick<IActionRecipe<T>, 'step' | 'recipeCategory'> | null>;
91
+ findById<T extends factory.actionType>(params: {
92
+ typeOf: T;
93
+ id: string;
94
+ }, inclusion?: IKeyOfProjection[], exclusion?: IKeyOfProjection[]): Promise<IAction<T>>;
95
+ private findActionStatusById;
96
+ protected upsertRecipe(savingRecipe: Pick<IRecipeAsDocument, 'project' | 'recipeCategory' | 'recipeFor' | 'step' | 'typeOf'>): Promise<import("mongoose").UpdateWriteOpResult>;
97
+ }
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ActionProcessRepo = exports.AVAILABLE_PROJECT_FIELDS = void 0;
27
+ const factory = __importStar(require("../../factory"));
28
+ // import { MONGO_MAX_TIME_MS } from '../settings';
29
+ const action_1 = require("../mongoose/schemas/action");
30
+ const actionRecipe_1 = require("../mongoose/schemas/actionRecipe");
31
+ exports.AVAILABLE_PROJECT_FIELDS = [
32
+ 'project',
33
+ 'actionStatus',
34
+ 'typeOf',
35
+ 'description',
36
+ 'agent',
37
+ 'recipient',
38
+ 'result',
39
+ 'error',
40
+ 'object',
41
+ 'startDate',
42
+ 'endDate',
43
+ 'purpose',
44
+ 'potentialActions',
45
+ 'amount',
46
+ 'fromLocation',
47
+ 'toLocation',
48
+ 'instrument',
49
+ 'location',
50
+ 'replacer',
51
+ 'targetCollection',
52
+ 'sameAs',
53
+ 'cancelAction',
54
+ 'about',
55
+ 'target',
56
+ 'identifier'
57
+ ];
58
+ /**
59
+ * アクション状態管理リポジトリ
60
+ */
61
+ class ActionProcessRepo {
62
+ actionModel;
63
+ actionRecipeModel;
64
+ constructor(connection) {
65
+ this.actionModel = connection.model(action_1.modelName, (0, action_1.createSchema)());
66
+ this.actionRecipeModel = connection.model(actionRecipe_1.modelName, (0, actionRecipe_1.createSchema)());
67
+ }
68
+ /**
69
+ * アクション開始
70
+ */
71
+ async start(attributes, options) {
72
+ const startDate = new Date();
73
+ const creatingAction = {
74
+ ...attributes,
75
+ actionStatus: factory.actionStatusType.ActiveActionStatus,
76
+ startDate
77
+ };
78
+ // reimplemnt with insertMany(2024-08-29~)
79
+ const result = await this.actionModel.insertMany(creatingAction, { rawResult: true });
80
+ const id = result.insertedIds?.[0]?.toHexString();
81
+ if (typeof id !== 'string') {
82
+ throw new factory.errors.Internal('action not saved');
83
+ }
84
+ // add recipe(2024-06-09~)
85
+ const savingRecipe = options?.recipe;
86
+ if (savingRecipe?.typeOf === 'Recipe') {
87
+ await this.upsertRecipe({ ...savingRecipe, recipeFor: { id, typeOf: creatingAction.typeOf } });
88
+ }
89
+ return { id, startDate, typeOf: creatingAction.typeOf };
90
+ }
91
+ async completeWithVoid(params) {
92
+ if (params.recipe?.typeOf === 'Recipe') {
93
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
94
+ }
95
+ const doc = await this.actionModel.findOneAndUpdate({
96
+ _id: { $eq: params.id },
97
+ typeOf: { $eq: params.typeOf }
98
+ }, {
99
+ $set: {
100
+ actionStatus: factory.actionStatusType.CompletedActionStatus,
101
+ result: params.result,
102
+ endDate: new Date()
103
+ }
104
+ }, { new: false, projection: { _id: 1 } })
105
+ .lean()
106
+ .exec();
107
+ if (doc === null) {
108
+ throw new factory.errors.NotFound(this.actionModel.modelName);
109
+ }
110
+ }
111
+ /**
112
+ * アクション取消
113
+ */
114
+ async cancelWithVoid(params) {
115
+ const cancelDate = new Date();
116
+ const cancelAction = (params.cancelAction !== undefined)
117
+ ? {
118
+ ...params.cancelAction,
119
+ endTime: cancelDate,
120
+ typeOf: factory.actionType.CancelAction
121
+ }
122
+ : undefined;
123
+ const doc = await this.actionModel.findOneAndUpdate({
124
+ _id: { $eq: params.id },
125
+ typeOf: { $eq: params.typeOf },
126
+ actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
127
+ }, {
128
+ $set: {
129
+ actionStatus: factory.actionStatusType.CanceledActionStatus,
130
+ ...(cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
131
+ }
132
+ }, { new: false, projection: { _id: 1 } })
133
+ .lean()
134
+ .exec();
135
+ if (doc === null) {
136
+ // 既にCanceledActionStatusであればok
137
+ const existingAction = await this.findActionStatusById({ id: params.id, typeOf: params.typeOf });
138
+ if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
139
+ throw new factory.errors.NotFound(this.actionModel.modelName);
140
+ }
141
+ }
142
+ // endDateが存在しなければセット(2024-04-22~)
143
+ await this.actionModel.updateOne({
144
+ _id: { $eq: params.id },
145
+ endDate: { $exists: false }
146
+ }, { $set: { endDate: cancelDate } })
147
+ .exec();
148
+ }
149
+ /**
150
+ * アクション失敗
151
+ */
152
+ async giveUp(params) {
153
+ const actionError = (Array.isArray(params.error))
154
+ ? params.error.map((e) => ({ ...e, message: e.message, name: e.name }))
155
+ : { ...params.error, message: params.error.message, name: params.error.name };
156
+ if (params.recipe?.typeOf === 'Recipe') {
157
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
158
+ }
159
+ const doc = await this.actionModel.findOneAndUpdate({
160
+ typeOf: { $eq: params.typeOf },
161
+ _id: { $eq: params.id }
162
+ }, {
163
+ $set: {
164
+ actionStatus: factory.actionStatusType.FailedActionStatus,
165
+ error: actionError,
166
+ endDate: new Date()
167
+ }
168
+ }, { new: true, projection: { _id: 1 } })
169
+ .lean()
170
+ .exec();
171
+ if (doc === null) {
172
+ throw new factory.errors.NotFound(this.actionModel.modelName);
173
+ }
174
+ }
175
+ /**
176
+ * 一定期間ActiveActionStatusのアクションをFailedActionStatusにする
177
+ */
178
+ async giveUpStartDatePassedCertainPeriod(params) {
179
+ return this.actionModel.updateMany({
180
+ actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus },
181
+ // 一定期間過ぎたもの
182
+ startDate: { $lt: params.startDate.$lt },
183
+ ...(typeof params.id?.$eq === 'string') ? { _id: { $eq: params.id.$eq } } : undefined
184
+ }, {
185
+ actionStatus: factory.actionStatusType.FailedActionStatus,
186
+ error: params.error,
187
+ endDate: new Date()
188
+ })
189
+ .exec();
190
+ }
191
+ async findRecipeByAction(params) {
192
+ return this.actionRecipeModel.findOne({
193
+ 'project.id': { $eq: params.project.id },
194
+ 'recipeFor.id': { $eq: params.recipeFor.id }
195
+ }, { step: 1, recipeCategory: 1 }
196
+ // { lean: true }
197
+ )
198
+ .lean()
199
+ .exec();
200
+ // if (result === null) {
201
+ // throw new factory.errors.NotFound(this.actionRecipeModel.modelName);
202
+ // }
203
+ // return result;
204
+ }
205
+ async findById(params, inclusion, exclusion) {
206
+ let positiveProjectionFields = exports.AVAILABLE_PROJECT_FIELDS;
207
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
208
+ positiveProjectionFields = inclusion.filter((key) => exports.AVAILABLE_PROJECT_FIELDS.includes(key));
209
+ }
210
+ else {
211
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
212
+ positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
213
+ }
214
+ }
215
+ const projection = {
216
+ _id: 0,
217
+ id: { $toString: '$_id' },
218
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
219
+ };
220
+ const doc = await this.actionModel.findOne({
221
+ typeOf: { $eq: params.typeOf },
222
+ _id: { $eq: params.id }
223
+ }, projection)
224
+ .lean() // 2024-08-26~
225
+ .exec();
226
+ if (doc === null) {
227
+ throw new factory.errors.NotFound(this.actionModel.modelName);
228
+ }
229
+ return doc;
230
+ }
231
+ async findActionStatusById(params) {
232
+ const projection = {
233
+ _id: 0,
234
+ id: { $toString: '$_id' },
235
+ actionStatus: 1
236
+ };
237
+ const doc = await this.actionModel.findOne({
238
+ typeOf: { $eq: params.typeOf },
239
+ _id: { $eq: params.id }
240
+ }, projection)
241
+ .lean() // 2024-08-26~
242
+ .exec();
243
+ if (doc === null) {
244
+ throw new factory.errors.NotFound(this.actionModel.modelName);
245
+ }
246
+ return doc;
247
+ }
248
+ async upsertRecipe(savingRecipe) {
249
+ const dateModified = new Date();
250
+ const { typeOf, project, recipeCategory, recipeFor, step } = savingRecipe;
251
+ const filter = {
252
+ 'recipeFor.id': { $eq: recipeFor.id }
253
+ };
254
+ const setOnInsert = {
255
+ project, typeOf, recipeCategory, recipeFor,
256
+ dateCreated: dateModified
257
+ };
258
+ const setKeys = { step, dateModified };
259
+ const update = {
260
+ $setOnInsert: setOnInsert,
261
+ $set: setKeys
262
+ };
263
+ return this.actionRecipeModel.updateOne(filter, update, {
264
+ upsert: true,
265
+ includeResultMetadata: true
266
+ })
267
+ .exec();
268
+ }
269
+ }
270
+ exports.ActionProcessRepo = ActionProcessRepo;
@@ -0,0 +1,21 @@
1
+ import * as factory from '../../factory';
2
+ import { IRecipeAsActionAttributes, ActionProcessRepo } from './actionProcess';
3
+ export type IAuthorizeOfferAction = factory.action.authorize.offer.eventService.IAction;
4
+ /**
5
+ * オファー承認リポジトリ
6
+ */
7
+ export declare class AuthorizeOfferActionRepo extends ActionProcessRepo<IAuthorizeOfferAction> {
8
+ /**
9
+ * アクション再開
10
+ */
11
+ reStart(params: {
12
+ typeOf: factory.actionType;
13
+ id: string;
14
+ recipe?: IRecipeAsActionAttributes;
15
+ }): Promise<void>;
16
+ reCompleteAuthorizeEventOfferAction(params: {
17
+ id: string;
18
+ object: factory.action.authorize.offer.eventService.IObject;
19
+ result: factory.action.authorize.offer.eventService.IResult;
20
+ }): Promise<void>;
21
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.AuthorizeOfferActionRepo = void 0;
27
+ const factory = __importStar(require("../../factory"));
28
+ // import { MONGO_MAX_TIME_MS } from '../settings';
29
+ // import { createSchema, IModel as IActionModel, modelName } from './mongoose/schemas/action';
30
+ // import { createSchema as createRecipeSchema, IModel as IActionRecipeModel, modelName as recipeModelName } from './mongoose/schemas/actionRecipe';
31
+ const actionProcess_1 = require("./actionProcess");
32
+ /**
33
+ * オファー承認リポジトリ
34
+ */
35
+ class AuthorizeOfferActionRepo extends actionProcess_1.ActionProcessRepo {
36
+ /**
37
+ * アクション再開
38
+ */
39
+ async reStart(params) {
40
+ const doc = await this.actionModel.findOneAndUpdate({
41
+ _id: { $eq: params.id },
42
+ typeOf: { $eq: params.typeOf },
43
+ actionStatus: { $eq: factory.actionStatusType.CompletedActionStatus }
44
+ }, {
45
+ $set: {
46
+ actionStatus: factory.actionStatusType.ActiveActionStatus,
47
+ startDate: new Date()
48
+ },
49
+ $unset: { endDate: 1 }
50
+ }, { new: false, projection: { _id: 1 } })
51
+ .lean()
52
+ .exec();
53
+ if (doc === null) {
54
+ throw new factory.errors.NotFound(this.actionModel.modelName);
55
+ }
56
+ // add recipe(2024-06-09~)
57
+ if (params.recipe?.typeOf === 'Recipe') {
58
+ await this.upsertRecipe({ ...params.recipe, recipeFor: { id: params.id, typeOf: params.typeOf } });
59
+ }
60
+ }
61
+ async reCompleteAuthorizeEventOfferAction(params) {
62
+ return this.actionModel.findOneAndUpdate({
63
+ // typeOf: factory.actionType.AuthorizeAction,
64
+ _id: { $eq: params.id },
65
+ // ActiveActionStatus->CompletedActionStatusで再実装(2024-01-15~)
66
+ // actionStatus: factory.actionStatusType.CompletedActionStatus
67
+ actionStatus: { $eq: factory.actionStatusType.ActiveActionStatus }
68
+ }, {
69
+ $set: {
70
+ actionStatus: factory.actionStatusType.CompletedActionStatus,
71
+ object: params.object,
72
+ result: params.result,
73
+ endDate: new Date()
74
+ }
75
+ }, { new: true, projection: { _id: 1 } })
76
+ .lean()
77
+ .exec()
78
+ .then((doc) => {
79
+ if (doc === null) {
80
+ throw new factory.errors.NotFound(this.actionModel.modelName);
81
+ }
82
+ });
83
+ }
84
+ }
85
+ exports.AuthorizeOfferActionRepo = AuthorizeOfferActionRepo;