@chevre/domain 21.32.0-alpha.15 → 21.32.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.
@@ -49,6 +49,16 @@ interface IStatus {
49
49
  interface IAggregateAction {
50
50
  statuses: IStatus[];
51
51
  }
52
+ export interface ICancelActionAction {
53
+ typeOf: factory.actionType.CancelAction;
54
+ agent: factory.action.IParticipantAsPerson | factory.action.IParticipantAsProject | factory.action.IParticipantAsWebApplication;
55
+ endTime: Date;
56
+ startTime: Date;
57
+ sameAs?: {
58
+ id: string;
59
+ typeOf: 'Task';
60
+ };
61
+ }
52
62
  /**
53
63
  * アクションリポジトリ
54
64
  */
@@ -81,8 +91,9 @@ export declare class MongoRepository {
81
91
  * アクション取消
82
92
  */
83
93
  cancelWithVoid(params: {
84
- typeOf: factory.actionType;
94
+ typeOf: factory.actionType.AuthorizeAction;
85
95
  id: string;
96
+ cancelAction?: Pick<ICancelActionAction, 'agent' | 'sameAs' | 'startTime'>;
86
97
  }): Promise<void>;
87
98
  /**
88
99
  * アクション失敗
@@ -505,19 +505,30 @@ class MongoRepository {
505
505
  */
506
506
  cancelWithVoid(params) {
507
507
  return __awaiter(this, void 0, void 0, function* () {
508
+ const cancelDate = new Date();
509
+ const cancelAction = (params.cancelAction !== undefined)
510
+ ? Object.assign(Object.assign({}, params.cancelAction), { endTime: cancelDate, typeOf: factory.actionType.CancelAction }) : undefined;
508
511
  const doc = yield this.actionModel.findOneAndUpdate({
509
512
  _id: { $eq: params.id },
510
- typeOf: { $eq: params.typeOf }
511
- }, { $set: { actionStatus: factory.actionStatusType.CanceledActionStatus } }, { new: false, projection: { _id: 1 } })
513
+ typeOf: { $eq: params.typeOf },
514
+ actionStatus: { $ne: factory.actionStatusType.CanceledActionStatus } // 冪等性確保(2024-05-26~)
515
+ }, {
516
+ $set: Object.assign({ actionStatus: factory.actionStatusType.CanceledActionStatus }, (cancelAction !== undefined) ? { cancelAction } : undefined // cancelAction連携(2024-05-26~)
517
+ )
518
+ }, { new: false, projection: { _id: 1 } })
512
519
  .exec();
513
520
  if (doc === null) {
514
- throw new factory.errors.NotFound(this.actionModel.modelName);
521
+ // 既にCanceledActionStatusであればok
522
+ const existingAction = yield this.findById({ id: params.id, typeOf: params.typeOf }, ['actionStatus'], []);
523
+ if (existingAction.actionStatus !== factory.actionStatusType.CanceledActionStatus) {
524
+ throw new factory.errors.NotFound(this.actionModel.modelName);
525
+ }
515
526
  }
516
527
  // endDateが存在しなければセット(2024-04-22~)
517
528
  yield this.actionModel.updateOne({
518
529
  _id: { $eq: params.id },
519
530
  endDate: { $exists: false }
520
- }, { $set: { endDate: new Date() } })
531
+ }, { $set: { endDate: cancelDate } })
521
532
  .exec();
522
533
  });
523
534
  }
@@ -27,7 +27,8 @@ const schemaDefinition = {
27
27
  location: mongoose_1.SchemaTypes.Mixed,
28
28
  replacer: mongoose_1.SchemaTypes.Mixed,
29
29
  targetCollection: mongoose_1.SchemaTypes.Mixed,
30
- sameAs: mongoose_1.SchemaTypes.Mixed // タスク関連付けのために追加(2024-04-20~)
30
+ sameAs: mongoose_1.SchemaTypes.Mixed,
31
+ cancelAction: mongoose_1.SchemaTypes.Mixed // add(2024-05-26~)
31
32
  };
