@chevre/domain 25.2.0-alpha.10 → 25.2.0-alpha.12

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.
@@ -214,19 +214,19 @@ const indexes = [
214
214
  alternateName: { $exists: true }
215
215
  }
216
216
  }
217
+ ],
218
+ // add unique index(dev)(2025-03-28~)
219
+ // add unique index(test,prod)(2026-07-08~)
220
+ [
221
+ { identifier: 1 },
222
+ {
223
+ unique: true,
224
+ name: 'uniqueIdentifier',
225
+ partialFilterExpression: {
226
+ identifier: { $exists: true }
227
+ }
228
+ }
217
229
  ]
218
- // eslint-disable-next-line no-warning-comments
219
- // TODO add unique index(2025-03-28~)
220
- // [
221
- // { identifier: 1 },
222
- // {
223
- // unique: true,
224
- // name: 'uniqueIdentifier',
225
- // partialFilterExpression: {
226
- // identifier: { $exists: true }
227
- // }
228
- // }
229
- // ]
230
230
  ];
231
231
  exports.indexes = indexes;
232
232
  /**
@@ -11,6 +11,7 @@ export type IOrderInTransaction = Pick<factory.order.IOrder, 'orderNumber' | 'pr
11
11
  acceptedOffers: factory.order.IAcceptedOffer[];
12
12
  customer?: factory.order.ICustomer;
13
13
  seller?: factory.order.ISeller;
14
+ confirmationNumber?: string;
14
15
  };
15
16
  /**
16
17
  * typeOf: Orderへドキュメント変換時の編集フィールド
@@ -127,6 +128,25 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
127
128
  setCustomerByIdentifier(params: Pick<IOrderInTransaction, 'project' | 'identifier'> & {
128
129
  customer: factory.order.ICustomer;
129
130
  }): Promise<import("mongoose").UpdateWriteOpResult>;
131
+ /**
132
+ * 確認番号を参照する
133
+ */
134
+ findConfirmationNumberByIdentifier(params: {
135
+ identifier: string;
136
+ }): Promise<string | undefined>;
137
+ /**
138
+ * 注文ドキュメントに確認番号を保管する
139
+ * 確認番号未発行の場合のみ保管される
140
+ */
141
+ saveConfirmationNumberIfNotExist(params: {
142
+ identifier: string;
143
+ confirmationNumber: string;
144
+ }, options: {
145
+ /**
146
+ * 注文取引タイプのドキュメントのみを参照対象にするかどうか
147
+ */
148
+ onlyPlaceOrder: boolean;
149
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
130
150
  deleteByIdentifier(params: {
131
151
  identifier: string;
132
152
  }): Promise<import("mongodb").DeleteResult>;
@@ -241,6 +241,39 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
241
241
  }
242
242
  return result;
243
243
  }
