@chevre/domain 24.0.0-alpha.6 → 24.0.0-alpha.7

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 (43) hide show
  1. package/lib/chevre/repo/mongoose/schemas/transaction.js +16 -0
  2. package/lib/chevre/repo/orderNumber.d.ts +3 -2
  3. package/lib/chevre/repo/orderNumber.js +17 -15
  4. package/lib/chevre/repo/transaction/placeOrder.d.ts +76 -0
  5. package/lib/chevre/repo/transaction/placeOrder.js +170 -0
  6. package/lib/chevre/repo/transaction.d.ts +0 -62
  7. package/lib/chevre/repo/transaction.js +205 -146
  8. package/lib/chevre/repository.d.ts +7 -0
  9. package/lib/chevre/repository.js +15 -1
  10. package/lib/chevre/service/offer/event/authorize.d.ts +2 -0
  11. package/lib/chevre/service/offer/event/authorize.js +2 -2
  12. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  13. package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +2 -0
  14. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +1 -1
  15. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +2 -0
  16. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +4 -4
  17. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +2 -0
  18. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +2 -9
  19. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -1
  20. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +2 -0
  21. package/lib/chevre/service/offer/moneyTransfer/authorize.js +2 -2
  22. package/lib/chevre/service/offer/product.d.ts +2 -0
  23. package/lib/chevre/service/offer/product.js +2 -2
  24. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +3 -2
  25. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +3 -2
  26. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js +1 -1
  27. package/lib/chevre/service/payment/any/fixOrderAsNeeded.d.ts +2 -0
  28. package/lib/chevre/service/payment/any/fixOrderAsNeeded.js +3 -6
  29. package/lib/chevre/service/payment/any.d.ts +3 -0
  30. package/lib/chevre/service/payment/any.js +4 -4
  31. package/lib/chevre/service/task/acceptCOAOffer.js +3 -1
  32. package/lib/chevre/service/task/authorizePayment.js +2 -0
  33. package/lib/chevre/service/task/publishPaymentUrl.js +2 -0
  34. package/lib/chevre/service/task/voidReserveTransaction.js +2 -1
  35. package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +2 -0
  36. package/lib/chevre/service/transaction/placeOrder/confirm.js +2 -2
  37. package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.d.ts → issueOrderNumberIfNotExist.d.ts} +4 -4
  38. package/lib/chevre/service/transaction/placeOrder/{publishOrderNumberIfNotExist.js → issueOrderNumberIfNotExist.js} +21 -13
  39. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.d.ts +2 -2
  40. package/lib/chevre/service/transaction/placeOrder/publishConfirmationNumberIfNotExist.js +3 -3
  41. package/lib/chevre/service/transaction.d.ts +2 -0
  42. package/lib/chevre/service/transaction.js +2 -2
  43. package/package.json +1 -1
@@ -4,6 +4,7 @@ import type { EventRepo } from '../../../repo/event';
4
4
  import type { OfferRepo } from '../../../repo/offer/unitPriceInCatalog';
5
5
  import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
6
6
  import type { TransactionRepo } from '../../../repo/transaction';
7
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
7
8
  import { IRequestBody, IResponseBody } from './authorize/factory';
8
9
  import { IAcceptedOfferBeforeAuthorize4COA } from './authorize/validateAcceptedOffers';
9
10
  import * as factory from '../../../factory';
@@ -15,6 +16,7 @@ export interface IAuthorizeRepos {
15
16
  event: EventRepo;
16
17
  offer: OfferRepo;
17
18
  orderInTransaction: OrderInTransactionRepo;
19
+ placeOrder: PlaceOrderRepo;
18
20
  transaction: TransactionRepo;
19
21
  }
20
22
  export type IAuthorizeOperation<T> = (repos: IAuthorizeRepos) => Promise<T>;
@@ -28,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.authorize = authorize;
30
30
  const moment_1 = __importDefault(require("moment"));
31
- // import { publishOrderNumberIfNotExist } from '../../transaction/placeOrder/publishOrderNumberIfNotExist';
32
31
  const any_1 = require("../any");
33
32
  const factory_1 = require("./authorize/factory");
34
33
  const validateAcceptedOffers_1 = require("./authorize/validateAcceptedOffers");
