@chevre/domain 25.2.0-alpha.35 → 25.2.0-alpha.36

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.
@@ -16,10 +16,20 @@ export type IOrderInTransaction = Pick<factory.order.IOrder, 'orderNumber' | 'pr
16
16
  /**
17
17
  * typeOf: Orderへドキュメント変換時の編集フィールド
18
18
  */
19
- export type IPlacingOrder = Pick<factory.order.IOrder, 'confirmationNumber' | 'orderDate' | 'orderNumber' | 'orderStatus' | 'orderedItem' | 'paymentMethods' | 'price' | 'priceCurrency' | 'typeOf'> & {
19
+ export type IPlacingOrder = Pick<factory.order.IOrder, 'orderDate' | 'orderStatus' | 'orderedItem' | 'paymentMethods' | 'price' | 'priceCurrency' | 'typeOf'> & {
20
20
  url?: never;
21
21
  identifier?: never;
22
22
  name?: never;
23
+ /**
24
+ * 上書きしてはいけない
25
+ * 注文取引進行中にセット済であり上書きしてはいけない
26
+ */
27
+ orderNumber?: never;
28
+ /**
29
+ * 上書きしてはいけない
30
+ * 注文取引進行中にセット済であり上書きしてはいけない
31
+ */
32
+ confirmationNumber?: never;
23
33
  /**
24
34
  * 上書きしてはいけない
25
35
  */
@@ -103,6 +113,11 @@ export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
103
113
  project: {
104
114
  id: string;
105
115
  };
116
+ }, options: {
117
+ /**
118
+ * 注文取引タイプのドキュメントのみを参照対象にするかどうか
119
+ */
120
+ onlyPlaceOrder: boolean;
106
121
  }): Promise<(Pick<factory.order.IAcceptedOffer, 'id' | 'itemOffered' | 'offeredThrough' | 'serialNumber' | 'typeOf'> & {
107
122
  priceSpecification?: factory.order.ITicketPriceSpecification;
108
123
  })[]>;
@@ -96,10 +96,12 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
96
96
  * 取引進行中の注文からacceptedOffersを検索する
97
97
  * 予約取引から予約ごとの価格仕様も参照する
98
98
  */
99
- async findAcceptedOffersWithPriceByIdentifier(params) {
99
+ async findAcceptedOffersWithPriceByIdentifier(params, options) {
100
+ const onlyPlaceOrder = options.onlyPlaceOrder === true;
100
101
  const doc = await this.orderModel.findOne({
101
102
  identifier: { $eq: params.identifier },
102
- typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder }
103
+ 'project.id': { $eq: params.project.id },
104
+ ...((onlyPlaceOrder) && { typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder } })
103
105
  }, { acceptedOffers: 1 })
104
106
  .lean()
105
107
  .exec();
@@ -145,7 +147,8 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
145
147
  if (!(order.orderDate instanceof Date)) {
146
148
  throw new factory_1.factory.errors.Argument('orderDate', 'must be Date');
147
149
  }
148
- const setFields = order;
150
+ const { confirmationNumber: _confirmationNumber, orderNumber: _orderNumber, ...setFields } = order;
151
+ // const setFields: AnyKeys<factory.order.IOrder> = order;
149
152
  // typeOf:PlaceOrderのドキュメントが存在すれば、typeOf:Orderに変更する