244
+ /**
245
+ * 確認番号を参照する
246
+ */
247
+ async findConfirmationNumberByIdentifier(params) {
248
+ const { identifier } = params;
249
+ const doc = await this.orderModel.findOne({
250
+ identifier: { $eq: identifier },
251
+ typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
252
+ }, { confirmationNumber: 1 })
253
+ .lean()
254
+ .exec();
255
+ if (doc === null) {
256
+ throw new factory_1.factory.errors.NotFound('orderInTransaction');
257
+ }
258
+ return doc.confirmationNumber;
259
+ }
260
+ /**
261
+ * 注文ドキュメントに確認番号を保管する
262
+ * 確認番号未発行の場合のみ保管される
263
+ */
264
+ async saveConfirmationNumberIfNotExist(params, options) {
265
+ const { identifier, confirmationNumber } = params;
266
+ const onlyPlaceOrder = options.onlyPlaceOrder === true;
267
+ if (typeof confirmationNumber !== 'string' || confirmationNumber === '') {
268
+ throw new factory_1.factory.errors.ArgumentNull('confirmationNumber');
269
+ }
270
+ return this.orderModel.updateOne({
271
+ identifier: { $eq: identifier },
272
+ confirmationNumber: { $exists: false },
273
+ ...((onlyPlaceOrder) && { typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder } })
274
+ }, { $set: { confirmationNumber } })
275
+ .exec();
276
+ }
244
277
  async deleteByIdentifier(params) {
245
278
  return this.orderModel.deleteOne({
246
279
  typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
@@ -43,15 +43,6 @@ export declare class PlaceOrderRepo {
43
43
  findInProgressPaymentMethodId(params: {
44
44
  id: string;
45
45
  }): Promise<factory.transaction.placeOrder.IPaymentMethodByPaymentUrl | undefined>;
46
- /**
47
- * 取引の確認番号を検索する
48
- */
49
- findInProgressConfirmationNumberById(params: {
50
- id: string;
51
- status: {
52
- $in: factory.transactionStatusType[];
53
- };
54
- }): Promise<string | undefined>;
55
46
  /**
56
47
  * 取引期限変更
57
48
  */
@@ -60,17 +51,6 @@ export declare class PlaceOrderRepo {
60
51
  id: string;
61
52
  expires: Date;
62
53
  }): Promise<void>;
63
- /**
64
- * 取引オブジェクトを更新
65
- * 注文名称など
66
- */
67
- updateObject(params: {
68
- typeOf: factory.transactionType.PlaceOrder;
69
- id: string;
70
- object?: {
71
- name?: string;
72
- };
73
- }): Promise<void>;
74
54
  /**
75
55
  * 特定の進行中取引を更新する(汎用)
76
56
  */
@@ -91,13 +71,6 @@ export declare class PlaceOrderRepo {
91
71
  }): Promise<{
92
72
  modifiedCount: number;
93
73
  }>;
94
- saveConfirmationNumberIfNotExist(params: {
95
- id: string;
96
- status: {
97
- $in: factory.transactionStatusType[];
98
- };
99
- confirmationNumber: string;
100
- }): Promise<void>;
101
74
  /**
102
75
  * 進行中の注文取引を取得する
103
76
  */
@@ -125,6 +98,7 @@ export declare class PlaceOrderRepo {
125
98
  object: {
126
99
  orderDate: Date;
127
100
  orderNumber: string;
101
+ confirmationNumber: string;
128
102
  };
129
103
  result: factory.transaction.IResult<factory.transactionType.PlaceOrder>;
130
104
  potentialActions: factory.transaction.IPotentialActions<factory.transactionType.PlaceOrder>;
@@ -226,22 +226,31 @@ class PlaceOrderRepo {
226
226
  // }
227
227
  // return doc.object.orderNumber;
228
228
  // }
229
- /**
230
- * 取引の確認番号を検索する
231
- */
232
- async findInProgressConfirmationNumberById(params) {
233
- const doc = await this.transactionModel.findOne({
234
- _id: { $eq: params.id },
235
- typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
236
- status: { $in: params.status.$in }
237
- }, { 'object.confirmationNumber': 1 })
238
- .lean() // 2024-08-26~
239
- .exec();
240
- if (doc === null) {
241
- throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${factory_1.factory.transactionType.PlaceOrder} ${params.status.$in.join(' or ')} not found`);
242
- }
243
- return doc.object.confirmationNumber;
244
- }
229
+ // /**
230
+ // * 取引の確認番号を検索する
231
+ // */
232
+ // public async findInProgressConfirmationNumberById(params: {
233
+ // id: string;
234
+ // status: { $in: factory.transactionStatusType[] };
235
+ // }): Promise<string | undefined> {
236
+ // const doc = await this.transactionModel.findOne(
237
+ // {
238
+ // _id: { $eq: params.id },
239
+ // typeOf: { $eq: factory.transactionType.PlaceOrder },
240
+ // status: { $in: params.status.$in }
241
+ // },
242
+ // { 'object.confirmationNumber': 1 }
243
+ // )
244
+ // .lean<{ object: Pick<factory.transaction.placeOrder.IObject, 'confirmationNumber'> }>() // 2024-08-26~
245
+ // .exec();
246
+ // if (doc === null) {
247
+ // throw new factory.errors.NotFound(
248
+ // this.transactionModel.modelName,
249
+ // `${factory.transactionType.PlaceOrder} ${params.status.$in.join(' or ')} not found`
250
+ // );
251
+ // }
252
+ // return doc.object.confirmationNumber;
253
+ // }
245
254
  /**
246
255
  * 取引期限変更
247
256
  */
@@ -263,28 +272,41 @@ class PlaceOrderRepo {
263
272
  throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory_1.factory.transactionStatusType.InProgress} not found`);
264
273
  }
265
274
  }
266
- /**
267
- * 取引オブジェクトを更新
268
- * 注文名称など
269
- */
270
- async updateObject(params) {
271
- const doc = await this.transactionModel.findOneAndUpdate({
272
- _id: { $eq: params.id },
273
- typeOf: { $eq: params.typeOf },
274
- status: { $eq: factory_1.factory.transactionStatusType.InProgress }
275
- }, {
276
- $set: {
277
- ...(typeof params.object?.name === 'string') ? { 'object.name': params.object.name } : undefined
278
- }
279
- }, {
280
- projection: { _id: 1 }
281
- })
282
- .lean()
283
- .exec();
284
- if (doc === null) {
285
- throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory_1.factory.transactionStatusType.InProgress} not found`);
286
- }
287
- }
275
+ // /**
276
+ // * 取引オブジェクトを更新
277
+ // * 注文名称など
278
+ // */
279
+ // public async updateObject(params: {
280
+ // typeOf: factory.transactionType.PlaceOrder;
281
+ // id: string;
282
+ // object?: {
283
+ // name?: string;
284
+ // };
285
+ // }): Promise<void> {
286
+ // const doc = await this.transactionModel.findOneAndUpdate(
287
+ // {
288
+ // _id: { $eq: params.id },
289
+ // typeOf: { $eq: params.typeOf },
290
+ // status: { $eq: factory.transactionStatusType.InProgress }
291
+ // },
292
+ // {
293
+ // $set: {
294
+ // ...(typeof params.object?.name === 'string') ? { 'object.name': params.object.name } : undefined
295
+ // }
296
+ // },
297
+ // {
298
+ // projection: { _id: 1 }
299
+ // }
300
+ // )
301
+ // .lean<{ _id: ObjectId }>()
302
+ // .exec();
303
+ // if (doc === null) {
304
+ // throw new factory.errors.NotFound(
305
+ // this.transactionModel.modelName,
306
+ // `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`
307
+ // );
308
+ // }
309
+ // }
288
310
  /**
289
311
  * 特定の進行中取引を更新する(汎用)
290
312
  */
@@ -316,15 +338,22 @@ class PlaceOrderRepo {
316
338
  .exec();
317
339
  return { modifiedCount: result.modifiedCount };
318
340
  }
319
- async saveConfirmationNumberIfNotExist(params) {
320
- await this.transactionModel.updateOne({
321
- _id: { $eq: params.id },
322
- // status: { $eq: factory.transactionStatusType.InProgress },
323
- status: { $in: params.status.$in },
324
- 'object.confirmationNumber': { $exists: false }
325
- }, { $set: { 'object.confirmationNumber': params.confirmationNumber } })
326
- .exec();
327
- }
341
+ // public async saveConfirmationNumberIfNotExist(params: {
342
+ // id: string;
343
+ // status: { $in: factory.transactionStatusType[] };
344
+ // confirmationNumber: string;
345
+ // }): Promise<void> {
346
+ // await this.transactionModel.updateOne(
347
+ // {
348
+ // _id: { $eq: params.id },
349
+ // // status: { $eq: factory.transactionStatusType.InProgress },
350
+ // status: { $in: params.status.$in },
351
+ // 'object.confirmationNumber': { $exists: false }
352
+ // },
353
+ // { $set: { 'object.confirmationNumber': params.confirmationNumber } }
354
+ // )
355
+ // .exec();
356
+ // }
328
357
  /**
329
358
  * 進行中の注文取引を取得する
330
359
  */
@@ -441,6 +470,7 @@ class PlaceOrderRepo {
441
470
  endDate,
442
471
  'object.orderDate': params.object.orderDate, // add(2026-06-15~)
443
472
  'object.orderNumber': params.object.orderNumber, // add(2026-06-27~)
473
+ 'object.confirmationNumber': params.object.confirmationNumber, // add(2026-07-08~)
444
474
  result: params.result, // resultを更新
445
475
  potentialActions: params.potentialActions // resultを更新
446
476
  }, {
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fixOrderAsNeeded = fixOrderAsNeeded;
4
- const factory_1 = require("../../../../factory");
5
4
  const publishConfirmationNumberIfNotExist_1 = require("../../../transaction/placeOrder/publishConfirmationNumberIfNotExist");
6
5
  function fixOrderAsNeeded(params) {
7
6
  return async (repos) => {
@@ -12,7 +11,7 @@ function fixOrderAsNeeded(params) {
12
11
  // if (params.paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket) {
13
12
  const confirmationNumber = await (0, publishConfirmationNumberIfNotExist_1.publishConfirmationNumberIfNotExist)({
14
13
  id: params.purpose.id,
15
- status: { $in: [factory_1.factory.transactionStatusType.InProgress] },
14
+ // status: { $in: [factory.transactionStatusType.InProgress] },
16
15
  object: { orderDate }
17
16
  })(repos);
18
17
  // }
@@ -0,0 +1,15 @@
1
+ import { factory } from '../../../factory';
2
+ import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
3
+ type IAuthorizeOfferAction = factory.action.authorize.offer.eventService.IAction;
4
+ type IAuthorizePaymentAction = factory.action.authorize.paymentMethod.any.IAction;
5
+ export declare function deletePayTransactionsByPlaceOrder(params: {
6
+ authorizeActions: (IAuthorizeOfferAction | IAuthorizePaymentAction)[];
7
+ transaction: Pick<factory.transaction.placeOrder.ITransaction, 'project'>;
8
+ }): (repos: {
9
+ assetTransaction: AssetTransactionRepo;
10
+ }) => Promise<{
11
+ deletePayTransactionResult: any;
12
+ deleteRefundResult: any;
13
+ payTransactionNumbers: string[];
14
+ }>;
15
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deletePayTransactionsByPlaceOrder = deletePayTransactionsByPlaceOrder;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const factory_1 = require("../../../factory");
6
+ function deletePayTransactionsByPlaceOrder(params) {
7
+ return async (repos) => {
8
+ let deletePayTransactionResult;
9
+ let deleteRefundResult;
10
+ const authorizeActions = params.authorizeActions;
11
+ // 決済取引番号を抽出
12
+ const authorizePaymentActions = authorizeActions
13
+ .filter((a) => {
14
+ return a.object.typeOf === factory_1.factory.action.authorize.paymentMethod.any.ResultType.Payment
15
+ && typeof a.object?.paymentMethodId === 'string'
16
+ && a.object.paymentMethodId.length > 0;
17
+ });
18
+ const payTransactionNumbers = authorizePaymentActions.map((a) => String(a.object.paymentMethodId));
19
+ if (payTransactionNumbers.length > 0) {
20
+ // 決済取引を削除(プロジェクトでも絞ること)(2022-06-07~)
21
+ const deleteAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
22
+ project: { id: params.transaction.project.id },
23
+ transactionNumbers: payTransactionNumbers,
24
+ typeOf: factory_1.factory.assetTransactionType.Pay
25
+ });
26
+ deletePayTransactionResult = {
27
+ n: deleteAssetTransactionsResult?.n,
28
+ ok: deleteAssetTransactionsResult?.ok,
29
+ deletedCount: deleteAssetTransactionsResult?.deletedCount
30
+ };
31
+ // 返金取引も削除(2023-05-19~)
32
+ const refundTransactions = await repos.assetTransaction.search({
33
+ typeOf: factory_1.factory.assetTransactionType.Refund,
34
+ object: { paymentMethodId: { $in: payTransactionNumbers } }
35
+ }, ['transactionNumber'], []);
36
+ if (refundTransactions.length > 0) {
37
+ const deleteRefundAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
38
+ project: { id: params.transaction.project.id },
39
+ transactionNumbers: refundTransactions.map(({ transactionNumber }) => transactionNumber),
40
+ typeOf: factory_1.factory.assetTransactionType.Refund
41
+ });
42
+ deleteRefundResult = {
43
+ n: deleteRefundAssetTransactionsResult?.n,
44
+ ok: deleteRefundAssetTransactionsResult?.ok,
45
+ deletedCount: deleteRefundAssetTransactionsResult?.deletedCount
46
+ };
47
+ }
48
+ }
49
+ return { deletePayTransactionResult, deleteRefundResult, payTransactionNumbers };
50
+ };
51
+ }
@@ -0,0 +1,23 @@
1
+ import { factory } from '../../../factory';
2
+ import type { AssetTransactionRepo } from '../../../repo/assetTransaction';
3
+ import type { ReservationRepo } from '../../../repo/reservation';
4
+ type IAuthorizeOfferAction = factory.action.authorize.offer.eventService.IAction;
5
+ type IAuthorizePaymentAction = factory.action.authorize.paymentMethod.any.IAction;
6
+ interface IDeleteResult {
7
+ n?: number;
8
+ ok?: number;
9
+ deletedCount?: number;
10
+ }
11
+ export declare function deleteReservationsByPlaceOrder(params: {
12
+ authorizeActions: (IAuthorizeOfferAction | IAuthorizePaymentAction)[];
13
+ transaction: Pick<factory.transaction.placeOrder.ITransaction, 'project'>;
14
+ }): (repos: {
15
+ assetTransaction: AssetTransactionRepo;
16
+ reservation: ReservationRepo;
17
+ }) => Promise<{
18
+ deleteResult?: IDeleteResult;
19
+ deleteReserveTransactionResult?: IDeleteResult;
20
+ deleteCancelReservationTransactionResult?: IDeleteResult;
21
+ reserveTransactionNumbers: string[];
22
+ }>;
23
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteReservationsByPlaceOrder = deleteReservationsByPlaceOrder;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ const factory_1 = require("../../../factory");
6
+ function deleteReservationsByPlaceOrder(params) {
7
+ return async (repos) => {
8
+ let deleteResult;
9
+ let deleteReserveTransactionResult;
10
+ let deleteCancelReservationTransactionResult;
11
+ const authorizeActions = params.authorizeActions;
12
+ // 予約取引番号を抽出
13
+ const authorizeReservationOfferActions = authorizeActions
14
+ .filter((a) => {
15
+ return a.object.typeOf === factory_1.factory.action.authorize.offer.eventService.ObjectType.SeatReservation
16
+ && a.instrument?.transactionNumber === 'string'
17
+ && a.instrument.transactionNumber.length > 0;
18
+ });
19
+ const reserveTransactionNumbers = authorizeReservationOfferActions
20
+ .map((a) => String(a.instrument?.transactionNumber));
21
+ if (reserveTransactionNumbers.length > 0) {
22
+ // 該当予約番号の予約を削除する(プロジェクトでも絞ること)
23
+ const deleteReservationsResult = await repos.reservation.deleteByReservationNumbers({
24
+ project: { id: params.transaction.project.id },
25
+ reservationNumbers: reserveTransactionNumbers
26
+ });
27
+ deleteResult = {
28
+ n: deleteReservationsResult?.n,
29
+ ok: deleteReservationsResult?.ok,
30
+ deletedCount: deleteReservationsResult?.deletedCount
31
+ };
32
+ // 予約取引を削除(プロジェクトでも絞ること)(2022-06-07~)
33
+ const deleteAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
34
+ project: { id: params.transaction.project.id },
35
+ transactionNumbers: reserveTransactionNumbers,
36
+ typeOf: factory_1.factory.assetTransactionType.Reserve
37
+ });
38
+ deleteReserveTransactionResult = {
39
+ n: deleteAssetTransactionsResult?.n,
40
+ ok: deleteAssetTransactionsResult?.ok,
41
+ deletedCount: deleteAssetTransactionsResult?.deletedCount
42
+ };
43
+ // 予約番号で予約取消取引を検索
44
+ const deletingCancelReservationTransactions = await repos.assetTransaction.search({
45
+ project: { id: { $eq: params.transaction.project.id } },
46
+ object: { reservationNumber: { $in: reserveTransactionNumbers } },
47
+ typeOf: factory_1.factory.assetTransactionType.CancelReservation
48
+ }, ['transactionNumber'], []);
49
+ if (deletingCancelReservationTransactions.length > 0) {
50
+ // 予約取消取引も削除(2024-04-18~)
51
+ const deleteCancelReservationResult = await repos.assetTransaction.deleteByTransactionNumber({
52
+ project: { id: params.transaction.project.id },
53
+ transactionNumbers: deletingCancelReservationTransactions.map(({ transactionNumber }) => String(transactionNumber)),
54
+ typeOf: factory_1.factory.assetTransactionType.CancelReservation
55
+ });
56
+ deleteCancelReservationTransactionResult = {
57
+ n: deleteCancelReservationResult?.n,
58
+ ok: deleteCancelReservationResult?.ok,
59
+ deletedCount: deleteCancelReservationResult?.deletedCount
60
+ };
61
+ }
62
+ }
63
+ return { deleteResult, deleteReserveTransactionResult, deleteCancelReservationTransactionResult, reserveTransactionNumbers };
64
+ };
65
+ }
@@ -4,6 +4,8 @@ exports.deleteTransaction = deleteTransaction;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  const factory_1 = require("../../factory");
6
6
  const deleteOrder_1 = require("../order/deleteOrder");
7
+ const deletePayTransactionsByPlaceOrder_1 = require("./deleteTransaction/deletePayTransactionsByPlaceOrder");
8
+ const deleteReservationsByPlaceOrder_1 = require("./deleteTransaction/deleteReservationsByPlaceOrder");
7
9
  /**
8
10
  * 取引に関わるリソースを削除する
9
11
  * 冪等性を確保すること
@@ -30,7 +32,6 @@ function deleteTransactionById(params) {
30
32
  if (typeof deletingTransactionId !== 'string' || deletingTransactionId.length === 0) {
31
33
  throw new factory_1.factory.errors.ArgumentNull('object.id');
32
34
  }
33
- // let deletingOrderNumberByTask: string | undefined;
34
35
  let transaction;
35
36
  if (params.object.typeOf === factory_1.factory.transactionType.PlaceOrder) {
36
37
  transaction = (await repos.placeOrder.findPlaceOrderTransactions({
@@ -38,7 +39,6 @@ function deleteTransactionById(params) {
38
39
  typeOf: params.object.typeOf,
39
40
  inclusion: ['typeOf', 'project', 'status']
40
41
  })).shift();
41
- // deletingOrderNumberByTask = params.object.object.orderNumber;
42
42
  }
43
43
  else if (params.object.typeOf === factory_1.factory.transactionType.ReturnOrder) {
44
44
  transaction = (await repos.returnOrder.findReturnOrderTransactions({
@@ -70,7 +70,6 @@ function deleteTransactionById(params) {
70
70
  let deleteCancelReservationTransactionResult;
71
71
  let deletedReservationNumbers = [];
72
72
  let deleteActionResult;
73
- // let deleteMessagessResult: IDeleteResult | undefined;
74
73
  const action = await repos.action.start(actionAttributes);
75
74
  try {
76
75
  const transactionTypeOf = transaction.typeOf;
@@ -90,11 +89,6 @@ function deleteTransactionById(params) {
90
89
  break;
91
90
  case factory_1.factory.transactionStatusType.Confirmed: {
92
91
  // identifierによる削除に変更(2026-06-28~)
93
- // if (typeof deletingOrderNumberByTask === 'string') {
94
- // await deleteOrder({
95
- // object: { orderNumber: deletingOrderNumberByTask }
96
- // })(repos);
97
- // }
98
92
  await (0, deleteOrder_1.deleteOrder)({
99
93
  object: { identifier: transaction.id }
100
94
  })(repos);
@@ -104,12 +98,12 @@ function deleteTransactionById(params) {
104
98
  throw new factory_1.factory.errors.NotImplemented(`${transaction.status} not implemented`);
105
99
  }
106
100
  // 決済取引を削除
107
- const deletePayTransactionsByPlaceOrderResult = await deletePayTransactionsByPlaceOrder({ authorizeActions, transaction })(repos);
101
+ const deletePayTransactionsByPlaceOrderResult = await (0, deletePayTransactionsByPlaceOrder_1.deletePayTransactionsByPlaceOrder)({ authorizeActions, transaction })(repos);
108
102
  deletePayTransactionResult = deletePayTransactionsByPlaceOrderResult.deletePayTransactionResult;
109
103
  deleteRefundResult = deletePayTransactionsByPlaceOrderResult.deleteRefundResult;
110
104
  payTransactionNumbers = deletePayTransactionsByPlaceOrderResult.payTransactionNumbers;
111
105
  // 取引上での予約を削除
112
- const deleteReservationsByPlaceOrderResult = await deleteReservationsByPlaceOrder({ authorizeActions, transaction })(repos);
106
+ const deleteReservationsByPlaceOrderResult = await (0, deleteReservationsByPlaceOrder_1.deleteReservationsByPlaceOrder)({ authorizeActions, transaction })(repos);
113
107
  deleteReservationsResult = deleteReservationsByPlaceOrderResult.deleteResult;
114
108
  deleteReserveTransactionResult = deleteReservationsByPlaceOrderResult.deleteReserveTransactionResult;
115
109
  deleteCancelReservationTransactionResult =
@@ -121,10 +115,12 @@ function deleteTransactionById(params) {
121
115
  purpose: { id: transaction.id, typeOf: transactionTypeOf },
122
116
  typeOf: {
123
117
  $in: [
124
- factory_1.factory.actionType.AuthorizeAction,
125
- factory_1.factory.actionType.CheckAction,
126
- factory_1.factory.actionType.InformAction,
127
- factory_1.factory.actionType.OrderAction
118
+ factory_1.factory.actionType.AcceptAction, // オファー採用、決済採用
119
+ factory_1.factory.actionType.AuthorizeAction, // オファー承認、決済承認
120
+ factory_1.factory.actionType.CheckAction, // 決済カード認証
121
+ // factory.actionType.InformAction, // 通知は特になし
122
+ factory_1.factory.actionType.OrderAction, // 注文
123
+ factory_1.factory.actionType.RefundAction // 決済採用返金
128
124
  ]
129
125
  }
130
126
  });
@@ -171,138 +167,3 @@ function deleteTransactionById(params) {
171
167
  await repos.action.completeWithVoid({ typeOf: action.typeOf, id: action.id, result: actionResult });
172
168
  };
173
169
  }
174
- function deleteReservationsByPlaceOrder(params) {
175
- return async (repos) => {
176
- let deleteResult;
177
- let deleteReserveTransactionResult;
178
- let deleteCancelReservationTransactionResult;
179
- const authorizeActions = params.authorizeActions;
180
- // 予約取引番号を抽出
181
- const authorizeReservationOfferActions = authorizeActions
182
- .filter((a) => {
183
- const pendingTransactionNumber = a.instrument?.transactionNumber;
184
- return a.object.typeOf === factory_1.factory.action.authorize.offer.eventService.ObjectType.SeatReservation
185
- && typeof pendingTransactionNumber === 'string'
186
- && pendingTransactionNumber.length > 0;
187
- });
188
- const reserveTransactionNumbers = authorizeReservationOfferActions
189
- .map((a) => String(a.instrument?.transactionNumber));
190
- if (reserveTransactionNumbers.length > 0) {
191
- // 該当予約番号の予約を削除する(プロジェクトでも絞ること)
192
- const deleteReservationsResult = await repos.reservation.deleteByReservationNumbers({
193
- project: { id: params.transaction.project.id },
194
- reservationNumbers: reserveTransactionNumbers
195
- });
196
- deleteResult = {
197
- n: deleteReservationsResult?.n,
198
- ok: deleteReservationsResult?.ok,
199
- deletedCount: deleteReservationsResult?.deletedCount
200
- };
201
- // 予約取引を削除(プロジェクトでも絞ること)(2022-06-07~)
202
- const deleteAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
203
- project: { id: params.transaction.project.id },
204
- transactionNumbers: reserveTransactionNumbers,
205
- typeOf: factory_1.factory.assetTransactionType.Reserve
206
- });
207
- deleteReserveTransactionResult = {
208
- n: deleteAssetTransactionsResult?.n,
209
- ok: deleteAssetTransactionsResult?.ok,
210
- deletedCount: deleteAssetTransactionsResult?.deletedCount
211
- };
212
- // 予約番号で予約取消取引を検索
213
- const deletingCancelReservationTransactions = await repos.assetTransaction.search({
214
- project: { id: { $eq: params.transaction.project.id } },
215
- object: { reservationNumber: { $in: reserveTransactionNumbers } },
216
- typeOf: factory_1.factory.assetTransactionType.CancelReservation
217
- }, ['transactionNumber'], []);
218
- if (deletingCancelReservationTransactions.length > 0) {
219
- // 予約取消取引も削除(2024-04-18~)
220
- const deleteCancelReservationResult = await repos.assetTransaction.deleteByTransactionNumber({
221
- project: { id: params.transaction.project.id },
222
- transactionNumbers: deletingCancelReservationTransactions.map(({ transactionNumber }) => String(transactionNumber)),
223
- typeOf: factory_1.factory.assetTransactionType.CancelReservation
224
- });
225
- deleteCancelReservationTransactionResult = {
226
- n: deleteCancelReservationResult?.n,
227
- ok: deleteCancelReservationResult?.ok,
228
- deletedCount: deleteCancelReservationResult?.deletedCount
229
- };
230
- }
231
- }
232
- return { deleteResult, deleteReserveTransactionResult, deleteCancelReservationTransactionResult, reserveTransactionNumbers };
233
- };
234
- }
235
- function deletePayTransactionsByPlaceOrder(params) {
236
- return async (repos) => {
237
- let deletePayTransactionResult;
238
- let deleteRefundResult;
239
- const authorizeActions = params.authorizeActions;
240
- // 決済取引番号を抽出
241
- const authorizePaymentActions = authorizeActions
242
- .filter((a) => {
243
- const pendingTransactionNumber = a.object?.paymentMethodId;
244
- return a.object.typeOf === factory_1.factory.action.authorize.paymentMethod.any.ResultType.Payment
245
- && typeof pendingTransactionNumber === 'string'
246
- && pendingTransactionNumber.length > 0;
247
- });
248
- const payTransactionNumbers = authorizePaymentActions.map((a) => String(a.object.paymentMethodId));
249
- if (payTransactionNumbers.length > 0) {
250
- // 決済取引を削除(プロジェクトでも絞ること)(2022-06-07~)
251
- const deleteAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
252
- project: { id: params.transaction.project.id },
253
- transactionNumbers: payTransactionNumbers,
254
- typeOf: factory_1.factory.assetTransactionType.Pay
255
- });
256
- deletePayTransactionResult = {
257
- n: deleteAssetTransactionsResult?.n,
258
- ok: deleteAssetTransactionsResult?.ok,
259
- deletedCount: deleteAssetTransactionsResult?.deletedCount
260
- };
261
- // 返金取引も削除(2023-05-19~)
262
- const refundTransactions = await repos.assetTransaction.search({
263
- typeOf: factory_1.factory.assetTransactionType.Refund,
264
- object: { paymentMethodId: { $in: payTransactionNumbers } }
265
- }, ['transactionNumber'], []);
266
- if (refundTransactions.length > 0) {
267
- const deleteRefundAssetTransactionsResult = await repos.assetTransaction.deleteByTransactionNumber({
268
- project: { id: params.transaction.project.id },
269
- transactionNumbers: refundTransactions.map(({ transactionNumber }) => transactionNumber),
270
- typeOf: factory_1.factory.assetTransactionType.Refund
271
- });
272
- deleteRefundResult = {
273
- n: deleteRefundAssetTransactionsResult?.n,
274
- ok: deleteRefundAssetTransactionsResult?.ok,
275
- deletedCount: deleteRefundAssetTransactionsResult?.deletedCount
276
- };
277
- }
278
- }
279
- return { deletePayTransactionResult, deleteRefundResult, payTransactionNumbers };
280
- };
281
- }
282
- // function deleteMessagesByPlaceOrder(params: {
283
- // transaction: factory.task.deleteTransaction.IObject;
284
- // }) {
285
- // return async (repos: {
286
- // message: MessageRepo;
287
- // }): Promise<{
288
- // deleteResult?: IDeleteResult;
289
- // }> => {
290
- // let deleteResult: IDeleteResult | undefined;
291
- // if (params.transaction.typeOf === factory.transactionType.PlaceOrder
292
- // && params.transaction.specifyingMethod === factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id) {
293
- // const orderNumber = params.transaction.object.orderNumber;
294
- // if (typeof orderNumber === 'string' && orderNumber.length > 0) {
295
- // const deleteReservationsResult = await repos.message.deleteByMainEntityOrderNumber({
296
- // project: { id: params.transaction.project.id },
297
- // mainEntity: { orderNumber }
298
- // });
299
- // deleteResult = {
300
- // n: deleteReservationsResult?.n,
301
- // ok: deleteReservationsResult?.ok,
302
- // deletedCount: deleteReservationsResult?.deletedCount
303
- // };
304
- // }
305
- // }
306
- // return { deleteResult };
307
- // };
308
- // }
@@ -58,9 +58,9 @@ function processTransactionNotInProgress(params) {
58
58
  function confirm(params, options) {
59
59
  return async (repos) => {
60
60
  // 確認番号を事前発行
61
- await (0, publishConfirmationNumberIfNotExist_1.publishConfirmationNumberIfNotExist)({
61
+ const confirmationNumber = await (0, publishConfirmationNumberIfNotExist_1.publishConfirmationNumberIfNotExist)({
62
62
  id: params.id,
63
- status: { $in: [factory_1.factory.transactionStatusType.Confirmed, factory_1.factory.transactionStatusType.InProgress] },
63
+ // status: { $in: [factory.transactionStatusType.Confirmed, factory.transactionStatusType.InProgress] },
64
64
  object: { orderDate: params.result.order.orderDate }
65
65
  })(repos);
66
66
  const transaction = await repos.placeOrder.findPlaceOrderById({ typeOf: factory_1.factory.transactionType.PlaceOrder, id: params.id }, ['typeOf', 'project', 'status', 'agent', 'seller', 'object', 'result']);
@@ -142,7 +142,9 @@ function confirm(params, options) {
142
142
  const seller = (0, factory_2.createSeller)({ transaction });
143
143
  const { paymentMethods, placingOrder, result, eventId, reservationIds } = createResult({
144
144
  ...params,
145
- orderNumber, transaction,
145
+ orderNumber,
146
+ confirmationNumber,
147
+ transaction,
146
148
  acceptPayActions,
147
149
  authorizePaymentActions, authorizeEventServiceOfferActions,
148
150
  acceptedOffers, payTransactions, customer,
@@ -178,7 +180,8 @@ function confirm(params, options) {
178
180
  id: transaction.id,
179
181
  object: {
180
182
  orderDate: params.result.order.orderDate,
181
- orderNumber
183
+ orderNumber,
184
+ confirmationNumber: placingOrder.confirmationNumber
182
185
  },
183
186
  result: result,
184
187
  potentialActions: potentialActions
@@ -341,8 +344,10 @@ function createResult(params, options) {
341
344
  result: params.result
342
345
  });
343
346
  (0, validation_1.validatePaymentMethods)({ order: { paymentMethods } }, options);
344
- // 確認番号を発行
345
- const { confirmationNumber } = createConfirmationNumber({ transaction });
347
+ // 取引のobjectへの依存を排除する(2026-07-08~)
348
+ const { confirmationNumber } = params;
349
+ // // 確認番号を発行
350
+ // const { confirmationNumber } = createConfirmationNumber({ transaction });
346
351
  // 注文作成
347
352
  const orderAsResult = (0, result_1.createOrderAsResult)({
348
353
  orderNumber: params.orderNumber,
@@ -433,14 +438,3 @@ function searchAuthorizeActions(params) {
433
438
  return authorizeActions;
434
439
  };
435
440
  }
436
- function createConfirmationNumber(params) {
437
- const confirmationNumber = params.transaction.object.confirmationNumber;
438
- // 取引に確認番号が保管されていなければ、確認番号を発行
439
- if (typeof confirmationNumber !== 'string') {
440
- // 事前に発行済なはずなので、ありえないフロー
441
- throw new factory_1.factory.errors.Internal('object.confirmationNumber undefined');
442
- }
443
- return {
444
- confirmationNumber,
445
- };
446
- }
@@ -1,22 +1,19 @@
1
1
  import type { ConfirmationNumberRepo } from '../../../repo/confirmationNumber';
2
- import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
3
- import { factory } from '../../../factory';
2
+ import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
4
3
  /**
5
- * 未発行であれば、注文の確認番号を発行して取引に保管する
4
+ * 未発行であれば、確認番号を発行して注文ドキュメントに保管する
5
+ * reimplement using OrderInTransactionRepo(2026-07-09~)
6
6
  */
7
7
  declare function publishConfirmationNumberIfNotExist(params: {
8
8
  /**
9
9
  * 取引ID
10
10
  */
11
11
  id: string;
12
- status: {
13
- $in: factory.transactionStatusType[];
14
- };
15
12
  object: {
16
13
  orderDate: Date;
17
14
  };
18
15
  }): (repos: {
19
- placeOrder: PlaceOrderRepo;
20
16
  confirmationNumber: ConfirmationNumberRepo;
17
+ orderInTransaction: OrderInTransactionRepo;
21
18
  }) => Promise<string>;
22
19
  export { publishConfirmationNumberIfNotExist };
@@ -1,36 +1,54 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.publishConfirmationNumberIfNotExist = publishConfirmationNumberIfNotExist;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ // import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
4
9
  const factory_1 = require("../../../factory");
10
+ const debug = (0, debug_1.default)('chevre-domain:service:transaction:placeOrder:publishConfirmationNumberIfNotExist');
5
11
  /**
6
- * 未発行であれば、注文の確認番号を発行して取引に保管する
12
+ * 未発行であれば、確認番号を発行して注文ドキュメントに保管する
13
+ * reimplement using OrderInTransactionRepo(2026-07-09~)
7
14
  */
8
15
  function publishConfirmationNumberIfNotExist(params) {
9
16
  return async (repos) => {
10
- let confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
11
- id: params.id,
12
- status: { $in: params.status.$in }
13
- });
17
+ // let confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
18
+ // id: params.id,
19
+ // status: { $in: params.status.$in }
20
+ // });
21
+ let confirmationNumber = await repos.orderInTransaction.findConfirmationNumberByIdentifier({ identifier: params.id });
22
+ debug('already exists?', confirmationNumber);
14
23
  // すでに発行済であれば何もしない
15
24
  if (typeof confirmationNumber === 'string') {
16
25
  return confirmationNumber;
17
26
  }
18
27
  // 確認番号を発行
19
28
  confirmationNumber = await repos.confirmationNumber.publish({ orderDate: params.object.orderDate });
20
- // 取引に存在しなければ保管
21
- await repos.placeOrder.saveConfirmationNumberIfNotExist({
22
- id: params.id,
23
- status: { $in: params.status.$in },
29
+ debug('saving new confirmationNumber...', confirmationNumber);
30
+ // // 取引に存在しなければ保管
31
+ // await repos.placeOrder.saveConfirmationNumberIfNotExist({
32
+ // id: params.id,
33
+ // status: { $in: params.status.$in },
34
+ // confirmationNumber
35
+ // });
36
+ // 注文ドキュメントにも保管(2026-07-08~)
37
+ const saveResult = await repos.orderInTransaction.saveConfirmationNumberIfNotExist({
38
+ identifier: params.id,
24
39
  confirmationNumber
25
- });
40
+ }, { onlyPlaceOrder: true });
41
+ debug('saveConfirmationNumberIfNotExist result:', JSON.stringify(saveResult));
26
42
  // 確認番号を取引から再取得
27
- confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
28
- id: params.id,
29
- status: { $in: params.status.$in }
30
- });
43
+ // confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
44
+ // id: params.id,
45
+ // status: { $in: params.status.$in }
46
+ // });
47
+ confirmationNumber = await repos.orderInTransaction.findConfirmationNumberByIdentifier({ identifier: params.id });
48
+ debug('confirmationNumber should exist:', confirmationNumber);
31
49
  // 万が一処理が想定通りでない場合confirmationNumberが存在しない
32
50
  if (typeof confirmationNumber !== 'string') {
33
- throw new factory_1.factory.errors.Internal('transaction.object.confirmationNumber not found');
51
+ throw new factory_1.factory.errors.Internal('orderInTransaction.confirmationNumber not found');
34
52
  }
35
53
  return confirmationNumber;
36
54
  };
package/package.json CHANGED
@@ -91,5 +91,5 @@
91
91
  "postversion": "git push origin --tags",
92
92
  "prepublishOnly": "npm run clean && npm run build"
93
93
  },
94
- "version": "25.2.0-alpha.10"
94
+ "version": "25.2.0-alpha.12"
95
95
  }