32
33
  const schemaOptions = {
33
34
  autoIndex: settings_1.MONGO_AUTO_INDEX,
@@ -0,0 +1,24 @@
1
+ import * as factory from '../../../../factory';
2
+ import type { MongoRepository as ActionRepo } from '../../../../repo/action';
3
+ import type { MongoRepository as AssetTransactionRepo } from '../../../../repo/assetTransaction';
4
+ import type { MongoRepository as OrderInTransactionRepo } from '../../../../repo/orderInTransaction';
5
+ import type { RedisRepository as OfferRateLimitRepo } from '../../../../repo/rateLimit/offer';
6
+ import type { MongoRepository as ReservationRepo } from '../../../../repo/reservation';
7
+ import type { StockHolderRepository as StockHolderRepo } from '../../../../repo/stockHolder';
8
+ import type { MongoRepository as TaskRepo } from '../../../../repo/task';
9
+ import type { MongoRepository as TransactionRepo } from '../../../../repo/transaction';
10
+ export import WebAPIIdentifier = factory.service.webAPI.Identifier;
11
+ interface IVoidTransactionRepos {
12
+ action: ActionRepo;
13
+ assetTransaction: AssetTransactionRepo;
14
+ stockHolder: StockHolderRepo;
15
+ offerRateLimit: OfferRateLimitRepo;
16
+ orderInTransaction: OrderInTransactionRepo;
17
+ reservation: ReservationRepo;
18
+ task: TaskRepo;
19
+ transaction: TransactionRepo;
20
+ }
21
+ declare function processVoidTransaction4chevre(params: {
22
+ action: factory.action.authorize.offer.eventService.IAction<WebAPIIdentifier.Chevre>;
23
+ }): (repos: IVoidTransactionRepos) => Promise<void>;
24
+ export { processVoidTransaction4chevre };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.processVoidTransaction4chevre = exports.WebAPIIdentifier = void 0;
13
+ const factory = require("../../../../factory");
14
+ const reserve_1 = require("../../../assetTransaction/reserve");
15
+ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
16
+ function processVoidTransaction4chevre(params) {
17
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
18
+ var _a;
19
+ const transactionNumber = (_a = params.action.object.pendingTransaction) === null || _a === void 0 ? void 0 : _a.transactionNumber;
20
+ if (typeof transactionNumber === 'string') {
21
+ // 取引が存在すれば中止
22
+ const assetTransactions = yield repos.assetTransaction.search({
23
+ limit: 1,
24
+ page: 1,
25
+ project: { id: { $eq: params.action.project.id } },
26
+ typeOf: factory.assetTransactionType.Reserve,
27
+ transactionNumber: { $eq: transactionNumber }
28
+ }, ['_id']);
29
+ if (assetTransactions.length > 0) {
30
+ yield (0, reserve_1.cancel)({ transactionNumber })(repos);
31
+ }
32
+ }
33
+ });
34
+ }
35
+ exports.processVoidTransaction4chevre = processVoidTransaction4chevre;
@@ -0,0 +1,6 @@
1
+ import * as factory from '../../../../factory';
2
+ export import WebAPIIdentifier = factory.service.webAPI.Identifier;
3
+ declare function processVoidTransaction4coa(params: {
4
+ action: factory.action.authorize.offer.eventService.IAction<WebAPIIdentifier.COA>;
5
+ }): Promise<void>;
6
+ export { processVoidTransaction4coa };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.processVoidTransaction4coa = exports.WebAPIIdentifier = void 0;
13
+ const COA = require("@motionpicture/coa-service");
14
+ const http_status_1 = require("http-status");
15
+ const credentials_1 = require("../../../../credentials");
16
+ const factory = require("../../../../factory");
17
+ const coaAuthClient = new COA.auth.RefreshToken({
18
+ endpoint: credentials_1.credentials.coa.endpoint,
19
+ refreshToken: credentials_1.credentials.coa.refreshToken,
20
+ useFetch: credentials_1.credentials.coa.useFetch
21
+ });
22
+ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
23
+ function processVoidTransaction4coa(params) {
24
+ var _a, _b;
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ // COAの場合、objectあるいはresultに連携内容情報が記録されているので、その情報を元に仮予約を取り消す
27
+ let delTmpReserveParams;
28
+ // objectに進行中取引情報があれば利用する(2023-09-11~)
29
+ const pendingTransaction = params.action.object.pendingTransaction;
30
+ if (typeof (pendingTransaction === null || pendingTransaction === void 0 ? void 0 : pendingTransaction.typeOf) === 'string') {
31
+ delTmpReserveParams = {
32
+ theaterCode: pendingTransaction.theaterCode,
33
+ dateJouei: pendingTransaction.dateJouei,
34
+ titleCode: pendingTransaction.titleCode,
35
+ titleBranchNum: pendingTransaction.titleBranchNum,
36
+ timeBegin: pendingTransaction.timeBegin,
37
+ tmpReserveNum: pendingTransaction.tmpReserveNum
38
+ };
39
+ }
40
+ else {
41
+ const coaRequestBody = (_a = params.action.result) === null || _a === void 0 ? void 0 : _a.requestBody;
42
+ const coaResponseBody = (_b = params.action.result) === null || _b === void 0 ? void 0 : _b.responseBody;
43
+ if (coaRequestBody !== undefined && coaResponseBody !== undefined) {
44
+ delTmpReserveParams = {
45
+ theaterCode: coaRequestBody.theaterCode,
46
+ dateJouei: coaRequestBody.dateJouei,
47
+ titleCode: coaRequestBody.titleCode,
48
+ titleBranchNum: coaRequestBody.titleBranchNum,
49
+ timeBegin: coaRequestBody.timeBegin,
50
+ tmpReserveNum: coaResponseBody.tmpReserveNum
51
+ };
52
+ }
53
+ }
54
+ if (delTmpReserveParams !== undefined) {
55
+ // COAで仮予約取消
56
+ try {
57
+ const reserveService = new COA.service.Reserve({
58
+ endpoint: credentials_1.credentials.coa.endpoint,
59
+ auth: coaAuthClient
60
+ }, { timeout: credentials_1.credentials.coa.timeout });
61
+ yield reserveService.delTmpReserve(delTmpReserveParams);
62
+ }
63
+ catch (error) {
64
+ let deleted = false;
65
+ // COAサービスエラーの場合ハンドリング
66
+ // tslint:disable-next-line:no-single-line-block-comment
67
+ /* istanbul ignore if */
68
+ if (error.name === 'COAServiceError') {
69
+ if (typeof error.code === 'number' && error.code < http_status_1.INTERNAL_SERVER_ERROR) {
70
+ // すでに取消済の場合こうなるので、okとする
71
+ if (error.message === '座席取消失敗') {
72
+ deleted = true;
73
+ }
74
+ }
75
+ }
76
+ if (!deleted) {
77
+ throw error;
78
+ }
79
+ }
80
+ }
81
+ });
82
+ }
83
+ exports.processVoidTransaction4coa = processVoidTransaction4coa;
@@ -19,8 +19,15 @@ interface IVoidTransactionRepos {
19
19
  transaction: TransactionRepo;
20
20
  }
