@chevre/domain 21.35.0-alpha.7 → 21.35.0-alpha.9

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.
@@ -97,19 +97,6 @@ const indexes = [
97
97
  { expires: 1, startDate: -1 },
98
98
  { name: 'searchByExpires-v2' }
99
99
  ],
100
- [
101
- { tasksExportationStatus: 1, startDate: -1 },
102
- { name: 'searchByTasksExportationStatus-v2' }
103
- ],
104
- [
105
- { tasksExportedAt: 1, startDate: -1 },
106
- {
107
- name: 'searchByTasksExportedAt-v2',
108
- partialFilterExpression: {
109
- tasksExportedAt: { $exists: true }
110
- }
111
- }
112
- ],
113
100
  [
114
101
  { 'object.accountId': 1, startDate: -1 },
115
102
  {
@@ -266,10 +253,6 @@ const indexes = [
266
253
  }
267
254
  }
268
255
  ],
269
- [
270
- { typeOf: 1, status: 1, tasksExportationStatus: 1 },
271
- { name: 'startExportTasks' }
272
- ],
273
256
  [
274
257
  { status: 1, expires: 1 },
275
258
  { name: 'makeExpired' }
@@ -80,19 +80,6 @@ const indexes = [
80
80
  { expires: 1, startDate: -1 },
81
81
  { name: 'searchByExpiresAndStartDate' }
82
82
  ],
83
- [
84
- { tasksExportationStatus: 1, startDate: -1 },
85
- { name: 'searchByTasksExportationStatusAndStartDate' }
86
- ],
87
- [
88
- { tasksExportedAt: 1, startDate: -1 },
89
- {
90
- name: 'searchByTasksExportedAtAndStartDate',
91
- partialFilterExpression: {
92
- tasksExportedAt: { $exists: true }
93
- }
94
- }
95
- ],
96
83
  [
97
84
  { 'result.order.confirmationNumber': 1, startDate: -1 },
98
85
  {
@@ -201,19 +188,6 @@ const indexes = [
201
188
  }
202
189
  }
203
190
  ],
204
- [
205
- { typeOf: 1, status: 1, tasksExportationStatus: 1 },
206
- { name: 'startExportTasks' }
207
- ],
208
- [
209
- { 'project.id': 1, typeOf: 1, status: 1, tasksExportationStatus: 1 },
210
- {
211
- name: 'startExportTasks-v2',
212
- partialFilterExpression: {
213
- 'project.id': { $exists: true }
214
- }
215
- }
216
- ],
217
191
  [
218
192
  { status: 1, expires: 1 },
219
193
  { name: 'makeExpired' }
@@ -0,0 +1,21 @@
1
+ import type { MongoRepository as ActionRepo } from '../../../repo/action';
2
+ import type { IPlacingOrder, MongoRepository as OrderInTransactionRepo } from '../../../repo/orderInTransaction';
3
+ import type { MongoRepository as TransactionRepo } from '../../../repo/transaction';
4
+ import * as factory from '../../../factory';
5
+ type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'project' | 'typeOf' | 'result' | 'object' | 'seller'>;
6
+ declare function createPlacingOrderFromExistingTransaction(params: {
7
+ project: {
8
+ id: string;
9
+ };
10
+ confirmationNumber: string;
11
+ orderNumber: string;
12
+ }): (repos: {
13
+ action: ActionRepo;
14
+ orderInTransaction: OrderInTransactionRepo;
15
+ transaction: TransactionRepo;
16
+ }) => Promise<{
17
+ order: IPlacingOrder;
18
+ placeOrderTransaction: IPlaceOrderTransaction;
19
+ serialNumbers: string[];
20
+ }>;
21
+ export { createPlacingOrderFromExistingTransaction };
@@ -0,0 +1,89 @@
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.createPlacingOrderFromExistingTransaction = void 0;
13
+ const createDebug = require("debug");
14
+ const factory = require("../../../factory");
15
+ const factory_1 = require("./factory");
16
+ const debug = createDebug('chevre-domain:service:order');
17
+ // tslint:disable-next-line:max-func-body-length
18
+ function createPlacingOrderFromExistingTransaction(params) {
19
+ // tslint:disable-next-line:max-func-body-length
20
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
21
+ var _a;
22
+ const confirmationNumber = String(params.confirmationNumber);
23
+ const orderNumber = params.orderNumber;
24
+ let order;
25
+ const placeOrderTransactions = yield repos.transaction.search({
26
+ limit: 1,
27
+ page: 1,
28
+ project: { id: { $eq: params.project.id } },
29
+ typeOf: factory.transactionType.PlaceOrder,
30
+ statuses: [factory.transactionStatusType.Confirmed],
31
+ result: {
32
+ order: {
33
+ confirmationNumber: { $eq: confirmationNumber },
34
+ orderNumbers: [orderNumber]
35
+ }
36
+ },
37
+ inclusion: ['project', 'typeOf', 'result', 'object', 'seller'] // potentialActionsは必要なし(2024-01-19~)
38
+ });
39
+ const placeOrderTransactionWithResult = placeOrderTransactions.shift();
40
+ if (placeOrderTransactionWithResult === undefined) {
41
+ throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
42
+ }
43
+ let authorizePaymentActions = [];
44
+ let authorizeOfferActionsWithInstrument = [];
45
+ const authorizeActionsAsResult = (_a = placeOrderTransactionWithResult.result) === null || _a === void 0 ? void 0 : _a.authorizeActions;
46
+ if (Array.isArray(authorizeActionsAsResult) && authorizeActionsAsResult.length > 0) {
47
+ const completedAuthorizeActionIds = authorizeActionsAsResult.map(({ id }) => id);
48
+ if (completedAuthorizeActionIds.length > 0) {
49
+ authorizePaymentActions = yield repos.action.search({
50
+ typeOf: factory.actionType.AuthorizeAction,
51
+ purpose: {
52
+ typeOf: { $in: [factory.transactionType.PlaceOrder] },
53
+ id: { $in: [placeOrderTransactionWithResult.id] }
54
+ },
55
+ object: { typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment } },
56
+ id: { $in: completedAuthorizeActionIds }
57
+ }, ['result'], []);
58
+ authorizeOfferActionsWithInstrument = (yield repos.action.search({
59
+ typeOf: factory.actionType.AuthorizeAction,
60
+ purpose: {
61
+ typeOf: { $in: [factory.transactionType.PlaceOrder] },
62
+ id: { $in: [placeOrderTransactionWithResult.id] }
63
+ },
64
+ object: {
65
+ typeOf: {
66
+ $in: [
67
+ factory.action.authorize.offer.eventService.ObjectType.SeatReservation,
68
+ factory.offerType.Offer
69
+ ]
70
+ }
71
+ },
72
+ id: { $in: completedAuthorizeActionIds }
73
+ }, ['instrument'], []));
74
+ debug('createPlacingOrderFromExistingTransaction: authorizeOfferActionsWithInstrument found:', JSON.stringify(authorizeOfferActionsWithInstrument));
75
+ }
76
+ }
77
+ // orderedItem生成のためにacceptedOffersを取得
78
+ let acceptedOffers;
79
+ const serialNumbers = authorizeOfferActionsWithInstrument
80
+ .filter(({ instrument }) => typeof instrument.transactionNumber === 'string')
81
+ .map(({ instrument }) => String(instrument.transactionNumber));
82
+ // すでにtypeOf: Orderに変更済の場合acceptedOffersは空になるが、そもそもorderedItemはその後上書きされないので、空のまま処理して問題なし
83
+ acceptedOffers = (yield repos.orderInTransaction.findAcceptedOffersByOrderNumber({ orderNumber: { $eq: orderNumber } }))
84
+ .filter(({ serialNumber }) => typeof serialNumber === 'string' && serialNumbers.includes(serialNumber));
85
+ order = (0, factory_1.createPlacingOrder)({ transaction: placeOrderTransactionWithResult, authorizePaymentActions, acceptedOffers });
86
+ return { order, placeOrderTransaction: placeOrderTransactionWithResult, serialNumbers };
87
+ });
88
+ }
89
+ exports.createPlacingOrderFromExistingTransaction = createPlacingOrderFromExistingTransaction;
@@ -1,8 +1,10 @@
1
1
  import type { IPlacingOrder } from '../../../repo/orderInTransaction';