@@ -104,15 +103,9 @@ function authorize(params) {
104
103
  await repos.action.giveUp({ typeOf: failedAction.typeOf, id: failedAction.id, error });
105
104
  throw error;
106
105
  }
107
- // const now = new Date();
108
- // const orderNumber = await publishOrderNumberIfNotExist({
109
- // project: { id: transaction.project.id },
110
- // id: transaction.id,
111
- // object: { orderDate: now }
112
- // })(repos);
113
- const orderNumber = await repos.transaction.findInProgressOrderNumberById({ id: params.transaction.id });
106
+ const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
114
107
  if (typeof orderNumber !== 'string') {
115
- // 事前に発行されているはず
108
+ // 事前に発行されているはず(acceptCOAOfferにて)
116
109
  throw new factory.errors.NotFound('transaction.object.orderNumber');
117
110
  }
118
111
  let result;
@@ -44,7 +44,7 @@ function changeOffers(params) {
44
44
  if (transaction.agent.id !== params.agent.id) {
45
45
  throw new factory.errors.Forbidden('Transaction not yours');
46
46
  }
47
- const orderNumber = await repos.transaction.findInProgressOrderNumberById({ id: params.transaction.id });
47
+ const orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.transaction.id });
48
48
  if (typeof orderNumber !== 'string') {
49
49
  // 事前に発行されているはず
50
50
  throw new factory.errors.NotFound('transaction.object.orderNumber');
@@ -6,6 +6,7 @@ import type { OrderNumberRepo } from '../../../repo/orderNumber';
6
6
  import type { ProductRepo } from '../../../repo/product';
7
7
  import type { ProjectRepo } from '../../../repo/project';
8
8
  import type { TransactionRepo } from '../../../repo/transaction';
9
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
9
10
  import type { TransactionNumberRepo } from '../../../repo/transactionNumber';
10
11
  interface IAuthorizeRepos {
11
12
  action: ActionRepo;
@@ -14,6 +15,7 @@ interface IAuthorizeRepos {
14
15
  assetTransaction: AssetTransactionRepo;
15
16
  orderInTransaction: OrderInTransactionRepo;
16
17
  orderNumber: OrderNumberRepo;
18
+ placeOrder: PlaceOrderRepo;
17
19
  transaction: TransactionRepo;
18
20
  transactionNumber: TransactionNumberRepo;
19
21
  }
@@ -30,7 +30,7 @@ exports.authorize = authorize;
30
30
  const moment_1 = __importDefault(require("moment"));
31
31
  const factory = __importStar(require("../../../factory"));
32
32
  const MoneyTransferAssetTransactionService = __importStar(require("../../assetTransaction/moneyTransfer"));
33
- const publishOrderNumberIfNotExist_1 = require("../../transaction/placeOrder/publishOrderNumberIfNotExist");
33
+ const issueOrderNumberIfNotExist_1 = require("../../transaction/placeOrder/issueOrderNumberIfNotExist");
34
34
  const any_1 = require("../any");
35
35
  function authorize(params) {
36
36
  return async (repos) => {
@@ -42,7 +42,7 @@ function authorize(params) {
42
42
  throw new factory.errors.Forbidden('Transaction not yours');
43
43
  }
44
44
  const now = new Date();
45
- const orderNumber = await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
45
+ const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
46
46
  project: { id: params.project.id },
47
47
  id: transaction.id,
48
48
  object: { orderDate: now }
@@ -12,6 +12,7 @@ import type { ProjectRepo } from '../../repo/project';
12
12
  import type { ServiceOutputRepo } from '../../repo/serviceOutput';
13
13
  import type { ServiceOutputIdentifierRepo } from '../../repo/serviceOutputIdentifier';
14
14
  import type { TransactionRepo } from '../../repo/transaction';
15
+ import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
15
16
  import type { TransactionNumberRepo } from '../../repo/transactionNumber';
16
17
  export interface IAuthorizeOperationRepos {
17
18
  account: AccountRepo;
@@ -26,6 +27,7 @@ export interface IAuthorizeOperationRepos {
26
27
  project: ProjectRepo;
27
28
  serviceOutput: ServiceOutputRepo;
28
29
  serviceOutputIdentifier: ServiceOutputIdentifierRepo;
30
+ placeOrder: PlaceOrderRepo;
29
31
  transaction: TransactionRepo;
30
32
  transactionNumber: TransactionNumberRepo;
31
33
  }
@@ -31,7 +31,7 @@ const factory = __importStar(require("../../factory"));
31
31
  const accountTransactionIdentifier_1 = require("../../factory/accountTransactionIdentifier");
32
32
  const availableProductTypes_1 = require("../../factory/availableProductTypes");
33
33
  const RegisterServiceTransaction = __importStar(require("../assetTransaction/registerService"));
34
- const publishOrderNumberIfNotExist_1 = require("../transaction/placeOrder/publishOrderNumberIfNotExist");
34
+ const issueOrderNumberIfNotExist_1 = require("../transaction/placeOrder/issueOrderNumberIfNotExist");
35
35
  const any_1 = require("./any");
36
36
  const factory_1 = require("./product/factory");
37
37
  const searchProductOffers_1 = require("./product/searchProductOffers");
@@ -117,7 +117,7 @@ function authorize(params) {
117
117
  })(repos);
118
118
  }
119
119
  // ポイント特典の識別子に利用するため注文番号を先に発行
120
- const orderNumber = await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
120
+ const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
121
121
  project: { id: transaction.project.id },
122
122
  id: transaction.id,
123
123
  object: { orderDate: new Date() }
@@ -2,7 +2,8 @@ import * as factory from '../../../../factory';
2
2
  import type { ActionRepo } from '../../../../repo/action';
3
3
  import type { AuthorizationRepo } from '../../../../repo/authorization';
4
4
  import type { TicketRepo } from '../../../../repo/ticket';
5
- import type { ITransactionInProgress, TransactionRepo } from '../../../../repo/transaction';
5
+ import type { ITransactionInProgress } from '../../../../repo/transaction';
6
+ import type { PlaceOrderRepo } from '../../../../repo/transaction/placeOrder';
6
7
  import type { TransactionNumberRepo } from '../../../../repo/transactionNumber';
7
8
  import * as PayTransactionService from '../../../assetTransaction/pay';
8
9
  import { IInvoiceByTicketToken } from '../factory';
@@ -10,7 +11,7 @@ interface IFixTransactionNumberRepos {
10
11
  action: ActionRepo;
11
12
  authorization: AuthorizationRepo;
12
13
  ticket: TicketRepo;
13
- transaction: TransactionRepo;
14
+ placeOrder: PlaceOrderRepo;
14
15
  transactionNumber: TransactionNumberRepo;
15
16
  }
16
17
  type IFixTransactionNumberOperation<T> = (repos: IFixTransactionNumberRepos) => Promise<T>;
@@ -2,7 +2,8 @@ import * as factory from '../../../../factory';
2
2
  import type { ActionRepo } from '../../../../repo/action';
3
3
  import type { AuthorizationRepo } from '../../../../repo/authorization';
4
4
  import type { TicketRepo } from '../../../../repo/ticket';
5
- import type { ITransactionInProgress, TransactionRepo } from '../../../../repo/transaction';
5
+ import type { ITransactionInProgress } from '../../../../repo/transaction';
6
+ import type { PlaceOrderRepo } from '../../../../repo/transaction/placeOrder';
6
7
  import * as PayTransactionService from '../../../assetTransaction/pay';
7
8
  import type { IInvoiceByTicketToken } from '../factory';
8
9
  type IObjectWithoutDetail = factory.action.authorize.paymentMethod.any.IObjectWithoutDetail;
@@ -21,7 +22,7 @@ declare function handlePrePublishedPaymentMethodIdOnAuthorizing(params: {
21
22
  action: ActionRepo;
22
23
  authorization: AuthorizationRepo;
23
24
  ticket: TicketRepo;
24
- transaction: TransactionRepo;
25
+ placeOrder: PlaceOrderRepo;
25
26
  }) => Promise<{
26
27
  authorizeParams?: {
27
28
  creditCard: factory.action.authorize.paymentMethod.any.ICreditCard;
@@ -122,7 +122,7 @@ function handlePrePublishedPaymentMethodIdOnAuthorizing(params) {
122
122
  let acceptPayAction;
123
123
  // transaction.objectへのアクセス回避(2024-05-30~)
124
124
  // const paymentMethodByTransaction = transaction.object.paymentMethods;
125
- const paymentMethodByTransaction = await repos.transaction.findInProgressPaymentMethodId({ id: params.transaction.id });
125
+ const paymentMethodByTransaction = await repos.placeOrder.findInProgressPaymentMethodId({ id: params.transaction.id });
126
126
  if (params.prePublishedPaymentMethodId === paymentMethodByTransaction?.paymentMethodId) {
127
127
  // check existence of acceptAction when authorizing payment(2024-06-01~)
128
128
  acceptPayAction = (await repos.action.search({
@@ -3,6 +3,7 @@ import type { ConfirmationNumberRepo } from '../../../repo/confirmationNumber';
3
3
  import type { OrderNumberRepo } from '../../../repo/orderNumber';
4
4
  import type { ProjectRepo } from '../../../repo/project';
5
5
  import type { TransactionRepo } from '../../../repo/transaction';
6
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
6
7
  declare function fixOrderAsNeeded(params: {
7
8
  project: {
8
9
  id: string;
@@ -10,6 +11,7 @@ declare function fixOrderAsNeeded(params: {
10
11
  purpose: factory.action.authorize.paymentMethod.any.IPurpose;
11
12
  }): (repos: {
12
13
  project: ProjectRepo;
14
+ placeOrder: PlaceOrderRepo;
13
15
  transaction: TransactionRepo;
14
16
  confirmationNumber: ConfirmationNumberRepo;
15
17
  orderNumber: OrderNumberRepo;
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.fixOrderAsNeeded = fixOrderAsNeeded;
27
27
  const factory = __importStar(require("../../../factory"));
28
28
  const publishConfirmationNumberIfNotExist_1 = require("../../transaction/placeOrder/publishConfirmationNumberIfNotExist");
29
- const publishOrderNumberIfNotExist_1 = require("../../transaction/placeOrder/publishOrderNumberIfNotExist");
29
+ const issueOrderNumberIfNotExist_1 = require("../../transaction/placeOrder/issueOrderNumberIfNotExist");
30
30
  function fixOrderAsNeeded(params) {
31
31
  return async (repos) => {
32
32
  const orderDate = new Date();
@@ -38,13 +38,10 @@ function fixOrderAsNeeded(params) {
38
38
  id: params.purpose.id,
39
39
  status: { $in: [factory.transactionStatusType.InProgress] },
40
40
  object: { orderDate }
41
- })({
42
- confirmationNumber: repos.confirmationNumber,
43
- transaction: repos.transaction
44
- });
41
+ })(repos);
45
42
  // }
46
43
  // publish orderNumber(2025-02-14~)
47
- const orderNumber = await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
44
+ const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
48
45
  project: { id: params.project.id },
49
46
  id: params.purpose.id,
50
47
  object: { orderDate }
@@ -19,6 +19,7 @@ import type { SellerPaymentAcceptedRepo } from '../../repo/sellerPaymentAccepted
19
19
  import type { TaskRepo } from '../../repo/task';
20
20
  import type { TicketRepo } from '../../repo/ticket';
21
21
  import type { TransactionRepo } from '../../repo/transaction';
22
+ import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
22
23
  import type { TransactionNumberRepo } from '../../repo/transactionNumber';
23
24
  import * as PayTransactionService from '../assetTransaction/pay';
24
25
  import { onPaymentStatusChanged } from './any/onPaymentStatusChanged';
@@ -98,6 +99,7 @@ interface IAuthorizeRepos {
98
99
  project: ProjectRepo;
99
100
  task: TaskRepo;
100
101
  ticket: TicketRepo;
102
+ placeOrder: PlaceOrderRepo;
101
103
  transaction: TransactionRepo;
102
104
  transactionNumber: TransactionNumberRepo;
103
105
  }
@@ -115,6 +117,7 @@ interface IPublishPaymentUrlRepos {
115
117
  paymentServiceProvider: PaymentServiceProviderRepo;
116
118
  project: ProjectRepo;
117
119
  ticket: TicketRepo;
120
+ placeOrder: PlaceOrderRepo;
118
121
  transaction: TransactionRepo;
119
122
  transactionNumber: TransactionNumberRepo;
120
123
  }
@@ -36,7 +36,7 @@ const util = __importStar(require("util"));
36
36
  const factory = __importStar(require("../../factory"));
37
37
  // import type { TransactionProcessRepo } from '../../repo/transactionProcess';
38
38
  const PayTransactionService = __importStar(require("../assetTransaction/pay"));
39
- const publishOrderNumberIfNotExist_1 = require("../transaction/placeOrder/publishOrderNumberIfNotExist");
39
+ const issueOrderNumberIfNotExist_1 = require("../transaction/placeOrder/issueOrderNumberIfNotExist");
40
40
  const fixTransactionNumber_1 = require("./any/authorize/fixTransactionNumber");
41
41
  const fixTransactionNumberOnPublishPaymentUrl_1 = require("./any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl");
42
42
  const factory_1 = require("./any/factory");
@@ -344,8 +344,8 @@ function publishPaymentUrl(params) {
344
344
  if (project.id !== transaction.project.id) {
345
345
  throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
346
346
  }
347
- // publishOrderNumber(2025-03-11~)
348
- await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
347
+ // issueOrderNumber(2025-03-11~)
348
+ await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
349
349
  project: { id: transaction.project.id },
350
350
  id: transaction.id,
351
351
  object: { orderDate: new Date() }
@@ -411,7 +411,7 @@ function publishPaymentUrl(params) {
411
411
  // execTranResult: result.execTranResult, // migrate to recipe(2024-06-05~)
412
412
  // paymentMethod: startParams.object.paymentMethod // 拡張(2024-01-04~) // migrate to acceptAction(2024-06-05~)
413
413
  };
414
- await repos.transaction.findByIdAndUpdateInProgress({
414
+ await repos.placeOrder.findByIdAndUpdateInProgress({
415
415
  id: transaction.id,
416
416
  update: { $set: { 'object.paymentMethods': paymentMethodByPaymentUrl } }
417
417
  });
@@ -33,7 +33,7 @@ const orderNumber_1 = require("../../repo/orderNumber");
33
33
  const project_1 = require("../../repo/project");
34
34
  const reserveInterface_1 = require("../../repo/reserveInterface");
35
35
  const transaction_1 = require("../../repo/transaction");
36
- // import { TransactionProcessRepo } from '../../repo/transactionProcess';
36
+ const placeOrder_1 = require("../../repo/transaction/placeOrder");
37
37
  const acceptOffer_1 = require("../offer/eventServiceByCOA/acceptOffer");
38
38
  let coaAuthClient;
39
39
  /**
@@ -106,6 +106,7 @@ function call(params) {
106
106
  event: new event_1.EventRepo(connection),
107
107
  orderNumber: new orderNumber_1.OrderNumberRepo({ connection }),
108
108
  project: new project_1.ProjectRepo(connection),
109
+ placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
109
110
  transaction: new transaction_1.TransactionRepo(connection),
110
111
  reserveService,
111
112
  masterService
@@ -124,6 +125,7 @@ function call(params) {
124
125
  event: new event_1.EventRepo(connection),
125
126
  orderNumber: new orderNumber_1.OrderNumberRepo({ connection }),
126
127
  project: new project_1.ProjectRepo(connection),
128
+ placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
127
129
  transaction: new transaction_1.TransactionRepo(connection),
128
130
  reserveService,
129
131
  masterService
@@ -44,6 +44,7 @@ const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted");
44
44
  const task_1 = require("../../repo/task");
45
45
  const ticket_1 = require("../../repo/ticket");
46
46
  const transaction_1 = require("../../repo/transaction");
47
+ const placeOrder_1 = require("../../repo/transaction/placeOrder");
47
48
  const transactionNumber_1 = require("../../repo/transactionNumber");
48
49
  // import { TransactionProcessRepo } from '../../repo/transactionProcess';
49
50
  const any_1 = require("../payment/any");
@@ -93,6 +94,7 @@ function call(params) {
93
94
  project: new project_1.ProjectRepo(connection),
94
95
  task: new task_1.TaskRepo(connection),
95
96
  ticket: new ticket_1.TicketRepo(connection),
97
+ placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
96
98
  transaction: new transaction_1.TransactionRepo(connection),
97
99
  transactionNumber: new transactionNumber_1.TransactionNumberRepo({ connection })
98
100
  // transactionProcess: transactionProcessRepo
@@ -38,6 +38,7 @@ const project_1 = require("../../repo/project");
38
38
  const sellerPaymentAccepted_1 = require("../../repo/sellerPaymentAccepted");
39
39
  const ticket_1 = require("../../repo/ticket");
40
40
  const transaction_1 = require("../../repo/transaction");
41
+ const placeOrder_1 = require("../../repo/transaction/placeOrder");
41
42
  const transactionNumber_1 = require("../../repo/transactionNumber");
42
43
  // import { TransactionProcessRepo } from '../../repo/transactionProcess';
43
44
  const any_1 = require("../payment/any");
@@ -73,6 +74,7 @@ function call(params) {
73
74
  paymentServiceProvider: new paymentServiceProvider_1.PaymentServiceProviderRepo(connection),
74
75
  project: new project_1.ProjectRepo(connection),
75
76
  ticket: new ticket_1.TicketRepo(connection),
77
+ placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
76
78
  transaction: new transaction_1.TransactionRepo(connection),
77
79
  transactionNumber: new transactionNumber_1.TransactionNumberRepo({ connection })
78
80
  }, settings);
@@ -37,7 +37,7 @@ const setting_1 = require("../../repo/setting");
37
37
  const stockHolder_1 = require("../../repo/stockHolder");
38
38
  const task_1 = require("../../repo/task");
39
39
  const transaction_1 = require("../../repo/transaction");
40
- // import { TransactionProcessRepo } from '../../repo/transactionProcess';
40
+ const placeOrder_1 = require("../../repo/transaction/placeOrder");
41
41
  let coaAuthClientCreated = false;
42
42
  let coaAuthClient = new COA.auth.RefreshToken({
43
43
  endpoint: '', // 使用されないので空文字でok
@@ -87,6 +87,7 @@ function call(params) {
87
87
  reservation: new reservation_1.ReservationRepo(connection),
88
88
  setting: new setting_1.SettingRepo(connection),
89
89
  task: new task_1.TaskRepo(connection),
90
+ placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
90
91
  transaction: new transaction_1.TransactionRepo(connection),
91
92
  reserveService
92
93
  }, settings);
@@ -9,6 +9,7 @@ import type { OrderNumberRepo } from '../../../repo/orderNumber';
9
9
  import type { ProjectRepo } from '../../../repo/project';
10
10
  import type { SettingRepo } from '../../../repo/setting';
11
11
  import type { TransactionRepo } from '../../../repo/transaction';
12
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
12
13
  import * as factory from '../../../factory';
13
14
  import { placeOrder as PlaceOrderFactory } from '../../../factory/transaction';
14
15
  interface IConfirmOperationRepos {
@@ -18,6 +19,7 @@ interface IConfirmOperationRepos {
18
19
  emailMessage?: EmailMessageRepo;
19
20
  message: MessageRepo;
20
21
  project: ProjectRepo;
22
+ placeOrder: PlaceOrderRepo;
21
23
  transaction: TransactionRepo;
22
24
  orderInTransaction: OrderInTransactionRepo;
23
25
  orderNumber: OrderNumberRepo;
@@ -40,7 +40,7 @@ const potentialActions_1 = require("./confirm/potentialActions");
40
40
  const publishCode_1 = require("./confirm/publishCode");
41
41
  const validation_1 = require("./confirm/validation");
42
42
  const publishConfirmationNumberIfNotExist_1 = require("./publishConfirmationNumberIfNotExist");
43
- const publishOrderNumberIfNotExist_1 = require("./publishOrderNumberIfNotExist");
43
+ const issueOrderNumberIfNotExist_1 = require("./issueOrderNumberIfNotExist");
44
44
  const debug = (0, debug_1.default)('chevre-domain:service:transaction');
45
45
  function processTransactionNotInProgress(transaction) {
46
46
  return async (repos) => {
@@ -95,7 +95,7 @@ function confirm(params, options) {
95
95
  acceptPayActions = await searchAcceptPayActions(params)(repos);
96
96
  }
97
97
  // 注文番号を発行
98
- const orderNumber = await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
98
+ const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
99
99
  project: { id: transaction.project.id },
100
100
  id: transaction.id,
101
101
  object: { orderDate: params.result.order.orderDate }
@@ -1,10 +1,10 @@
1
1
  import type { OrderNumberRepo } from '../../../repo/orderNumber';
2
2
  import type { ProjectRepo } from '../../../repo/project';
3
- import type { TransactionRepo } from '../../../repo/transaction';
3
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
4
4
  /**
5
5
  * 未発行であれば、注文番号を発行して取引に保管する
6
6
  */
7
- declare function publishOrderNumberIfNotExist(params: {
7
+ declare function issueOrderNumberIfNotExist(params: {
8
8
  project: {
9
9
  id: string;
10
10
  };
@@ -17,7 +17,7 @@ declare function publishOrderNumberIfNotExist(params: {
17
17
  };
18
18
  }): (repos: {
19
19
  project: ProjectRepo;
20
- transaction: TransactionRepo;
20
+ placeOrder: PlaceOrderRepo;
21
21
  orderNumber: OrderNumberRepo;
22
22
  }) => Promise<string>;
23
- export { publishOrderNumberIfNotExist };
23
+ export { issueOrderNumberIfNotExist };
@@ -23,36 +23,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.publishOrderNumberIfNotExist = publishOrderNumberIfNotExist;
26
+ exports.issueOrderNumberIfNotExist = issueOrderNumberIfNotExist;
27
27
  const factory = __importStar(require("../../../factory"));
28
28
  /**
29
29
  * 未発行であれば、注文番号を発行して取引に保管する
30
30
  */
31
- function publishOrderNumberIfNotExist(params) {
31
+ function issueOrderNumberIfNotExist(params) {
32
32
  return async (repos) => {
33
- // 最適化(2023-02-03~)
34
- let orderNumber = await repos.transaction.findInProgressOrderNumberById({ id: params.id });
33
+ // 1. 最初のチェック
34
+ let orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
35
35
  // すでに発行済であれば何もしない
36
36
  if (typeof orderNumber === 'string') {
37
37
  return orderNumber;
38
38
  }
39
- // 注文番号を発行
39
+ // 2. 発行準備
40
40
  const { alternateName } = await repos.project.findAlternateNameById({ id: params.project.id });
41
41
  if (typeof alternateName !== 'string') {
42
42
  throw new factory.errors.NotFound('project.alternateName');
43
43
  }
44
- orderNumber = await repos.orderNumber.publishByTimestamp({
44
+ // 3. 番号発行
45
+ const issuedOrderNumber = await repos.orderNumber.issueOrderNumber({
45
46
  project: { alternateName },
46
47
  orderDate: params.object.orderDate
47
48
  });
48
- // 取引に存在しなければ保管
49
- await repos.transaction.saveOrderNumberIfNotExist({ id: params.id, orderNumber });
50
- // 注文番号を取引から再取得
51
- // 最適化(2023-02-03~)
52
- orderNumber = await repos.transaction.findInProgressOrderNumberById({ id: params.id });
53
- // 万が一処理が想定通りでない場合orderNumberが存在しない
49
+ // 4. 保管を試みる
50
+ const { modifiedCount } = await repos.placeOrder.saveOrderNumberIfNotExist({
51
+ id: params.id,
52
+ orderNumber: issuedOrderNumber
53
+ });
54
+ // 5. 書き込めたなら、自分が発行した番号が「真実」
55
+ if (modifiedCount === 1) {
56
+ return issuedOrderNumber;
57
+ }
58
+ // 6. 競合が発生した場合(他者が先に書き込んだ場合)
59
+ // DBにある「正解」を再取得して返す
60
+ orderNumber = await repos.placeOrder.findInProgressOrderNumberById({ id: params.id });
54
61
  if (typeof orderNumber !== 'string') {
55
- throw new factory.errors.Internal('transaction.object.orderNumber not found');
62
+ // ここを通るのは、他者が保存した直後に取引がキャンセル/削除された等の極めて稀なケース
63
+ throw new factory.errors.Internal('OrderNumber conflict: failed to retrieve existing number');
56
64
  }
57
65
  return orderNumber;
58
66
  };
@@ -1,5 +1,5 @@
1
1
  import type { ConfirmationNumberRepo } from '../../../repo/confirmationNumber';
2
- import type { TransactionRepo } from '../../../repo/transaction';
2
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
3
3
  import * as factory from '../../../factory';
4
4
  /**
5
5
  * 未発行であれば、注文の確認番号を発行して取引に保管する
@@ -16,7 +16,7 @@ declare function publishConfirmationNumberIfNotExist(params: {
16
16
  orderDate: Date;
17
17
  };
18
18
  }): (repos: {
19
- transaction: TransactionRepo;
19
+ placeOrder: PlaceOrderRepo;
20
20
  confirmationNumber: ConfirmationNumberRepo;
21
21
  }) => Promise<string>;
22
22
  export { publishConfirmationNumberIfNotExist };
@@ -30,7 +30,7 @@ const factory = __importStar(require("../../../factory"));
30
30
  */
31
31
  function publishConfirmationNumberIfNotExist(params) {
32
32
  return async (repos) => {
33
- let confirmationNumber = await repos.transaction.findInProgressConfirmationNumberById({
33
+ let confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
34
34
  id: params.id,
35
35
  status: { $in: params.status.$in }
36
36
  });
@@ -41,13 +41,13 @@ function publishConfirmationNumberIfNotExist(params) {
41
41
  // 確認番号を発行
42
42
  confirmationNumber = await repos.confirmationNumber.publish({ orderDate: params.object.orderDate });
43
43
  // 取引に存在しなければ保管
44
- await repos.transaction.saveConfirmationNumberIfNotExist({
44
+ await repos.placeOrder.saveConfirmationNumberIfNotExist({
45
45
  id: params.id,
46
46
  status: { $in: params.status.$in },
47
47
  confirmationNumber
48
48
  });
49
49
  // 確認番号を取引から再取得
50
- confirmationNumber = await repos.transaction.findInProgressConfirmationNumberById({
50
+ confirmationNumber = await repos.placeOrder.findInProgressConfirmationNumberById({
51
51
  id: params.id,
52
52
  status: { $in: params.status.$in }
53
53
  });
@@ -5,6 +5,7 @@ import type { ProjectRepo } from '../repo/project';
5
5
  import type { SettingRepo } from '../repo/setting';
6
6
  import type { TaskRepo } from '../repo/task';
7
7
  import type { TransactionRepo } from '../repo/transaction';
8
+ import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
8
9
  import { deleteTransaction } from './transaction/deleteTransaction';
9
10
  import * as MoneyTransferTransactionService from './transaction/moneyTransfer';
10
11
  import * as PlaceOrderTransactionService from './transaction/placeOrder';
@@ -32,6 +33,7 @@ export declare function updateAgent(params: {
32
33
  orderInTransaction: OrderInTransactionRepo;
33
34
  orderNumber: OrderNumberRepo;
34
35
  project: ProjectRepo;
36
+ placeOrder: PlaceOrderRepo;
35
37
  transaction: TransactionRepo;
36
38
  }) => Promise<void>;
37
39
  export type IExportTasksOperation<T> = (repos: {
@@ -35,7 +35,7 @@ const deleteTransaction_1 = require("./transaction/deleteTransaction");
35
35
  Object.defineProperty(exports, "deleteTransaction", { enumerable: true, get: function () { return deleteTransaction_1.deleteTransaction; } });
36
36
  const MoneyTransferTransactionService = __importStar(require("./transaction/moneyTransfer"));
37
37
  const PlaceOrderTransactionService = __importStar(require("./transaction/placeOrder"));
38
- const publishOrderNumberIfNotExist_1 = require("./transaction/placeOrder/publishOrderNumberIfNotExist");
38
+ const issueOrderNumberIfNotExist_1 = require("./transaction/placeOrder/issueOrderNumberIfNotExist");
39
39
  const ReturnOrderTransactionService = __importStar(require("./transaction/returnOrder"));
40
40
  exports.moneyTransfer = MoneyTransferTransactionService;
41
41
  exports.placeOrder = PlaceOrderTransactionService;
@@ -120,7 +120,7 @@ function updateAgent(params) {
120
120
  // });
121
121
  // also save in orderInTransaction(2024-06-20~)
122
122
  if (customer !== undefined) {
123
- const orderNumber = await (0, publishOrderNumberIfNotExist_1.publishOrderNumberIfNotExist)({
123
+ const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
124
124
  project: { id: transaction.project.id },
125
125
  id: params.id,
126
126
  object: { orderDate: new Date() }
package/package.json CHANGED
@@ -99,5 +99,5 @@
99
99
  "postversion": "git push origin --tags",
100
100
  "prepublishOnly": "npm run clean && npm run build"
101
101
  },
102
- "version": "24.0.0-alpha.6"
102
+ "version": "24.0.0-alpha.7"
103
103
  }