21
21
  /**
22
- * 興行オファー承認取消(タスクから実行)
23
- * 取引中の承認アクション全てについて処理する
22
+ * 興行オファー承認取消(タスクから実行 or apiから実行))
23
+ * 取引中の承認アクション全てについて処理する or 特定の承認アクションについて処理する
24
24
  */
25
- export declare function voidTransaction(params: factory.task.IData<factory.taskName.VoidReserveTransaction>): (repos: IVoidTransactionRepos) => Promise<void>;
25
+ export declare function voidTransaction(params: factory.task.IData<factory.taskName.VoidReserveTransaction> & {
26
+ sameAs?: {
27
+ /**
28
+ * 実行元タスクID
29
+ */
30
+ id: string;
31
+ };
32
+ }): (repos: IVoidTransactionRepos) => Promise<void>;
26
33
  export {};
@@ -10,25 +10,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.voidTransaction = exports.WebAPIIdentifier = void 0;
13
- const COA = require("@motionpicture/coa-service");
14
- const http_status_1 = require("http-status");
15
- const credentials_1 = require("../../../credentials");
16
13
  const factory = require("../../../factory");
17
- const ReserveTransactionService = require("../../assetTransaction/reserve");
18
14
  const any_1 = require("../any");
19
- const coaAuthClient = new COA.auth.RefreshToken({
20
- endpoint: credentials_1.credentials.coa.endpoint,
21
- refreshToken: credentials_1.credentials.coa.refreshToken,
22
- useFetch: credentials_1.credentials.coa.useFetch
23
- });
15
+ const processVoidTransaction4chevre_1 = require("./voidTransaction/processVoidTransaction4chevre");
16
+ const processVoidTransaction4coa_1 = require("./voidTransaction/processVoidTransaction4coa");
17
+ const voidTransactionByActionId_1 = require("./voidTransactionByActionId");
24
18
  exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
25
19
  /**
26
- * 興行オファー承認取消(タスクから実行)
27
- * 取引中の承認アクション全てについて処理する
20
+ * 興行オファー承認取消(タスクから実行 or apiから実行))
21
+ * 取引中の承認アクション全てについて処理する or 特定の承認アクションについて処理する
28
22
  */