2
2
  import * as factory from '../../../factory';
3
3
  type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'project' | 'typeOf' | 'result' | 'object' | 'seller'>;
4
+ type IOrderAcceptedOffer = factory.order.IAcceptedOffer<factory.order.IItemOffered>;
4
5
  declare function createPlacingOrder(params: {
5
6
  transaction: IPlaceOrderTransaction;
6
7
  authorizePaymentActions: Pick<factory.action.authorize.paymentMethod.any.IAction, 'result'>[];
8
+ acceptedOffers: IOrderAcceptedOffer[];
7
9
  }): IPlacingOrder;
8
- export { createPlacingOrder };
10
+ export { createPlacingOrder, IOrderAcceptedOffer };
@@ -4,6 +4,7 @@ exports.createPlacingOrder = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("../../../factory");
6
6
  const result_1 = require("../../transaction/placeOrderInProgress/result");
7
+ const orderedItem_1 = require("../../transaction/placeOrderInProgress/result/orderedItem");
7
8
  function createPlacingOrder(params) {
8
9
  var _a, _b;
9
10
  const { transaction, authorizePaymentActions } = params;
@@ -11,17 +12,45 @@ function createPlacingOrder(params) {
11
12
  if (orderByTransaction === undefined) {
12
13
  throw new factory.errors.NotFound('transaction.result.order');
13
14
  }
14
- const orderedItems = (Array.isArray(orderByTransaction.orderedItem)) ? orderByTransaction.orderedItem : [];
15
+ // const orderedItems: factory.order.IOrderedItem[]
16
+ // = (Array.isArray(orderByTransaction.orderedItem)) ? orderByTransaction.orderedItem : [];
15
17
  const customer = (0, result_1.createCustomer)({ transaction });
16
18
  const seller = (0, result_1.createSeller)({ transaction });
17
19
  const name = (typeof transaction.object.name === 'string') ? transaction.object.name : undefined;
18
20
  const broker = (typeof ((_b = transaction.object.broker) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? transaction.object.broker : undefined;
19
21
  const { paymentMethods, price } = (0, result_1.createPaymentMethods)({ authorizePaymentActions });
22
+ const eventReservationAcceptedOffers = [];
23
+ const productAcceptedOffers = [];
24
+ const moneyTransferAcceptedOffers = [];
25
+ params.acceptedOffers.forEach((acceptedOffer) => {
26
+ const itemOfferedTypeOf = acceptedOffer.itemOffered.typeOf;
27
+ switch (itemOfferedTypeOf) {
28
+ case factory.reservationType.BusReservation:
29
+ case factory.reservationType.EventReservation:
30
+ eventReservationAcceptedOffers.push(acceptedOffer);
31
+ break;
32
+ case factory.permit.PermitType.Permit:
33
+ productAcceptedOffers.push(acceptedOffer);
34
+ break;
35
+ case factory.actionType.MoneyTransfer:
36
+ moneyTransferAcceptedOffers.push(acceptedOffer);
37
+ break;
38
+ default:
39
+ throw new factory.errors.NotImplemented(`${itemOfferedTypeOf} not implemented`);
40
+ }
41
+ });
42
+ const orderedItem = (0, orderedItem_1.acceptedOffers2orderedItem)({
43
+ eventReservationAcceptedOffers,
44
+ productAcceptedOffers,
45
+ moneyTransferAcceptedOffers
46
+ });
20
47
  return Object.assign(Object.assign(Object.assign(Object.assign({}, orderByTransaction), { customer,
21
48
  seller,
22
49
  paymentMethods,
23
50
  price, orderDate: moment(orderByTransaction.orderDate)
24
- .toDate(), orderedItem: orderedItems }), (typeof name === 'string') ? { name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker } : undefined // 2024-06-17~
51
+ .toDate(),
52
+ // orderedItem: orderedItems,
53
+ orderedItem }), (typeof name === 'string') ? { name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker } : undefined // 2024-06-17~
25
54
  // discontinue(2024-06-17~)
26
55
  // ...(params.dateReturned !== null && params.dateReturned !== undefined)
27
56
  // ? {
@@ -0,0 +1,10 @@
1
+ import type { MongoRepository as OrderInTransactionRepo } from '../../../repo/orderInTransaction';
2
+ declare function voidAcceptedOfferIfNecessary(params: {
3
+ object: {
4
+ orderNumber: string;
5
+ };
6
+ serialNumbers: string[];
7
+ }): (repos: {
8
+ orderInTransaction: OrderInTransactionRepo;
9
+ }) => Promise<void>;
10
+ export { voidAcceptedOfferIfNecessary };
@@ -0,0 +1,34 @@
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.voidAcceptedOfferIfNecessary = void 0;
13
+ const createDebug = require("debug");
14
+ // import type { MongoRepository as TransactionRepo } from '../../../repo/transaction';
15
+ // import * as factory from '../../../factory';
16
+ const debug = createDebug('chevre-domain:service:order');
17
+ // type IPlaceOrderTransaction = Pick<
18
+ // factory.transaction.placeOrder.ITransaction,
19
+ // 'id' | 'project' | 'typeOf' | 'result' | 'object' | 'seller'
20
+ // >;
21
+ function voidAcceptedOfferIfNecessary(params) {
22
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
23
+ if (Array.isArray(params.serialNumbers) && params.serialNumbers.length > 0) {
24
+ // 取引に保管された承認アクション以外のアクションについて、オファーを除外する
25
+ debug('voidAcceptedOfferBySerialNumber processing...', params.object.orderNumber, 'serialNumbersMustBeIn:', params.serialNumbers);
26
+ const voidAcceptedOfferBySerialNumberResult = yield repos.orderInTransaction.voidAcceptedOfferBySerialNumber({
27
+ orderNumber: params.object.orderNumber,
28
+ acceptedOffers: { serialNumber: { $nin: params.serialNumbers } }
29
+ });
30
+ debug('voidAcceptedOfferBySerialNumber processed.', params.object.orderNumber, 'voidAcceptedOfferBySerialNumberResult:', voidAcceptedOfferBySerialNumberResult);
31
+ }
32
+ });
33
+ }
34
+ exports.voidAcceptedOfferIfNecessary = voidAcceptedOfferIfNecessary;
@@ -6,22 +6,6 @@ import type { MongoRepository as OrderInTransactionRepo } from '../../repo/order
6
6
  import type { MongoRepository as TaskRepo } from '../../repo/task';
7
7
  import type { MongoRepository as TransactionRepo } from '../../repo/transaction';
8
8
  import * as factory from '../../factory';
9
- import { IExternalOrder } from './onOrderStatusChanged';
10
- /**
11
- * 注文取引なしに注文を作成する
12
- */
13
- declare function placeOrderWithoutTransaction(params: {
14
- agent?: factory.action.trade.order.IAgent;
15
- project: {
16
- id: string;
17
- };
18
- object: IExternalOrder;
19
- }): (repos: {
20
- accountingReport: AccountingReportRepo;
21
- action: ActionRepo;
22
- order: OrderRepo;
23
- task: TaskRepo;
24
- }) => Promise<void>;
25
9
  /**
26
10
  * 注文を作成する
27
11
  */
@@ -46,4 +30,4 @@ declare function placeOrder(params: {
46
30
  }) => Promise<{
47
31
  order: factory.transaction.placeOrder.IOrderAsResult;
48
32
  }>;
49
- export { placeOrder, placeOrderWithoutTransaction };
33
+ export { placeOrder };
@@ -9,141 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.placeOrderWithoutTransaction = exports.placeOrder = void 0;
13
- const createDebug = require("debug");
12
+ exports.placeOrder = void 0;
14
13
  const factory = require("../../factory");
15
14
  const onAssetTransactionStatusChanged_1 = require("./onAssetTransactionStatusChanged");
16
15
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
17
- const factory_1 = require("./placeOrder/factory");
18
- const debug = createDebug('chevre-domain:service:order');
19
- function createPlacingOrderFromExistingTransaction(params) {
20
- return (repos) => __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- const confirmationNumber = String(params.confirmationNumber);
23
- const orderNumber = params.orderNumber;
24
- let order;
25
- const placeOrderTransactions = yield repos.transaction.search({
26
- limit: 1,
27
- page: 1,
28
- project: { id: { $eq: params.project.id } },
29
- typeOf: factory.transactionType.PlaceOrder,
30
- statuses: [factory.transactionStatusType.Confirmed],
31
- result: {
32
- order: {
33
- confirmationNumber: { $eq: confirmationNumber },
34
- orderNumbers: [orderNumber]
35
- }
36
- },
37
- inclusion: ['project', 'typeOf', 'result', 'object', 'seller'] // potentialActionsは必要なし(2024-01-19~)
38
- });
39
- const placeOrderTransactionWithResult = placeOrderTransactions.shift();
40
- if (placeOrderTransactionWithResult === undefined) {
41
- throw new factory.errors.NotFound(factory.transactionType.PlaceOrder);
42
- }
43
- let authorizePaymentActions = [];
44
- const authorizeActionsAsResult = (_a = placeOrderTransactionWithResult.result) === null || _a === void 0 ? void 0 : _a.authorizeActions;
45
- if (Array.isArray(authorizeActionsAsResult) && authorizeActionsAsResult.length > 0) {
46
- const completedAuthorizeActionIds = authorizeActionsAsResult.map(({ id }) => id);
47
- if (completedAuthorizeActionIds.length > 0) {
48
- authorizePaymentActions = yield repos.action.search({
49
- typeOf: factory.actionType.AuthorizeAction,
50
- purpose: {
51
- typeOf: { $in: [factory.transactionType.PlaceOrder] },
52
- id: { $in: [placeOrderTransactionWithResult.id] }
53
- },
54
- object: { typeOf: { $eq: factory.action.authorize.paymentMethod.any.ResultType.Payment } },
55
- id: { $in: completedAuthorizeActionIds }
56
- }, ['result'], []);
57
- debug('createPlacingOrderFromExistingTransaction: authorizePaymentActions found:', JSON.stringify(authorizePaymentActions));
58
- }
59
- }
60
- order = (0, factory_1.createPlacingOrder)({ transaction: placeOrderTransactionWithResult, authorizePaymentActions });
61
- return { order, placeOrderTransaction: placeOrderTransactionWithResult };
62
- });
63
- }
64
- /**
65
- * 注文取引なしに注文を作成する
66
- */
67
- function placeOrderWithoutTransaction(params) {
68
- return (repos) => __awaiter(this, void 0, void 0, function* () {
69
- var _a;
70
- const order = params.object;
71
- const simpleOrder = {
72
- typeOf: order.typeOf,
73
- // seller: {
74
- // id: order.seller.id,
75
- // typeOf: order.seller.typeOf,
76
- // name: order.seller.name
77
- // }, // 廃止(2024-03-06~)
78
- // customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
79
- orderNumber: order.orderNumber,
80
- price: order.price,
81
- priceCurrency: order.priceCurrency,
82
- orderDate: order.orderDate
83
- };
84
- const orderActionAttributes = {
85
- agent: (typeof ((_a = params.agent) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.agent : order.project,
86
- object: simpleOrder,
87
- potentialActions: {},
88
- project: order.project,
89
- // purpose: { typeOf: placeOrderTransaction.typeOf, id: placeOrderTransaction.id },
90
- typeOf: factory.actionType.OrderAction
91
- };
92
- const action = yield repos.action.start(orderActionAttributes);
93
- try {
94
- yield repos.order.createIfNotExist(Object.assign(Object.assign({}, order), {
95
- // discounts: [], // 廃止(2024-04-16~)
96
- acceptedOffers: [] }));
97
- }
98
- catch (error) {
99
- try {
100
- yield repos.action.giveUp({ typeOf: orderActionAttributes.typeOf, id: action.id, error });
101
- }
102
- catch (__) {
103
- // 失敗したら仕方ない
104
- }
105
- throw error;
106
- }
107
- yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
108
- });
109
- }
110
- exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
111
- function voidAcceptedOfferIfNecessary(params) {
112
- return (repos) => __awaiter(this, void 0, void 0, function* () {
113
- var _a;
114
- // 取引に保管された承認アクション以外のアクションについて、オファーを除外する
115
- const authorizeActionsAsResult = (_a = params.purpose.result) === null || _a === void 0 ? void 0 : _a.authorizeActions;
116
- if (Array.isArray(authorizeActionsAsResult) && authorizeActionsAsResult.length > 0) {
117
- const completedAuthorizeActionIds = authorizeActionsAsResult.map(({ id }) => id);
118
- debug(completedAuthorizeActionIds.length, 'completedAuthorizeActionIds found from transaction', params.purpose.id);
119
- const authorizeActionsWithInstrument = yield repos.action.search({
120
- typeOf: factory.actionType.AuthorizeAction,
121
- purpose: {
122
- typeOf: { $in: [factory.transactionType.PlaceOrder] },
123
- id: { $in: [params.purpose.id] }
124
- },
125
- object: {
126
- typeOf: {
127
- $in: [
128
- factory.action.authorize.offer.eventService.ObjectType.SeatReservation,
129
- factory.offerType.Offer
130
- ]
131
- }
132
- },
133
- id: { $in: completedAuthorizeActionIds }
134
- }, ['instrument'], []);
135
- const serialNumbersMustBeIn = authorizeActionsWithInstrument
136
- .filter(({ instrument }) => typeof instrument.transactionNumber === 'string')
137
- .map(({ instrument }) => String(instrument.transactionNumber));
138
- debug('voidAcceptedOfferBySerialNumber processing...', params.object.orderNumber, 'serialNumbersMustBeIn:', serialNumbersMustBeIn);
139
- const voidAcceptedOfferBySerialNumberResult = yield repos.orderInTransaction.voidAcceptedOfferBySerialNumber({
140
- orderNumber: params.object.orderNumber,
141
- acceptedOffers: { serialNumber: { $nin: serialNumbersMustBeIn } }
142
- });
143
- debug('voidAcceptedOfferBySerialNumber processed.', params.object.orderNumber, 'voidAcceptedOfferBySerialNumberResult:', voidAcceptedOfferBySerialNumberResult);
144
- }
145
- });
146
- }
16
+ const createPlacingOrderFromExistingTransaction_1 = require("./placeOrder/createPlacingOrderFromExistingTransaction");
17
+ const voidAcceptedOfferIfNecessary_1 = require("./placeOrder/voidAcceptedOfferIfNecessary");
147
18
  /**
148
19
  * 注文を作成する
149
20
  */
@@ -155,19 +26,15 @@ function placeOrder(params) {
155
26
  throw new factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
156
27
  }
157
28
  // 注文番号から取引と注文をfixする
158
- const { order, placeOrderTransaction } = yield createPlacingOrderFromExistingTransaction({
29
+ const { order, placeOrderTransaction, serialNumbers } = yield (0, createPlacingOrderFromExistingTransaction_1.createPlacingOrderFromExistingTransaction)({
159
30
  project: { id: params.project.id },
160
31
  confirmationNumber: params.object.confirmationNumber,
161
32
  orderNumber: params.object.orderNumber
162
- })({
163
- action: repos.action,
164
- transaction: repos.transaction
165
- });
33
+ })(repos);
166
34
  // USE_ORDER_PAYMENT_DUE_ON_PLACED設定を廃止したので、必ずOrderPaymentDueのはず(2024-01-10~)
167
35
  if (order.orderStatus !== factory.orderStatus.OrderPaymentDue) {
168
36
  throw new factory.errors.ServiceUnavailable(`orderStatus must be ${factory.orderStatus.OrderPaymentDue}`);
169
37
  }
170
- // const maskedCustomer = createMaskedCustomer(order, { noProfile: true });
171
38
  const simpleOrder = {
172
39
  typeOf: order.typeOf,
173
40
  // seller: {
@@ -198,9 +65,7 @@ function placeOrder(params) {
198
65
  page: 1,
199
66
  actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
200
67
  typeOf: { $eq: orderActionAttributes.typeOf },
201
- object: {
202
- orderNumber: { $in: [orderActionAttributes.object.orderNumber] }
203
- },
68
+ object: { orderNumber: { $in: [orderActionAttributes.object.orderNumber] } },
204
69
  purpose: {
205
70
  id: { $in: [orderActionPurpose.id] },
206
71
  typeOf: { $in: [orderActionPurpose.typeOf] }
@@ -210,22 +75,13 @@ function placeOrder(params) {
210
75
  const action = yield repos.action.start(orderActionAttributes);
211
76
  try {
212
77
  // 冗長なオファーを除外する(念のため)
213
- yield voidAcceptedOfferIfNecessary({
78
+ yield (0, voidAcceptedOfferIfNecessary_1.voidAcceptedOfferIfNecessary)({
214
79
  object: { orderNumber: order.orderNumber },
215
- purpose: placeOrderTransaction
80
+ // purpose: placeOrderTransaction,
81
+ serialNumbers
216
82
  })(repos);
217
- // acceptedOffersの内容検証(開発)
218
- // if (USE_ACCEPTED_OFFERS_AS_TRANSACTION_RESULT) {
219
- // if (USE_VERIFY_ACCEPTED_OFFERS) {
220
- // await verifyAcceptedOffers({ order })(repos);
221
- // }
222
- // }
223
- // const ignoreAccpetedOffersFromResult = placeOrderTransaction.result?.options?.ignoreAccpetedOffersFromResult === true;
224
83
  // orderInTransactionを考慮(2024-01-14~)
225
84
  yield repos.orderInTransaction.placeOrder(order);
226
- // if (!ignoreAccpetedOffersFromResult) {
227
- // await repos.order.createIfNotExist(order);
228
- // }
229
85
  }
230
86
  catch (error) {
231
87
  try {
@@ -239,9 +95,7 @@ function placeOrder(params) {
239
95
  yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
240
96
  }
241
97
  if (params.useOnOrderStatusChanged) {
242
- // 経理レポートを保管
243
- // CreateAccountingReportへ移行(2024-02-02~)
244
- // await createAccountingReportIfNotExist(order)({ accountingReport: repos.accountingReport });
98
+ // 経理レポートを保管->CreateAccountingReportへ移行(2024-02-02~)
245
99
  // PaymentDueであればonOrderStatusChangedを実行(2023-08-23~)
246
100
  if (order.orderStatus === factory.orderStatus.OrderPaymentDue) {
247
101
  yield (0, onOrderStatusChanged_1.onOrderPaymentDue)({
@@ -250,7 +104,6 @@ function placeOrder(params) {
250
104
  project: placeOrderTransaction.project,
251
105
  orderNumber: order.orderNumber,
252
106
  confirmationNumber: order.confirmationNumber,
253
- // customer: order.customer,
254
107
  orderDate: order.orderDate,
255
108
  seller: order.seller,
256
109
  typeOf: order.typeOf,
@@ -261,26 +114,6 @@ function placeOrder(params) {
261
114
  })({
262
115
  task: repos.task
263
116
  });
264
- // } else if (order.orderStatus === factory.orderStatus.OrderProcessing) {
265
- // // OrderPaymentDueをスキップしてOrderProcessingから開始する場合(2023-08-23~)
266
- // // OrderPaymentDueに対する処理をまず強制的に実行する(2023-08-24~)
267
- // await onOrderPaymentDue({
268
- // order: {
269
- // paymentMethods: order.paymentMethods,
270
- // project: order.project,
271
- // orderNumber: order.orderNumber,
272
- // confirmationNumber: order.confirmationNumber,
273
- // customer: order.customer,
274
- // orderDate: order.orderDate,
275
- // seller: order.seller,
276
- // typeOf: order.typeOf,
277
- // price: order.price,
278
- // priceCurrency: order.priceCurrency,
279
- // orderStatus: factory.orderStatus.OrderPaymentDue
280
- // }
281
- // })({
282
- // task: repos.task
283
- // });
284
117
  }
285
118
  else {
286
119
  throw new factory.errors.NotImplemented(`placing an order on the status '${order.orderStatus}' not implemented`);
@@ -0,0 +1,22 @@
1
+ import type { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
2
+ import type { MongoRepository as ActionRepo } from '../../repo/action';
3
+ import type { MongoRepository as OrderRepo } from '../../repo/order';
4
+ import type { MongoRepository as TaskRepo } from '../../repo/task';
5
+ import * as factory from '../../factory';
6
+ import { IExternalOrder } from './onOrderStatusChanged';
7
+ /**
8
+ * 注文取引なしに注文を作成する
9
+ */
10
+ declare function placeOrderWithoutTransaction(params: {
11
+ agent?: factory.action.trade.order.IAgent;
12
+ project: {
13
+ id: string;
14
+ };
15
+ object: IExternalOrder;
16
+ }): (repos: {
17
+ accountingReport: AccountingReportRepo;
18
+ action: ActionRepo;
19
+ order: OrderRepo;
20
+ task: TaskRepo;
21
+ }) => Promise<void>;
22
+ export { placeOrderWithoutTransaction };
@@ -0,0 +1,60 @@
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.placeOrderWithoutTransaction = void 0;
13
+ const factory = require("../../factory");
14
+ /**
15
+ * 注文取引なしに注文を作成する
16
+ */
17
+ function placeOrderWithoutTransaction(params) {
18
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
19
+ var _a;
20
+ const order = params.object;
21
+ const simpleOrder = {
22
+ typeOf: order.typeOf,
23
+ // seller: {
24
+ // id: order.seller.id,
25
+ // typeOf: order.seller.typeOf,
26
+ // name: order.seller.name
27
+ // }, // 廃止(2024-03-06~)
28
+ // customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
29
+ orderNumber: order.orderNumber,
30
+ price: order.price,
31
+ priceCurrency: order.priceCurrency,
32
+ orderDate: order.orderDate
33
+ };
34
+ const orderActionAttributes = {
35
+ agent: (typeof ((_a = params.agent) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.agent : order.project,
36
+ object: simpleOrder,
37
+ potentialActions: {},
38
+ project: order.project,
39
+ // purpose: { typeOf: placeOrderTransaction.typeOf, id: placeOrderTransaction.id },
40
+ typeOf: factory.actionType.OrderAction
41
+ };
42
+ const action = yield repos.action.start(orderActionAttributes);
43
+ try {
44
+ yield repos.order.createIfNotExist(Object.assign(Object.assign({}, order), {
45
+ // discounts: [], // 廃止(2024-04-16~)
46
+ acceptedOffers: [] }));
47
+ }
48
+ catch (error) {
49
+ try {
50
+ yield repos.action.giveUp({ typeOf: orderActionAttributes.typeOf, id: action.id, error });
51
+ }
52
+ catch (__) {
53
+ // 失敗したら仕方ない
54
+ }
55
+ throw error;
56
+ }
57
+ yield repos.action.completeWithVoid({ typeOf: orderActionAttributes.typeOf, id: action.id, result: {} });
58
+ });
59
+ }
60
+ exports.placeOrderWithoutTransaction = placeOrderWithoutTransaction;
@@ -7,6 +7,7 @@ import { onAssetTransactionStatusChanged, paymentDue2Processing } from './order/
7
7
  import { onOrderProcessing } from './order/onOrderStatusChanged';
8
8
  import { onOrderUpdated } from './order/onOrderUpdated';
9
9
  import { payOrder } from './order/payOrder';
10
- import { placeOrder, placeOrderWithoutTransaction } from './order/placeOrder';
10
+ import { placeOrder } from './order/placeOrder';
11
+ import { placeOrderWithoutTransaction } from './order/placeOrderWithoutTransaction';
11
12
  import { sendOrder } from './order/sendOrder';
12
13
  export { confirmPayTransaction, deleteOrder, onAssetTransactionStatusChanged, onOrderProcessing, onOrderUpdated, paymentDue2Processing, payOrder, placeOrder, placeOrderWithoutTransaction, sendOrder };
@@ -19,6 +19,7 @@ const payOrder_1 = require("./order/payOrder");
19
19
  Object.defineProperty(exports, "payOrder", { enumerable: true, get: function () { return payOrder_1.payOrder; } });
20
20
  const placeOrder_1 = require("./order/placeOrder");
21
21
  Object.defineProperty(exports, "placeOrder", { enumerable: true, get: function () { return placeOrder_1.placeOrder; } });
22
- Object.defineProperty(exports, "placeOrderWithoutTransaction", { enumerable: true, get: function () { return placeOrder_1.placeOrderWithoutTransaction; } });
22
+ const placeOrderWithoutTransaction_1 = require("./order/placeOrderWithoutTransaction");
23
+ Object.defineProperty(exports, "placeOrderWithoutTransaction", { enumerable: true, get: function () { return placeOrderWithoutTransaction_1.placeOrderWithoutTransaction; } });
23
24
  const sendOrder_1 = require("./order/sendOrder");
24
25
  Object.defineProperty(exports, "sendOrder", { enumerable: true, get: function () { return sendOrder_1.sendOrder; } });
@@ -20,9 +20,11 @@ function createOrder(params) {
20
20
  const broker = (typeof ((_a = params.transaction.object.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? params.transaction.object.broker : undefined;
21
21
  return Object.assign({ typeOf: factory.order.OrderType.Order, price: params.price, priceCurrency: factory.priceCurrency.JPY,
22
22
  // discounts: discounts, // 廃止(2024-04-16~)
23
- confirmationNumber: '', orderNumber: params.orderNumber, orderedItem: params.orderedItem, url: '', orderStatus: params.orderStatus, orderDate: params.orderDate, identifier: [] }, (settings_1.USE_EXPERIMENTAL_FEATURE)
23
+ confirmationNumber: '', orderNumber: params.orderNumber, url: '', orderStatus: params.orderStatus, orderDate: params.orderDate, identifier: [] }, (settings_1.USE_EXPERIMENTAL_FEATURE)
24
24
  ? {}
25
- : Object.assign(Object.assign({ paymentMethods: params.paymentMethods, customer, project: params.transaction.project, seller, isGift: params.isGift }, (typeof name === 'string') ? { name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker } : undefined));
25
+ : Object.assign(Object.assign({ orderedItem: params.orderedItem, paymentMethods: params.paymentMethods, // discontinue(2024-06-17~)
26
+ customer, project: params.transaction.project, // discontinue(2024-06-17~)
27
+ seller, isGift: params.isGift }, (typeof name === 'string') ? { name } : undefined), (typeof (broker === null || broker === void 0 ? void 0 : broker.typeOf) === 'string') ? { broker } : undefined));
26
28
  }
27
29
  exports.createOrder = createOrder;
28
30
  function createSeller(params) {
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "dependencies": {
12
12
  "@aws-sdk/credential-providers": "3.433.0",
13
- "@chevre/factory": "4.375.0-alpha.6",
13
+ "@chevre/factory": "4.375.0-alpha.7",
14
14
  "@cinerino/sdk": "7.3.0-alpha.0",
15
15
  "@motionpicture/coa-service": "9.4.0",
16
16
  "@motionpicture/gmo-service": "5.3.0",
@@ -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.35.0-alpha.7"
113
+ "version": "21.35.0-alpha.9"
114
114
  }