150
153
  await this.orderModel.updateOne({
151
154
  identifier: { $eq: identifier },
@@ -5,7 +5,6 @@ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
5
5
  import { factory } from '../../../factory';
6
6
  type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'project' | 'typeOf' | 'result' | 'object' | 'seller'>;
7
7
  interface ICreatePlacingOrderFromExistingTransactionRepos {
8
- action?: never;
9
8
  authorizeOfferAction: AuthorizeOfferActionRepo;
10
9
  authorizePaymentMethodAction: AuthorizePaymentMethodActionRepo;
11
10
  orderInTransaction: OrderInTransactionRepo;
@@ -18,6 +17,8 @@ declare function createPlacingOrderFromExistingTransaction(params: {
18
17
  confirmationNumber: string;
19
18
  orderNumber: string;
20
19
  }): (repos: ICreatePlacingOrderFromExistingTransactionRepos) => Promise<{
20
+ orderNumber: string;
21
+ confirmationNumber: string;
21
22
  order: IPlacingOrder;
22
23
  placeOrderTransaction: IPlaceOrderTransaction;
23
24
  serialNumbers: string[];
@@ -17,12 +17,6 @@ function createPlacingOrderFromExistingTransaction(params) {
17
17
  object: {
18
18
  orderNumber: { $eq: orderNumber },
19
19
  },
20
- // result: {
21
- // order: {
22
- // confirmationNumber: { $eq: confirmationNumber },
23
- // orderNumbers: [orderNumber]
24
- // }
25
- // },
26
20
  inclusion: ['project', 'typeOf', 'result', 'object', 'seller']
27
21
  });
28
22
  const placeOrderTransactionWithResult = placeOrderTransactions.shift();
@@ -39,43 +33,12 @@ function createPlacingOrderFromExistingTransaction(params) {
39
33
  const authorizeActionsAsResult = placeOrderTransactionWithResult.result?.authorizeActions;
40
34
  if (Array.isArray(authorizeActionsAsResult) && authorizeActionsAsResult.length > 0) {
41
35
  const completedAuthorizeActionIds = authorizeActionsAsResult.map(({ id }) => id);
36
+ /* istanbul ignore else -- @preserve */
42
37
  if (completedAuthorizeActionIds.length > 0) {
43
- // authorizePaymentActions = <Pick<factory.action.authorize.paymentMethod.any.IAction, 'result'>[]>
44
- // await repos.action.search<factory.actionType.AuthorizeAction>(
45
- // {
46
- // typeOf: factory.actionType.AuthorizeAction,
47
- // purpose: {
48
- // typeOf: { $in: [factory.transactionType.PlaceOrder] },
49
- // id: { $in: [placeOrderTransactionWithResult.id] }
50
- // },
51
- // object: { typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment } },
52
- // id: { $in: completedAuthorizeActionIds }
53
- // },
54
- // ['result']
55
- // );
56
38
  authorizePaymentActions = await repos.authorizePaymentMethodAction.findAuthorizePaymentMethodResultsById({
57
39
  purpose: { id: placeOrderTransactionWithResult.id },
58
40
  ids: completedAuthorizeActionIds
59
41
  });
60
- // authorizeOfferActionsWithInstrument = <IAuthorizeActionWithInstrument[]>await repos.action.search<factory.actionType.AuthorizeAction>(
61
- // {
62
- // typeOf: factory.actionType.AuthorizeAction,
63
- // purpose: {
64
- // typeOf: { $in: [factory.transactionType.PlaceOrder] },
65
- // id: { $in: [placeOrderTransactionWithResult.id] }
66
- // },
67
- // object: {
68
- // typeOf: {
69
- // $in: [
70
- // factory.action.authorize.offer.eventService.ObjectType.SeatReservation,
71
- // factory.offerType.Offer
72
- // ]
73
- // }
74
- // },
75
- // id: { $in: completedAuthorizeActionIds }
76
- // },
77
- // ['instrument']
78
- // );
79
42
  authorizeOfferActionsWithInstrument = await repos.authorizeOfferAction.findAuthorizeOfferInstrumentsByIds({
80
43
  purpose: { id: placeOrderTransactionWithResult.id },
81
44
  ids: completedAuthorizeActionIds
@@ -87,26 +50,18 @@ function createPlacingOrderFromExistingTransaction(params) {
87
50
  const serialNumbers = authorizeOfferActionsWithInstrument
88
51
  .filter(({ instrument }) => typeof instrument.transactionNumber === 'string')
89
52
  .map(({ instrument }) => String(instrument.transactionNumber));
90
- try {
91
- // すでにtypeOf: Orderに変更済の場合acceptedOffersは空になるが、そもそもorderedItemはその後上書きされないので、空のまま処理して問題なし
92
- acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
93
- // orderNumber,
94
- identifier: placeOrderTransactionWithResult.id,
95
- project: { id: params.project.id }
96
- }))
97
- .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
98
- }
99
- catch (error) {
100
- let throwsError = true;
101
- // すでにtypeOf: Orderに変更済の場合、NotFoundとなる
102
- if (error instanceof factory_1.factory.errors.NotFound) {
103
- throwsError = false;
104
- }
105
- if (throwsError) {
106
- throw error;
107
- }
108
- }
53
+ // すでにtypeOf: Orderに変更済の場合acceptedOffersは空になるが、そもそもorderedItemはその後上書きされないので、空のまま処理して問題なし
54
+ acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
55
+ identifier: placeOrderTransactionWithResult.id,
56
+ project: { id: params.project.id }
57
+ }, { onlyPlaceOrder: false } // typeOf:PlaceOrderフィルターを無効化したのでもうNotFoundになる心配はなし(2026-07-20~)
58
+ ))
59
+ .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
109
60
  const order = (0, factory_2.createPlacingOrder)({ transaction: placeOrderTransactionWithResult, authorizePaymentActions, acceptedOffers });
110
- return { order, placeOrderTransaction: placeOrderTransactionWithResult, serialNumbers };
61
+ return {
62
+ orderNumber,
63
+ confirmationNumber,
64
+ order, placeOrderTransaction: placeOrderTransactionWithResult, serialNumbers
65
+ };
111
66
  };
112
67
  }
@@ -68,7 +68,6 @@ function createSeller(params) {
68
68
  }
69
69
  function createPlacingOrder(params) {
70
70
  const { transaction, authorizePaymentActions } = params;
71
- let orderDateByTransaction;
72
71
  const { confirmationNumber, orderDate, orderNumber } = transaction.object;
73
72
  if (typeof confirmationNumber !== 'string') {
74
73
  // 事前に発行済なはずなので、ありえないフロー
@@ -79,25 +78,8 @@ function createPlacingOrder(params) {
79
78
  throw new factory_1.factory.errors.Internal('object.orderNumber undefined');
80
79
  }
81
80
  if (orderDate === undefined) {
82
- // orderDateByTransaction = transaction.result?.order?.orderDate
83
- }
84
- else {
85
- orderDateByTransaction = orderDate;
86
- }
87
- if (orderDateByTransaction === undefined) {
88
81
  throw new factory_1.factory.errors.NotFound('orderDate in the transaction');
89
82
  }
90
- // const orderByTransaction = transaction.result?.order;
91
- // if (orderByTransaction === undefined) {
92
- // throw new factory.errors.NotFound('transaction.result.order');
93
- // }
94
- // const seller = createSeller({ transaction });
95
- // discontinue(2026-06-11~)
96
- // const name: string | undefined =
97
- // (typeof transaction.object.name === 'string') ? transaction.object.name : undefined;
98
- // discontinue(2026-06-22~)
99
- // const broker: factory.order.IBroker | undefined =
100
- // (typeof transaction.object.broker?.typeOf === 'string') ? transaction.object.broker : undefined;
101
83
  const { paymentMethods, price } = createPaymentMethods({ authorizePaymentActions });
102
84
  const eventReservationAcceptedOffers = [];
103
85
  params.acceptedOffers.forEach((acceptedOffer) => {
@@ -115,15 +97,15 @@ function createPlacingOrder(params) {
115
97
  });
116
98
  return {
117
99
  // ...orderByTransaction, // transaction.result.orderへの依存廃止(2026-06-15~)
118
- confirmationNumber,
119
- orderNumber,
100
+ // confirmationNumber, // placeOrder時に上書きする必要なし(2026-07-20~)
101
+ // orderNumber, // placeOrder時に上書きする必要なし(2026-07-20~)
120
102
  typeOf: factory_1.factory.order.OrderType.Order, // 取引保管を廃止するためにここで指定(2026-06-14~)
121
103
  orderStatus: factory_1.factory.orderStatus.OrderPaymentDue, // 取引保管を廃止するためにここで指定(2026-06-14~)
122
104
  // seller, // 取引開始時の注文ドキュメント作成へ移行(2026-06-25~)
123
105
  paymentMethods, // 2024-06-17~
124
106
  price, // 2024-06-17~
125
107
  priceCurrency: factory_1.factory.priceCurrency.JPY, // 取引保管を廃止するためにここで指定(2026-06-14~)
126
- orderDate: (0, moment_1.default)(orderDateByTransaction)
108
+ orderDate: (0, moment_1.default)(orderDate)
127
109
  .toDate(),
128
110
  orderedItem, // 2024-06-18~
129
111
  // ...(typeof name === 'string') ? { name } : undefined, // discontinue(2026-06-11~)
@@ -11,7 +11,6 @@ import type { TaskRepo } from '../../repo/task';
11
11
  import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
12
12
  import { factory } from '../../factory';
13
13
  import type { IntegrationSettingRepo as Settings } from '../../repo/setting/integration';
14
- import { IPlacingOrder } from './placeOrder/createPlacingOrderFromExistingTransaction';
15
14
  interface IPlaceOrderRepos {
16
15
  acceptedOffer: AcceptedOfferRepo;
17
16
  accountingReport: AccountingReportRepo;
@@ -29,7 +28,7 @@ interface IPlaceOrderRepos {
29
28
  * 注文を作成する
30
29
  */
31
30
  declare function placeOrder(params: {
32
- agent?: factory.action.trade.order.IAgent;
31
+ agent: factory.action.trade.order.IAgent;
33
32
  project: {
34
33
  id: string;
35
34
  };
@@ -38,7 +37,5 @@ declare function placeOrder(params: {
38
37
  orderNumber: string;
39
38
  };
40
39
  useOnOrderStatusChanged: boolean;
41
- }): (repos: IPlaceOrderRepos, settings: Settings) => Promise<{
42
- order: IPlacingOrder;
43
- }>;
40
+ }): (repos: IPlaceOrderRepos, settings: Settings) => Promise<void>;
44
41
  export { IPlaceOrderRepos, placeOrder };
@@ -11,11 +11,8 @@ const voidAcceptedOfferIfNecessary_1 = require("./placeOrder/voidAcceptedOfferIf
11
11
  */
12
12
  function placeOrder(params) {
13
13
  return async (repos, settings) => {
14
- if (typeof params.useOnOrderStatusChanged !== 'boolean') {
15
- throw new factory_1.factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
16
- }
17
14
  // 注文番号から取引と注文をfixする
18
- const { order, placeOrderTransaction, serialNumbers } = await (0, createPlacingOrderFromExistingTransaction_1.createPlacingOrderFromExistingTransaction)({
15
+ const { orderNumber, confirmationNumber, order, placeOrderTransaction, serialNumbers } = await (0, createPlacingOrderFromExistingTransaction_1.createPlacingOrderFromExistingTransaction)({
19
16
  project: { id: params.project.id },
20
17
  confirmationNumber: params.object.confirmationNumber,
21
18
  orderNumber: params.object.orderNumber
@@ -31,14 +28,14 @@ function placeOrder(params) {
31
28
  }
32
29
  const simpleOrder = {
33
30
  typeOf: order.typeOf,
34
- orderNumber: order.orderNumber,
31
+ orderNumber,
35
32
  orderDate: order.orderDate
36
33
  };
37
34
  const orderActionPurpose = {
38
35
  typeOf: placeOrderTransaction.typeOf, id: placeOrderTransaction.id
39
36
  };
40
37
  const orderActionAttributes = {
41
- agent: (typeof params.agent?.typeOf === 'string') ? params.agent : placeOrderTransaction.project,
38
+ agent: params.agent,
42
39
  object: simpleOrder,
43
40
  project: placeOrderTransaction.project,
44
41
  purpose: orderActionPurpose,
@@ -61,7 +58,6 @@ function placeOrder(params) {
61
58
  try {
62
59
  // 冗長なオファーを除外する(念のため)
63
60
  await (0, voidAcceptedOfferIfNecessary_1.voidAcceptedOfferIfNecessary)({
64
- // object: { orderNumber: order.orderNumber },
65
61
  placeOrderId: placeOrderTransaction.id,
66
62
  serialNumbers
67
63
  })(repos);
@@ -81,38 +77,31 @@ function placeOrder(params) {
81
77
  if (params.useOnOrderStatusChanged) {
82
78
  // 経理レポートを保管->CreateAccountingReportへ移行(2024-02-02~)
83
79
  // PaymentDueであればonOrderStatusChangedを実行(2023-08-23~)
84
- if (order.orderStatus === factory_1.factory.orderStatus.OrderPaymentDue) {
85
- await (0, onOrderStatusChanged_1.onOrderPaymentDue)({
86
- order: {
87
- paymentMethods: order.paymentMethods,
88
- project: placeOrderTransaction.project,
89
- orderNumber: order.orderNumber,
90
- confirmationNumber: order.confirmationNumber,
91
- orderDate: order.orderDate,
92
- // seller: order.seller,
93
- typeOf: order.typeOf,
94
- // price: order.price,
95
- // priceCurrency: order.priceCurrency,
96
- orderStatus: order.orderStatus
97
- }
98
- })({
99
- task: repos.task
100
- });
101
- }
102
- else {
103
- throw new factory_1.factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
104
- }
80
+ await (0, onOrderStatusChanged_1.onOrderPaymentDue)({
81
+ order: {
82
+ paymentMethods: order.paymentMethods,
83
+ project: placeOrderTransaction.project,
84
+ orderNumber,
85
+ confirmationNumber,
86
+ orderDate: order.orderDate,
87
+ typeOf: order.typeOf,
88
+ orderStatus: order.orderStatus
89
+ }
90
+ })({
91
+ task: repos.task
92
+ });
105
93
  // paymentMethods.length: 0の場合を考慮(2023-08-24~)
94
+ /* istanbul ignore else -- @preserve */
106
95
  if (order.paymentMethods.length === 0) {
107
96
  // paymentMethods.length: 0の場合に、confirmPayTransactionは実行されないので、ここで強制的にpaymentDue2Processingを実行する必要がある
108
97
  await (0, onAssetTransactionStatusChanged_1.paymentDue2Processing)({
109
98
  project: { id: placeOrderTransaction.project.id },
110
- confirmationNumber: order.confirmationNumber,
111
- orderNumber: order.orderNumber,
99
+ confirmationNumber,
100
+ orderNumber,
112
101
  useOnOrderStatusChanged: params.useOnOrderStatusChanged === true
113
102
  })(repos, settings);
114
103
  }
115
104
  }
116
- return { order };
105
+ // return { order };
117
106
  };
118
107
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.call = call;
4
+ const factory_1 = require("../../factory");
4
5
  const acceptedOffer_1 = require("../../repo/acceptedOffer");
5
6
  const accountingReport_1 = require("../../repo/accountingReport");
6
7
  const action_1 = require("../../repo/action");
@@ -22,6 +23,7 @@ function call(data) {
22
23
  const settings = new integration_1.IntegrationSettingRepo({ connection });
23
24
  await (0, placeOrder_2.placeOrder)({
24
25
  ...data,
26
+ agent: { id: data.project.id, typeOf: factory_1.factory.organizationType.Project },
25
27
  useOnOrderStatusChanged: true
26
28
  })({
27
29
  acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
@@ -112,10 +112,9 @@ function confirm(params, options) {
112
112
  serialNumbers } = dissolveAuthorizeActions(completedAuthorizeActions);
113
113
  // orderInTransactionから検索する(2024-03-04~)
114
114
  const acceptedOffers = (await repos.orderInTransaction.findAcceptedOffersWithPriceByIdentifier({
115
- // orderNumber,
116
115
  identifier: transaction.id,
117
116
  project: { id: transaction.project.id }
118
- }))
117
+ }, { onlyPlaceOrder: true }))
119
118
  .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
120
119
  // 単価オファーの全適用条件を検証するために、単価オファーを参照(2026-07-06~)
121
120
  const unitPriceOfferConditions = await (0, prepareUnitPriceOfferConditions_1.prepareUnitPriceOfferConditions)({
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "25.2.0-alpha.35"
91
+ "version": "25.2.0-alpha.36"
92
92
  }