29
23
  function voidTransaction(params) {
30
24
  return (repos) => __awaiter(this, void 0, void 0, function* () {
31
- var _a, _b;
25
+ var _a, _b, _c;
26
+ // support void by action ID(2024-05-26~)
27
+ if (typeof params.id === 'string') {
28
+ yield (0, voidTransactionByActionId_1.voidTransactionByActionId)(params)(repos);
29
+ return;
30
+ }
31
+ const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
32
32
  const transaction = yield repos.transaction.findById({
33
33
  typeOf: params.purpose.typeOf,
34
34
  id: params.purpose.id,
@@ -49,7 +49,7 @@ function voidTransaction(params) {
49
49
  // 確定取引に対応(2023-05-07~)
50
50
  case factory.transactionStatusType.Confirmed:
51
51
  // OrderCancelledを考慮(2023-08-30~)
52
- const orderCancelled = ((_b = (_a = params.purpose.result) === null || _a === void 0 ? void 0 : _a.order) === null || _b === void 0 ? void 0 : _b.orderStatus) === factory.orderStatus.OrderCancelled;
52
+ const orderCancelled = ((_c = (_b = params.purpose.result) === null || _b === void 0 ? void 0 : _b.order) === null || _c === void 0 ? void 0 : _c.orderStatus) === factory.orderStatus.OrderCancelled;
53
53
  if (!orderCancelled) {
54
54
  // 取り消すべきアクションに絞る
55
55
  authorizeActions = authorizeActions.filter((a) => a.actionStatus !== factory.actionStatusType.CompletedActionStatus);
@@ -77,98 +77,19 @@ function voidTransaction(params) {
77
77
  }
78
78
  }
79
79
  yield Promise.all(authorizeActions.map((action) => __awaiter(this, void 0, void 0, function* () {
80
- yield repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id });
80
+ yield repos.action.cancelWithVoid({ typeOf: action.typeOf, id: action.id, cancelAction });
81
81
  switch (action.instrument.identifier) {
82
82
  case exports.WebAPIIdentifier.COA:
83
- yield processVoidTransaction4coa({
83
+ yield (0, processVoidTransaction4coa_1.processVoidTransaction4coa)({
84
84
  action: action
85
85
  });
86
86
  break;
87
87
  default:
88
- yield processVoidTransaction4chevre({
89
- action: action,
90
- project: params.project
88
+ yield (0, processVoidTransaction4chevre_1.processVoidTransaction4chevre)({
89
+ action: action
91
90
  })(repos);
92
91
  }
93
92
  })));
94
93
  });
95
94
  }
96
95
  exports.voidTransaction = voidTransaction;
97
- function processVoidTransaction4coa(params) {
98
- var _a, _b;
99
- return __awaiter(this, void 0, void 0, function* () {
100
- // COAの場合、objectあるいはresultに連携内容情報が記録されているので、その情報を元に仮予約を取り消す
101
- let delTmpReserveParams;
102
- // objectに進行中取引情報があれば利用する(2023-09-11~)
103
- const pendingTransaction = params.action.object.pendingTransaction;
104
- if (typeof (pendingTransaction === null || pendingTransaction === void 0 ? void 0 : pendingTransaction.typeOf) === 'string') {
105
- delTmpReserveParams = {
106
- theaterCode: pendingTransaction.theaterCode,
107
- dateJouei: pendingTransaction.dateJouei,
108
- titleCode: pendingTransaction.titleCode,
109
- titleBranchNum: pendingTransaction.titleBranchNum,
110
- timeBegin: pendingTransaction.timeBegin,
111
- tmpReserveNum: pendingTransaction.tmpReserveNum
112
- };
113
- }
114
- else {
115
- const coaRequestBody = (_a = params.action.result) === null || _a === void 0 ? void 0 : _a.requestBody;
116
- const coaResponseBody = (_b = params.action.result) === null || _b === void 0 ? void 0 : _b.responseBody;
117
- if (coaRequestBody !== undefined && coaResponseBody !== undefined) {
118
- delTmpReserveParams = {
119
- theaterCode: coaRequestBody.theaterCode,
120
- dateJouei: coaRequestBody.dateJouei,
121
- titleCode: coaRequestBody.titleCode,
122
- titleBranchNum: coaRequestBody.titleBranchNum,
123
- timeBegin: coaRequestBody.timeBegin,
124
- tmpReserveNum: coaResponseBody.tmpReserveNum
125
- };
126
- }
127
- }
128
- if (delTmpReserveParams !== undefined) {
129
- // COAで仮予約取消
130
- try {
131
- const reserveService = new COA.service.Reserve({
132
- endpoint: credentials_1.credentials.coa.endpoint,
133
- auth: coaAuthClient
134
- }, { timeout: credentials_1.credentials.coa.timeout });
135
- yield reserveService.delTmpReserve(delTmpReserveParams);
136
- }
137
- catch (error) {
138
- let deleted = false;
139
- // COAサービスエラーの場合ハンドリング
140
- // tslint:disable-next-line:no-single-line-block-comment
141
- /* istanbul ignore if */
142
- if (error.name === 'COAServiceError') {
143
- if (typeof error.code === 'number' && error.code < http_status_1.INTERNAL_SERVER_ERROR) {
144
- // すでに取消済の場合こうなるので、okとする
145
- if (error.message === '座席取消失敗') {
146
- deleted = true;
147
- }
148
- }
149
- }
150
- if (!deleted) {
151
- throw error;
152
- }
153
- }
154
- }
155
- });
156
- }
157
- function processVoidTransaction4chevre(params) {
158
- return (repos) => __awaiter(this, void 0, void 0, function* () {
159
- var _a;
160
- const transactionNumber = (_a = params.action.object.pendingTransaction) === null || _a === void 0 ? void 0 : _a.transactionNumber;
161
- if (typeof transactionNumber === 'string') {
162
- // 取引が存在すれば中止
163
- const assetTransactions = yield repos.assetTransaction.search({
164
- limit: 1,
165
- project: { id: { $eq: params.project.id } },
166
- typeOf: factory.assetTransactionType.Reserve,
167
- transactionNumber: { $eq: transactionNumber }
168
- });
169
- if (assetTransactions.length > 0) {
170
- yield ReserveTransactionService.cancel({ transactionNumber })(repos);
171
- }
172
- }
173
- });
174
- }
@@ -7,7 +7,7 @@ import type { MongoRepository as ReservationRepo } from '../../../repo/reservati
7
7
  import type { StockHolderRepository as StockHolderRepo } from '../../../repo/stockHolder';
8
8
  import type { MongoRepository as TaskRepo } from '../../../repo/task';
9
9
  import type { MongoRepository as TransactionRepo } from '../../../repo/transaction';
10
- interface ICancelRepos {
10
+ interface IVoidTransactionByActionIdRepos {
11
11
  action: ActionRepo;
12
12
  assetTransaction: AssetTransactionRepo;
13
13
  stockHolder: StockHolderRepo;
@@ -21,26 +21,12 @@ interface ICancelRepos {
21
21
  * 興行オファー承認取消(apiから実行)
22
22
  * 特定の承認アクションについて処理する
23
23
  */
24
- export declare function cancel(params: {
25
- project: {
24
+ declare function voidTransactionByActionId(params: factory.task.IData<factory.taskName.VoidReserveTransaction> & {
25
+ sameAs?: {
26
+ /**
27
+ * 実行元タスクID
28
+ */
26
29
  id: string;
27
- typeOf: factory.organizationType.Project;
28
30
  };
29
- /**
30
- * 承認アクションID
31
- */
32
- id: string;
33
- /**
34
- * 取引進行者
35
- */
36
- agent: {
37
- id: string;
38
- };
39
- /**
40
- * 取引
41
- */
42
- transaction: {
43
- id: string;
44
- };
45
- }): (repos: ICancelRepos) => Promise<void>;
46
- export {};
31
+ }): (repos: IVoidTransactionByActionIdRepos) => Promise<void>;
32
+ export { voidTransactionByActionId };
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.voidTransactionByActionId = void 0;
13
+ const factory = require("../../../factory");
14
+ const any_1 = require("../any");
15
+ const processVoidTransaction4chevre_1 = require("./voidTransaction/processVoidTransaction4chevre");
16
+ const processVoidTransaction4coa_1 = require("./voidTransaction/processVoidTransaction4coa");
17
+ /**
18
+ * 興行オファー承認取消(apiから実行)
19
+ * 特定の承認アクションについて処理する
20
+ */
21
+ function voidTransactionByActionId(params) {
22
+ // export function cancel(params: {
23
+ // project: { id: string; typeOf: factory.organizationType.Project };
24
+ // /**
25
+ // * 承認アクションID
26
+ // */
27
+ // id: string;
28
+ // /**
29
+ // * 取引進行者
30
+ // */
31
+ // agent: { id: string };
32
+ // /**
33
+ // * 取引
34
+ // */
35
+ // transaction: { id: string };
36
+ // }) {
37
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
38
+ var _a;
39
+ if (typeof params.id !== 'string' || params.id === '') {
40
+ throw new factory.errors.ArgumentNull('id');
41
+ }
42
+ const cancelAction = Object.assign({ startTime: new Date(), agent: { id: params.project.id, typeOf: factory.organizationType.Project } }, (typeof ((_a = params.sameAs) === null || _a === void 0 ? void 0 : _a.id) === 'string') ? { sameAs: { id: params.sameAs.id, typeOf: 'Task' } } : undefined);
43
+ const transaction = yield repos.transaction.findInProgressById({
44
+ typeOf: factory.transactionType.PlaceOrder,
45
+ id: params.purpose.id
46
+ });
47
+ // if (transaction.agent.id !== params.agent.id) {
48
+ // throw new factory.errors.Forbidden('Transaction not yours');
49
+ // }
50
+ const action = yield repos.action.findById({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
51
+ if (action.purpose.typeOf !== transaction.typeOf || action.purpose.id !== transaction.id) {
52
+ throw new factory.errors.Argument('Transaction', 'Action not found in the transaction');
53
+ }
54
+ // MongoDBでcompleteステータスであるにも関わらず、Chevreでは削除されている、というのが最悪の状況
55
+ // それだけは回避するためにMongoDBを先に変更
56
+ yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id, cancelAction });
57
+ // add orderInTransaction(2024-01-15~)
58
+ // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
59
+ const orderNumberByTransaction = transaction.object.orderNumber;
60
+ if (typeof orderNumberByTransaction === 'string') {
61
+ yield (0, any_1.voidAcceptedOffer)({
62
+ // authorizeActions: [action],
63
+ authorizeActionsWithInstrument: [action],
64
+ orderNumber: orderNumberByTransaction
65
+ })(repos);
66
+ }
67
+ switch (action.instrument.identifier) {
68
+ case factory.service.webAPI.Identifier.COA:
69
+ yield (0, processVoidTransaction4coa_1.processVoidTransaction4coa)({
70
+ action: action
71
+ });
72
+ break;
73
+ default:
74
+ yield (0, processVoidTransaction4chevre_1.processVoidTransaction4chevre)({
75
+ action: action
76
+ })(repos);
77
+ // const transactionNumber = action.object.pendingTransaction?.transactionNumber;
78
+ // if (typeof transactionNumber === 'string') {
79
+ // // すでに取消済であったとしても、すべて取消処理(actionStatusに関係なく)
80
+ // await ReserveTransactionService.cancel({ transactionNumber })(repos);
81
+ // }
82
+ }
83
+ });
84
+ }
85
+ exports.voidTransactionByActionId = voidTransactionByActionId;
@@ -1,6 +1,5 @@
1
1
  import { authorize } from './event/authorize';
2
- import { cancel } from './event/cancel';
3
2
  import { importCategoryCodesFromCOA, importFromCOA } from './event/importFromCOA';
4
3
  import { searchEventTicketOffers, searchOfferAppliesToMovieTicket, searchOfferCatalogItemAvailability, searchOfferCatalogItems } from './event/searchEventTicketOffers';
5
4
  import { voidTransaction } from './event/voidTransaction';
6
- export { authorize, cancel, importCategoryCodesFromCOA, importFromCOA, voidTransaction, searchEventTicketOffers, searchOfferAppliesToMovieTicket, searchOfferCatalogItemAvailability, searchOfferCatalogItems };
5
+ export { authorize, importCategoryCodesFromCOA, importFromCOA, voidTransaction, searchEventTicketOffers, searchOfferAppliesToMovieTicket, searchOfferCatalogItemAvailability, searchOfferCatalogItems };
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.searchOfferCatalogItems = exports.searchOfferCatalogItemAvailability = exports.searchOfferAppliesToMovieTicket = exports.searchEventTicketOffers = exports.voidTransaction = exports.importFromCOA = exports.importCategoryCodesFromCOA = exports.cancel = exports.authorize = void 0;
3
+ exports.searchOfferCatalogItems = exports.searchOfferCatalogItemAvailability = exports.searchOfferAppliesToMovieTicket = exports.searchEventTicketOffers = exports.voidTransaction = exports.importFromCOA = exports.importCategoryCodesFromCOA = exports.authorize = void 0;
4
4
  const authorize_1 = require("./event/authorize");
5
5
  Object.defineProperty(exports, "authorize", { enumerable: true, get: function () { return authorize_1.authorize; } });
6
- const cancel_1 = require("./event/cancel");
7
- Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return cancel_1.cancel; } });
6
+ // import { cancel } from './event/cancel';
8
7
  const importFromCOA_1 = require("./event/importFromCOA");
9
8
  Object.defineProperty(exports, "importCategoryCodesFromCOA", { enumerable: true, get: function () { return importFromCOA_1.importCategoryCodesFromCOA; } });
10
9
  Object.defineProperty(exports, "importFromCOA", { enumerable: true, get: function () { return importFromCOA_1.importFromCOA; } });
@@ -15,6 +15,9 @@ interface ICancelResult {
15
15
  * COA興行オファー承認取消
16
16
  */
17
17
  export declare function cancel(params: {
18
+ project: {
19
+ id: string;
20
+ };
18
21
  /**
19
22
  * 承認アクションID
20
23
  */
@@ -18,6 +18,10 @@ exports.WebAPIIdentifier = factory.service.webAPI.Identifier;
18
18
  */
19
19
  function cancel(params) {
20
20
  return (repos) => __awaiter(this, void 0, void 0, function* () {
21
+ const cancelAction = {
22
+ startTime: new Date(),
23
+ agent: { id: params.project.id, typeOf: factory.organizationType.Project }
24
+ };
21
25
  const transaction = yield repos.transaction.findInProgressById({
22
26
  typeOf: factory.transactionType.PlaceOrder,
23
27
  id: params.transaction.id
@@ -30,7 +34,7 @@ function cancel(params) {
30
34
  if (action.purpose.typeOf !== transaction.typeOf || action.purpose.id !== transaction.id) {
31
35
  throw new factory.errors.Argument('Transaction', 'Action not found in the transaction');
32
36
  }
33
- yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
37
+ yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id, cancelAction });
34
38
  // add orderInTransaction(2024-01-15~)
35
39
  // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
36
40
  const orderNumberByTransaction = transaction.object.orderNumber;
@@ -1,6 +1,6 @@
1
- import type { IOperationExecute } from '../task';
1
+ import type { IExecutableTaskKeys, IOperationExecute } from '../task';
2
2
  import * as factory from '../../factory';
3
3
  /**
4
4
  * タスク実行関数
5
5
  */
6
- export declare function call(data: factory.task.IData<factory.taskName.VoidReserveTransaction>): IOperationExecute<void>;
6
+ export declare function call(params: Pick<factory.task.ITask<factory.taskName.VoidReserveTransaction>, IExecutableTaskKeys>): IOperationExecute<void>;
@@ -19,25 +19,46 @@ const reservation_1 = require("../../repo/reservation");
19
19
  const stockHolder_1 = require("../../repo/stockHolder");
20
20
  const task_1 = require("../../repo/task");
21
21
  const transaction_1 = require("../../repo/transaction");
22
- const EventOfferService = require("../offer/event");
22
+ const transactionProcess_1 = require("../../repo/transactionProcess");
23
+ const event_1 = require("../offer/event");
23
24
  /**
24
25
  * タスク実行関数
25
26
  */
26
- function call(data) {
27
- return (settings) => __awaiter(this, void 0, void 0, function* () {
27
+ function call(params) {
28
+ // export function call(data: factory.task.IData<factory.taskName.VoidReserveTransaction>): IOperationExecute<void> {
29
+ return (settings, options) => __awaiter(this, void 0, void 0, function* () {
28
30
  if (settings.redisClient === undefined) {
29
31
  throw new factory.errors.Argument('settings', 'redisClient required');
30
32
  }
31
- yield EventOfferService.voidTransaction(data)({
32
- action: new action_1.MongoRepository(settings.connection),
33
- assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
34
- stockHolder: new stockHolder_1.StockHolderRepository(settings.redisClient, settings.connection),
35
- offerRateLimit: new offer_1.RedisRepository(settings.redisClient),
36
- orderInTransaction: new orderInTransaction_1.MongoRepository(settings.connection),
37
- reservation: new reservation_1.MongoRepository(settings.connection),
38
- task: new task_1.MongoRepository(settings.connection),
39
- transaction: new transaction_1.MongoRepository(settings.connection)
40
- });
33
+ const voidByActionId = typeof params.data.id === 'string';
34
+ if (voidByActionId) {
35
+ // 遅延実行(executeByName)には対応しない
36
+ if (!options.executeById) {
37
+ return;
38
+ }
39
+ }
40
+ const transactionProcessRepo = new transactionProcess_1.TransactionProcessRepository(settings.redisClient, { lockExpiresInSeconds: 120 });
41
+ try {
42
+ yield (0, event_1.voidTransaction)(Object.assign(Object.assign({}, params.data), { sameAs: { id: params.id } }))({
43
+ action: new action_1.MongoRepository(settings.connection),
44
+ assetTransaction: new assetTransaction_1.MongoRepository(settings.connection),
45
+ stockHolder: new stockHolder_1.StockHolderRepository(settings.redisClient, settings.connection),
46
+ offerRateLimit: new offer_1.RedisRepository(settings.redisClient),
47
+ orderInTransaction: new orderInTransaction_1.MongoRepository(settings.connection),
48
+ reservation: new reservation_1.MongoRepository(settings.connection),
49
+ task: new task_1.MongoRepository(settings.connection),
50
+ transaction: new transaction_1.MongoRepository(settings.connection)
51
+ });
52
+ }
53
+ catch (error) {
54
+ throw error;
55
+ }
56
+ finally {
57
+ // アクションID指定であれば取引プロセスロック解除(2024-05-26~)
58
+ if (voidByActionId) {
59
+ yield transactionProcessRepo.unlock({ typeOf: params.data.purpose.typeOf, id: params.data.purpose.id });
60
+ }
61
+ }
41
62
  });
42
63
  }
43
64
  exports.call = call;
@@ -109,6 +109,7 @@ function execute(task) {
109
109
  case factory.taskName.CheckMovieTicket:
110
110
  case factory.taskName.PublishPaymentUrl:
111
111
  case factory.taskName.Refund:
112
+ case factory.taskName.VoidReserveTransaction:
112
113
  yield call(task)(settings, options);
113
114
  break;
114
115
  default:
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.32.0-alpha.15"
113
+ "version": "21.32.0-alpha.17"
114
114
  }
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.cancel = void 0;
13
- const factory = require("../../../factory");
14
- const ReserveTransactionService = require("../../assetTransaction/reserve");
15
- const any_1 = require("../any");
16
- /**
17
- * 興行オファー承認取消(apiから実行)
18
- * 特定の承認アクションについて処理する
19
- */
20
- function cancel(params) {
21
- return (repos) => __awaiter(this, void 0, void 0, function* () {
22
- var _a;
23
- const transaction = yield repos.transaction.findInProgressById({
24
- typeOf: factory.transactionType.PlaceOrder,
25
- id: params.transaction.id
26
- });
27
- if (transaction.agent.id !== params.agent.id) {
28
- throw new factory.errors.Forbidden('Transaction not yours');
29
- }
30
- // MongoDBでcompleteステータスであるにも関わらず、Chevreでは削除されている、というのが最悪の状況
31
- // それだけは回避するためにMongoDBを先に変更
32
- yield repos.action.cancelWithVoid({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
33
- const action = yield repos.action.findById({ typeOf: factory.actionType.AuthorizeAction, id: params.id });
34
- switch (action.instrument.identifier) {
35
- case factory.service.webAPI.Identifier.COA:
36
- // 実質使用する予定なしなので廃止(2022-05-12~)
37
- throw new factory.errors.NotImplemented(`booking service '${action.instrument.identifier}' not implemented`);
38
- default:
39
- // add orderInTransaction(2024-01-15~)
40
- // USE_CREATE_ORDER_ON_OFFER_ACCEPTEDの場合、orderNumber発行済のはず
41
- const orderNumberByTransaction = transaction.object.orderNumber;
42
- if (typeof orderNumberByTransaction === 'string') {
43
- yield (0, any_1.voidAcceptedOffer)({
44
- // authorizeActions: [action],
45
- authorizeActionsWithInstrument: [action],
46
- orderNumber: orderNumberByTransaction
47
- })(repos);
48
- }
49
- const transactionNumber = (_a = action.object.pendingTransaction) === null || _a === void 0 ? void 0 : _a.transactionNumber;
50
- if (typeof transactionNumber === 'string') {
51
- // すでに取消済であったとしても、すべて取消処理(actionStatusに関係なく)
52
- yield ReserveTransactionService.cancel({ transactionNumber })(repos);
53
- }
54
- }
55
- });
56
- }
57
- exports.cancel = cancel;