@chevre/domain 27.1.0-alpha.8 → 28.0.0-alpha.0

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.
@@ -96,10 +96,6 @@ const indexes = [
96
96
  { eventStatus: 1, startDate: 1 },
97
97
  { name: 'searchByEventStatus' }
98
98
  ],
99
- [
100
- { name: 1, startDate: 1 },
101
- { name: 'searchByName' }
102
- ],
103
99
  [
104
100
  { 'superEvent.id': 1, startDate: 1 },
105
101
  {
@@ -174,18 +170,6 @@ const indexes = [
174
170
  name: 'searchByOffersItemOfferedServiceOutputReservedTicketTicketedSeatTypeOf'
175
171
  }
176
172
  ],
177
- [
178
- {
179
- 'offers.itemOffered.serviceType.id': 1,
180
- startDate: 1
181
- },
182
- {
183
- partialFilterExpression: {
184
- 'offers.itemOffered.serviceType.id': { $exists: true }
185
- },
186
- name: 'searchByOffersItemOfferedServiceTypeId'
187
- }
188
- ],
189
173
  [
190
174
  {
191
175
  'offers.itemOffered.id': 1,
@@ -235,24 +219,6 @@ const indexes = [
235
219
  }
236
220
  }
237
221
  ],
238
- [
239
- { 'name.ja': 1, startDate: 1 },
240
- {
241
- name: 'searchByNameJa',
242
- partialFilterExpression: {
243
- 'name.ja': { $exists: true }
244
- }
245
- }
246
- ],
247
- [
248
- { 'name.en': 1, startDate: 1 },
249
- {
250
- name: 'searchByNameEn',
251
- partialFilterExpression: {
252
- 'name.en': { $exists: true }
253
- }
254
- }
255
- ],
256
222
  [
257
223
  { additionalProperty: 1, startDate: 1 },
258
224
  {
@@ -261,7 +227,42 @@ const indexes = [
261
227
  additionalProperty: { $exists: true }
262
228
  }
263
229
  }
264
- ]
230
+ ],
231
+ // 以下廃止(2026-09-07~)
232
+ // [
233
+ // {
234
+ // 'offers.itemOffered.serviceType.id': 1,
235
+ // startDate: 1
236
+ // },
237
+ // {
238
+ // partialFilterExpression: {
239
+ // 'offers.itemOffered.serviceType.id': { $exists: true }
240
+ // },
241
+ // name: 'searchByOffersItemOfferedServiceTypeId'
242
+ // }
243
+ // ],
244
+ // [
245
+ // { name: 1, startDate: 1 },
246
+ // { name: 'searchByName' }
247
+ // ],
248
+ // [
249
+ // { 'name.ja': 1, startDate: 1 },
250
+ // {
251
+ // name: 'searchByNameJa',
252
+ // partialFilterExpression: {
253
+ // 'name.ja': { $exists: true }
254
+ // }
255
+ // }
256
+ // ],
257
+ // [
258
+ // { 'name.en': 1, startDate: 1 },
259
+ // {
260
+ // name: 'searchByNameEn',
261
+ // partialFilterExpression: {
262
+ // 'name.en': { $exists: true }
263
+ // }
264
+ // }
265
+ // ],
265
266
  ];
266
267
  exports.indexes = indexes;
267
268
  /**
@@ -97,15 +97,6 @@ const indexes = [
97
97
  }
98
98
  }
99
99
  ],
100
- [
101
- { 'object.order.orderNumber': 1, startDate: -1 },
102
- {
103
- name: 'searchByObjectOrderNumberAndStartDate',
104
- partialFilterExpression: {
105
- 'object.order.orderNumber': { $exists: true }
106
- }
107
- }
108
- ],
109
100
  [
110
101
  // 注文取引のobject.orderNumberも発行されている場合ユニークなはず(2026-02-21~)
111
102
  {
@@ -121,19 +112,6 @@ const indexes = [
121
112
  }
122
113
  }
123
114
  ],
124
- [
125
- // ひとつの注文取引に対する確定返品取引はユニークなはず
126
- { 'object.order.orderNumber': 1 },
127
- {
128
- name: 'object.order.orderNumber_1',
129
- unique: true,
130
- partialFilterExpression: {
131
- typeOf: factory_1.factory.transactionType.ReturnOrder, // 返品取引
132
- status: factory_1.factory.transactionStatusType.Confirmed, // 確定ステータス
133
- 'object.order.orderNumber': { $exists: true }
134
- }
135
- }
136
- ],
137
115
  [
138
116
  { 'agent.typeOf': 1, startDate: -1 },
139
117
  {
@@ -210,55 +188,27 @@ const indexes = [
210
188
  'tasksExportAction.startDate': { $exists: true }
211
189
  }
212
190
  }
213
- ]
214
- // result.order廃止につきインデックス廃止(2026-06-28~)
215
- // [
216
- // { 'result.order.confirmationNumber': 1, startDate: -1 },
217
- // {
218
- // name: 'searchByResultOrderConfirmationNumber',
219
- // partialFilterExpression: {
220
- // 'result.order.confirmationNumber': { $exists: true }
221
- // }
222
- // }
223
- // ],
224
- // [
225
- // { 'result.order.orderNumber': 1, startDate: -1 },
226
- // {
227
- // name: 'searchByResultOrderNumberAndStartDate',
228
- // partialFilterExpression: {
229
- // 'result.order.orderNumber': { $exists: true }
230
- // }
231
- // }
232
- // ],
233
- // result.order廃止につきインデックス廃止(2026-06-28~)
191
+ ],
192
+ // typeOf: ReturnOrder廃止につき以下廃止(2026-09-08~)
234
193
  // [
235
- // // 結果の注文番号はユニークなはず
194
+ // { 'object.order.orderNumber': 1, startDate: -1 },
236
195
  // {
237
- // typeOf: 1,
238
- // 'result.order.orderNumber': 1
239
- // },
240
- // {
241
- // name: 'searchPlaceOrderByOrderNumber',
242
- // unique: true,
196
+ // name: 'searchByObjectOrderNumberAndStartDate',
243
197
  // partialFilterExpression: {
244
- // 'result.order.orderNumber': { $exists: true }
198
+ // 'object.order.orderNumber': { $exists: true }
245
199
  // }
246
200
  // }
247
201
  // ],
248
- // uniquePlacingOrderNumberと重複しているので廃止(2026-06-28~)
249
202
  // [
250
- // // 注文取引のobject.orderNumberも発行されている場合ユニークなはず(2026-02-21~)
251
- // {
252
- // typeOf: 1,
253
- // 'object.orderNumber': 1
254
- // },
203
+ // // ひとつの注文取引に対する確定返品取引はユニークなはず
204
+ // { 'object.order.orderNumber': 1 },
255
205
  // {
256
- // name: 'uniquePlacingOrderNumber20260221',
206
+ // name: 'object.order.orderNumber_1',
257
207
  // unique: true,
258
208
  // partialFilterExpression: {
259
- // typeOf: factory.transactionType.PlaceOrder,
260
- // 'object.orderNumber': { $exists: true },
261
- // startDate: { $gte: new Date('2026-02-21T11:00:00Z') }
209
+ // typeOf: factory.transactionType.ReturnOrder, // 返品取引
210
+ // status: factory.transactionStatusType.Confirmed, // 確定ステータス
211
+ // 'object.order.orderNumber': { $exists: true }
262
212
  // }
263
213
  // }
264
214
  // ],
@@ -1,6 +1,7 @@
1
1
  import type { RedisClientType } from '@redis/client';
2
2
  import { factory } from '../../factory';
3
- import type { IStartedTransaction } from './returnOrder';
3
+ type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
4
+ export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IStartedTransactionFields>;
4
5
  /**
5
6
  * 返品取引リポジトリ
6
7
  */
@@ -17,3 +18,4 @@ export declare class ReturnOrderInProgressRepo {
17
18
  id: string;
18
19
  }): Promise<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>>;
19
20
  }
21
+ export {};
@@ -113,7 +113,6 @@ import type { TaskDelayedRepo } from './repo/taskDelayed';
113
113
  import type { TicketRepo } from './repo/ticket';
114
114
  import type { TransactionRepo } from './repo/transaction';
115
115
  import type { PlaceOrderRepo } from './repo/transaction/placeOrder';
116
- import type { ReturnOrderRepo } from './repo/transaction/returnOrder';
117
116
  import type { ReturnOrderInProgressRepo } from './repo/transaction/returnOrderInProgress';
118
117
  import type { TransactionNumberRepo } from './repo/transactionNumber';
119
118
  import type { TransactionProcessRepo } from './repo/transactionProcess';
@@ -604,10 +603,6 @@ export declare namespace transaction {
604
603
  namespace PlaceOrder {
605
604
  function createInstance(...params: ConstructorParameters<typeof PlaceOrderRepo>): Promise<PlaceOrderRepo>;
606
605
  }
607
- type ReturnOrder = ReturnOrderRepo;
608
- namespace ReturnOrder {
609
- function createInstance(...params: ConstructorParameters<typeof ReturnOrderRepo>): Promise<ReturnOrderRepo>;
610
- }
611
606
  type ReturnOrderInProgress = ReturnOrderInProgressRepo;
612
607
  namespace ReturnOrderInProgress {
613
608
  function createInstance(...params: ConstructorParameters<typeof ReturnOrderInProgressRepo>): Promise<ReturnOrderInProgressRepo>;
@@ -1288,17 +1288,6 @@ var transaction;
1288
1288
  }
1289
1289
  PlaceOrder.createInstance = createInstance;
1290
1290
  })(PlaceOrder = transaction.PlaceOrder || (transaction.PlaceOrder = {}));
1291
- let ReturnOrder;
1292
- (function (ReturnOrder) {
1293
- let repo;
1294
- async function createInstance(...params) {
1295
- if (repo === undefined) {
1296
- repo = (await import('./repo/transaction/returnOrder.js')).ReturnOrderRepo;
1297
- }
1298
- return new repo(...params);
1299
- }
1300
- ReturnOrder.createInstance = createInstance;
1301
- })(ReturnOrder = transaction.ReturnOrder || (transaction.ReturnOrder = {}));
1302
1291
  let ReturnOrderInProgress;
1303
1292
  (function (ReturnOrderInProgress) {
1304
1293
  let repo;
@@ -3,7 +3,6 @@ import type { ReturnActionRepo } from '../../repo/action/returnAction';
3
3
  import type { OrderRepo } from '../../repo/order';
4
4
  import type { SettingRepo } from '../../repo/setting';
5
5
  import type { TaskRepo } from '../../repo/task';
6
- import type { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
7
6
  import { factory } from '../../factory';
8
7
  declare function returnOrder(params: {
9
8
  agent: factory.action.transfer.returnAction.order.IAgent;
@@ -24,6 +23,5 @@ declare function returnOrder(params: {
24
23
  order: OrderRepo;
25
24
  setting: SettingRepo;
26
25
  task: TaskRepo;
27
- returnOrder: ReturnOrderRepo;
28
26
  }) => Promise<void>;
29
27
  export { returnOrder };
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.returnOrder = returnOrder;
7
7
  const debug_1 = __importDefault(require("debug"));
8
+ // import type { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
8
9
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
9
10
  const factory_1 = require("../../factory");
10
11
  const debug = (0, debug_1.default)('chevre-domain:service:order');
@@ -49,20 +50,22 @@ function returnOrder(params) {
49
50
  returnOrderTransaction = params.returnOrderTransaction;
50
51
  }
51
52
  else {
52
- // 互換性維持対応としての返品取引検索(2026-09-05~)
53
- const returnOrderTransactions = await repos.returnOrder.findReturnOrderTransactions({
54
- limit: 1,
55
- page: 1,
56
- project: { id: { $eq: order.project.id } },
57
- typeOf: factory_1.factory.transactionType.ReturnOrder,
58
- statuses: [factory_1.factory.transactionStatusType.Confirmed],
59
- object: { order: { orderNumbers: [orderNumber] } },
60
- inclusion: ['typeOf', 'potentialActions', 'object']
61
- });
62
- returnOrderTransaction = returnOrderTransactions.shift();
63
- if (returnOrderTransaction === undefined) {
64
- throw new factory_1.factory.errors.NotFound(factory_1.factory.transactionType.ReturnOrder);
65
- }
53
+ throw new factory_1.factory.errors.ArgumentNull('returnOrderTransaction');
54
+ // // 互換性維持対応としての返品取引検索(2026-09-05~)
55
+ // const returnOrderTransactions =
56
+ // await repos.returnOrder.findReturnOrderTransactions({
57
+ // limit: 1,
58
+ // page: 1,
59
+ // project: { id: { $eq: order.project.id } },
60
+ // typeOf: factory.transactionType.ReturnOrder,
61
+ // statuses: [factory.transactionStatusType.Confirmed],
62
+ // object: { order: { orderNumbers: [orderNumber] } },
63
+ // inclusion: ['typeOf', 'potentialActions', 'object']
64
+ // });
65
+ // returnOrderTransaction = returnOrderTransactions.shift();
66
+ // if (returnOrderTransaction === undefined) {
67
+ // throw new factory.errors.NotFound(factory.transactionType.ReturnOrder);
68
+ // }
66
69
  }
67
70
  const simpleOrder = {
68
71
  typeOf: order.typeOf,
@@ -11,7 +11,6 @@ const note_1 = require("../../repo/note");
11
11
  const order_1 = require("../../repo/order");
12
12
  const reservation_1 = require("../../repo/reservation");
13
13
  const placeOrder_1 = require("../../repo/transaction/placeOrder");
14
- const returnOrder_1 = require("../../repo/transaction/returnOrder");
15
14
  const transaction_1 = require("../transaction");
16
15
  /**
17
16
  * タスク実行関数
@@ -32,7 +31,6 @@ function call(params) {
32
31
  order: new order_1.OrderRepo(connection),
33
32
  reservation: new reservation_1.ReservationRepo(connection),
34
33
  placeOrder: new placeOrder_1.PlaceOrderRepo(connection),
35
- returnOrder: new returnOrder_1.ReturnOrderRepo(connection),
36
34
  });
37
35
  };
38
36
  }
@@ -6,15 +6,15 @@ const returnAction_1 = require("../../repo/action/returnAction");
6
6
  const order_1 = require("../../repo/order");
7
7
  const setting_1 = require("../../repo/setting");
8
8
  const task_1 = require("../../repo/task");
9
- const returnOrder_1 = require("../../repo/transaction/returnOrder");
10
- const returnOrder_2 = require("../order/returnOrder");
9
+ // import { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
10
+ const returnOrder_1 = require("../order/returnOrder");
11
11
  /**
12
12
  * タスク実行関数
13
13
  */
14
14
  function call(params) {
15
15
  return async ({ connection }) => {
16
16
  const { data } = params;
17
- await (0, returnOrder_2.returnOrder)({
17
+ await (0, returnOrder_1.returnOrder)({
18
18
  ...data,
19
19
  useOnOrderStatusChanged: true
20
20
  })({
@@ -23,7 +23,7 @@ function call(params) {
23
23
  order: new order_1.OrderRepo(connection),
24
24
  setting: new setting_1.SettingRepo(connection),
25
25
  task: new task_1.TaskRepo(connection),
26
- returnOrder: new returnOrder_1.ReturnOrderRepo(connection)
26
+ // returnOrder: new ReturnOrderRepo(connection)
27
27
  });
28
28
  };
29
29
  }
@@ -47,7 +47,7 @@ const paymentService_1 = require("../../repo/paymentService");
47
47
  const potentialAction_1 = require("../../repo/potentialAction");
48
48
  const product_1 = require("../../repo/product");
49
49
  const task_1 = require("../../repo/task");
50
- const returnOrder_1 = require("../../repo/transaction/returnOrder");
50
+ // import { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
51
51
  const transactionNumber_1 = require("../../repo/transactionNumber");
52
52
  const RefundTransactionService = __importStar(require("../assetTransaction/refund"));
53
53
  /**
@@ -70,7 +70,7 @@ function call(params) {
70
70
  potentialAction: new potentialAction_1.PotentialActionRepo(connection),
71
71
  product: new product_1.ProductRepo(connection),
72
72
  task: new task_1.TaskRepo(connection),
73
- returnOrder: new returnOrder_1.ReturnOrderRepo(connection),
73
+ // returnOrder: new ReturnOrderRepo(connection),
74
74
  transactionNumber: new transactionNumber_1.TransactionNumberRepo({ connection })
75
75
  });
76
76
  };
@@ -119,16 +119,17 @@ function fixOrderAndTransaction(params, project) {
119
119
  returnOrderTransaction = params.returnOrderTransaction;
120
120
  }
121
121
  else {
122
- returnOrderTransaction = (await repos.returnOrder.findReturnOrderTransactions({
123
- limit: 1,
124
- page: 1,
125
- typeOf: factory_1.factory.transactionType.ReturnOrder,
126
- object: { order: { orderNumbers: [orderNumber] } },
127
- inclusion: ['object']
128
- })).shift();
129
- if (returnOrderTransaction === undefined) {
130
- throw new factory_1.factory.errors.NotFound(factory_1.factory.transactionType.ReturnOrder);
131
- }
122
+ throw new factory_1.factory.errors.ArgumentNull('returnOrderTransaction');
123
+ // returnOrderTransaction = (await repos.returnOrder.findReturnOrderTransactions({
124
+ // limit: 1,
125
+ // page: 1,
126
+ // typeOf: factory.transactionType.ReturnOrder,
127
+ // object: { order: { orderNumbers: [orderNumber] } },
128
+ // inclusion: ['object']
129
+ // })).shift();
130
+ // if (returnOrderTransaction === undefined) {
131
+ // throw new factory.errors.NotFound(factory.transactionType.ReturnOrder);
132
+ // }
132
133
  }
133
134
  const order = await repos.order.projectFieldsByOrderNumber({
134
135
  orderNumber,
@@ -9,7 +9,6 @@ import type { NoteRepo } from '../../repo/note';
9
9
  import type { OrderRepo } from '../../repo/order';
10
10
  import type { ReservationRepo } from '../../repo/reservation';
11
11
  import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
12
- import type { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
13
12
  interface IDeleteTransactionRepos {
14
13
  acceptedOffer: AcceptedOfferRepo;
15
14
  adminAccountingReport: AdminAccountingReportRepo;
@@ -23,7 +22,6 @@ interface IDeleteTransactionRepos {
23
22
  order: OrderRepo;
24
23
  reservation: ReservationRepo;
25
24
  placeOrder: PlaceOrderRepo;
26
- returnOrder: ReturnOrderRepo;
27
25
  }
28
26
  /**
29
27
  * 取引に関わるリソースを削除する
@@ -41,11 +41,12 @@ function deleteTransactionById(params) {
41
41
  })).shift();
42
42
  }
43
43
  else if (params.object.typeOf === factory_1.factory.transactionType.ReturnOrder) {
44
- transaction = (await repos.returnOrder.findReturnOrderTransactions({
45
- ids: [deletingTransactionId],
46
- typeOf: params.object.typeOf,
47
- inclusion: ['typeOf', 'project', 'status']
48
- })).shift();
44
+ // 廃止済(ドキュメントはマニュアルで削除済)につき何もしない(2026-09-08~)
45
+ // transaction = (await repos.returnOrder.findReturnOrderTransactions({
46
+ // ids: [deletingTransactionId],
47
+ // typeOf: params.object.typeOf,
48
+ // inclusion: ['typeOf', 'project', 'status']
49
+ // })).shift();
49
50
  }
50
51
  else {
51
52
  throw new factory_1.factory.errors.NotImplemented(`object not implemented. typeOf:${params.object.typeOf}`);
@@ -1,7 +1,7 @@
1
1
  import { factory } from '../../../../factory';
2
2
  import type { ISetting } from '../../../../repo/setting';
3
3
  export declare function createReturnPaymentMethodActions(params: {
4
- order: Pick<factory.order.IOrder, 'confirmationNumber' | 'customer' | 'orderDate' | 'orderNumber' | 'orderStatus' | 'orderedItem' | 'paymentMethods' | 'price' | 'priceCurrency' | 'seller' | 'typeOf'>;
4
+ order: Pick<factory.order.IOrder, 'confirmationNumber' | 'customer' | 'orderDate' | 'orderNumber' | 'orderedItem' | 'paymentMethods' | 'price' | 'priceCurrency' | 'seller' | 'typeOf'>;
5
5
  returnOrderActionParams?: factory.transaction.returnOrder.IReturnOrderActionParams;
6
6
  transaction: Pick<factory.transaction.returnOrder.ITransaction, 'object'>;
7
7
  }, setting: Pick<ISetting, 'defaultSenderEmail'>): Promise<{
@@ -11,10 +11,8 @@ import type { ReservationRepo } from '../../repo/reservation';
11
11
  import type { SellerRepo } from '../../repo/seller';
12
12
  import type { SellerReturnPolicyRepo } from '../../repo/sellerReturnPolicy';
13
13
  import type { SettingRepo } from '../../repo/setting';
14
- import type { ScheduledTaskRepo } from '../../repo/scheduledTask';
15
14
  import type { TaskRepo } from '../../repo/task';
16
- import type { IStartedTransaction, ReturnOrderRepo } from '../../repo/transaction/returnOrder';
17
- import type { ReturnOrderInProgressRepo } from '../../repo/transaction/returnOrderInProgress';
15
+ import type { IStartedTransaction, ReturnOrderInProgressRepo } from '../../repo/transaction/returnOrderInProgress';
18
16
  import { preStart } from './returnOrder/preStart';
19
17
  interface IStartOperationRepos {
20
18
  acceptedOffer: AcceptedOfferRepo;
@@ -27,29 +25,18 @@ interface IStartOperationRepos {
27
25
  reservation: ReservationRepo;
28
26
  seller: SellerRepo;
29
27
  sellerReturnPolicy: SellerReturnPolicyRepo;
30
- returnOrder: ReturnOrderRepo;
31
28
  returnOrderInProgress: ReturnOrderInProgressRepo;
32
29
  }
33
30
  type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
34
- interface IExportTasksByIdRepos {
35
- setting: SettingRepo;
36
- scheduledTask: ScheduledTaskRepo;
37
- task: TaskRepo;
38
- returnOrder: ReturnOrderRepo;
39
- }
40
- type ITaskAndTransactionOperation<T> = (repos: IExportTasksByIdRepos) => Promise<T>;
41
31
  /**
42
32
  * 返品取引開始
43
33
  */
44
- declare function start(params: factory.transaction.returnOrder.IStartParamsWithoutDetail, options: {
45
- useConfirmReturnOrderTask: boolean;
46
- }): IStartOperation<IStartedTransaction>;
34
+ declare function start(params: factory.transaction.returnOrder.IStartParamsWithoutDetail): IStartOperation<IStartedTransaction>;
47
35
  interface IConfirmRepos {
48
36
  acceptedOffer: AcceptedOfferRepo;
49
37
  message: MessageRepo;
50
38
  order: OrderRepo;
51
39
  setting: SettingRepo;
52
- returnOrder: ReturnOrderRepo;
53
40
  returnOrderInProgress: ReturnOrderInProgressRepo;
54
41
  task: TaskRepo;
55
42
  }
@@ -62,19 +49,5 @@ declare function confirm(params: factory.transaction.returnOrder.IConfirmParams
62
49
  dateReturned: Date;
63
50
  };
64
51
  };
65
- }, options: {
66
- useConfirmReturnOrderTask: boolean;
67
- }): (repos: IConfirmRepos) => Promise<import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult | undefined>;
68
- /**
69
- * 取引のタスクを出力します
70
- * 複数タスクが生成されます
71
- * この関数では、取引のタスクエクスポートステータスは見ません
72
- */
73
- declare function exportTasksById(params: {
74
- id: string;
75
- /**
76
- * タスク実行日時バッファ
77
- */
78
- runsTasksAfterInSeconds?: number;
79
- }): ITaskAndTransactionOperation<void>;
80
- export { IStartOperationRepos, IConfirmRepos, IExportTasksByIdRepos, preStart, start, confirm, exportTasksById };
52
+ }): (repos: IConfirmRepos) => Promise<import("@chevre/factory/lib/chevre/transaction/returnOrder").IResult>;
53
+ export { IStartOperationRepos, IConfirmRepos, preStart, start, confirm, };
@@ -1,28 +1,21 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.preStart = void 0;
7
4
  exports.start = start;
8
5
  exports.confirm = confirm;
9
- exports.exportTasksById = exportTasksById;
10
6
  /**
11
7
  * 返品取引サービス
12
8
  */
13
- const moment_timezone_1 = __importDefault(require("moment-timezone"));
9
+ const util_1 = require("util");
14
10
  const factory_1 = require("../../factory");
15
- const factory_2 = require("./returnOrder/exportTasks/factory");
16
11
  const potentialActions_1 = require("./returnOrder/potentialActions");
17
12
  const preStart_1 = require("./returnOrder/preStart");
18
13
  Object.defineProperty(exports, "preStart", { enumerable: true, get: function () { return preStart_1.preStart; } });
19
- const errorHandler_1 = require("../../errorHandler");
20
14
  /**
21
15
  * 返品取引開始
22
16
  */
23
- function start(params, options) {
17
+ function start(params) {
24
18
  return async (repos) => {
25
- const { useConfirmReturnOrderTask } = options;
26
19
  const { transactionObject, expiresInSeconds, seller } = await (0, preStart_1.preStart)(params)(repos);
27
20
  const returnOrderAttributes = {
28
21
  project: params.project,
@@ -36,23 +29,7 @@ function start(params, options) {
36
29
  object: transactionObject,
37
30
  expiresInSeconds
38
31
  };
39
- let returnOrderTransaction;
40
- if (useConfirmReturnOrderTask) {
41
- returnOrderTransaction = await repos.returnOrderInProgress.startReturnOrder(returnOrderAttributes);
42
- }
43
- else {
44
- try {
45
- returnOrderTransaction = await repos.returnOrder.startReturnOrder(returnOrderAttributes);
46
- }
47
- catch (error) {
48
- if (await (0, errorHandler_1.isMongoDuplicateError)(error)) {
49
- // 同一取引に対して返品取引を作成しようとすると、MongoDBでE11000 duplicate key errorが発生する
50
- throw new factory_1.factory.errors.Argument('orderNumber', 'Already returned');
51
- }
52
- throw error;
53
- }
54
- }
55
- return returnOrderTransaction;
32
+ return repos.returnOrderInProgress.startReturnOrder(returnOrderAttributes);
56
33
  };
57
34
  }
58
35
  function saveMessagesIfNeeded(params) {
@@ -84,26 +61,9 @@ function saveMessagesIfNeeded(params) {
84
61
  /**
85
62
  * 取引確定
86
63
  */
87
- function confirm(params, options) {
64
+ function confirm(params) {
88
65
  return async (repos) => {
89
- const { useConfirmReturnOrderTask } = options;
90
- let transaction;
91
- if (useConfirmReturnOrderTask) {
92
- transaction = await repos.returnOrderInProgress.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id });
93
- }
94
- else {
95
- transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result', 'startDate']);
96
- if (transaction.status === factory_1.factory.transactionStatusType.Confirmed) {
97
- // すでに確定済の場合
98
- return transaction.result;
99
- }
100
- else if (transaction.status === factory_1.factory.transactionStatusType.Expired) {
101
- throw new factory_1.factory.errors.Argument('transaction', 'Transaction already expired');
102
- }
103
- else if (transaction.status === factory_1.factory.transactionStatusType.Canceled) {
104
- throw new factory_1.factory.errors.Argument('transaction', 'Transaction already canceled');
105
- }
106
- }
66
+ const transaction = await repos.returnOrderInProgress.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id });
107
67
  if (typeof params.agent?.id === 'string' && transaction.agent.id !== params.agent.id) {
108
68
  throw new factory_1.factory.errors.Forbidden('Transaction not yours');
109
69
  }
@@ -112,7 +72,7 @@ function confirm(params, options) {
112
72
  throw new factory_1.factory.errors.Argument('object.order', 'number of orders must be 1');
113
73
  }
114
74
  const returningOrders = await repos.order.projectFields({
115
- limit: 1,
75
+ limit: 1, // 1に限定なので1で十分
116
76
  page: 1,
117
77
  project: { id: { $eq: transaction.project.id } },
118
78
  confirmationNumbers: [transaction.object.order[0].confirmationNumber],
@@ -123,6 +83,14 @@ function confirm(params, options) {
123
83
  'orderedItem', 'paymentMethods', 'price', 'priceCurrency', 'project', 'seller', 'typeOf'
124
84
  ]
125
85
  });
86
+ if (returningOrders.length === 0) {
87
+ throw new factory_1.factory.errors.NotFound(factory_1.factory.order.OrderType.Order);
88
+ }
89
+ // 既に返品済であれば400(2026-09-08~)
90
+ const orderStatus = returningOrders[0].orderStatus;
91
+ if (orderStatus === factory_1.factory.orderStatus.OrderReturned) {
92
+ throw new factory_1.factory.errors.Argument('orderNumber', `invalid orderStatus: ${orderStatus}`);
93
+ }
126
94
  const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['defaultSenderEmail']);
127
95
  if (typeof setting?.defaultSenderEmail !== 'string') {
128
96
  throw new factory_1.factory.errors.NotFound('setting.defaultSenderEmail');
@@ -142,70 +110,30 @@ function confirm(params, options) {
142
110
  project: { id: transaction.project.id },
143
111
  order: { orderNumber: returningOrders[0].orderNumber }, seller: { id: returningOrders[0].seller.id }, emailMessages
144
112
  })(repos);
145
- if (useConfirmReturnOrderTask) {
146
- // タスク作成
147
- const endDate = new Date();
148
- const task = {
149
- project: transaction.project,
150
- name: factory_1.factory.taskName.ConfirmReturnOrder,
151
- status: factory_1.factory.taskStatus.Ready,
152
- runsAt: endDate,
153
- remainingNumberOfTries: 10,
154
- numberOfTried: 0,
155
- executionResults: [],
156
- data: {
157
- typeOf: transaction.typeOf,
158
- id: transaction.id,
159
- agent: transaction.agent,
160
- startDate: transaction.startDate,
161
- object: transaction.object,
162
- project: transaction.project,
163
- potentialActions,
164
- endDate
165
- }
166
- };
167
- await repos.task.saveMany([task]);
168
- }
169
- else {
170
- // ステータス変更
171
- await repos.returnOrder.confirmReturnOrder({
113
+ // タスク作成(注文番号でユニークネス保証)
114
+ const taskIdentifier = (0, util_1.format)('%s:%s:%s', transaction.project.id, factory_1.factory.taskName.ConfirmReturnOrder, returningOrders[0].orderNumber);
115
+ const endDate = new Date();
116
+ const confirmReturnOrderTask = {
117
+ identifier: taskIdentifier,
118
+ project: transaction.project,
119
+ name: factory_1.factory.taskName.ConfirmReturnOrder,
120
+ status: factory_1.factory.taskStatus.Ready,
121
+ runsAt: endDate,
122
+ remainingNumberOfTries: 10,
123
+ numberOfTried: 0,
124
+ executionResults: [],
125
+ data: {
172
126
  typeOf: transaction.typeOf,
173
127
  id: transaction.id,
174
- result, potentialActions
175
- });
176
- }
128
+ agent: transaction.agent,
129
+ startDate: transaction.startDate,
130
+ object: transaction.object,
131
+ project: transaction.project,
132
+ potentialActions,
133
+ endDate
134
+ }
135
+ };
136
+ await repos.task.runTaskByIdentifier(confirmReturnOrderTask);
177
137
  return result;
178
138
  };
179
139
  }
180
- /**
181
- * 取引のタスクを出力します
182
- * 複数タスクが生成されます
183
- * この関数では、取引のタスクエクスポートステータスは見ません
184
- */
185
- function exportTasksById(params) {
186
- return async (repos) => {
187
- const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory_1.factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
188
- // タスク実行日時バッファの指定があれば調整
189
- let taskRunsAt = new Date();
190
- if (typeof params.runsTasksAfterInSeconds === 'number') {
191
- taskRunsAt = (0, moment_timezone_1.default)(taskRunsAt)
192
- .add(params.runsTasksAfterInSeconds, 'seconds')
193
- .toDate();
194
- }
195
- // search settings
196
- const setting = await repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
197
- const deleteTransactionTaskExpiresInDays = setting?.storage?.deleteTransactionTaskExpiresInDays;
198
- if (typeof deleteTransactionTaskExpiresInDays !== 'number') {
199
- throw new factory_1.factory.errors.Internal('settings.storage.deleteTransactionTaskExpiresInDays required');
200
- }
201
- const deleteTask = (0, factory_2.createScheduledTasks)({ transaction }, setting);
202
- // support scheduledTask(2026-08-02~)
203
- await repos.task.saveMany((0, factory_2.createImmediateTasks)({ transaction, taskRunsAt }));
204
- await repos.scheduledTask.addScheduledTasks([{
205
- ...deleteTask,
206
- expires: (0, moment_timezone_1.default)(deleteTask.runsAt)
207
- .add(deleteTransactionTaskExpiresInDays, 'days')
208
- .toDate()
209
- }]);
210
- };
211
- }
@@ -7,7 +7,6 @@ import type { ScheduledTaskRepo } from '../repo/scheduledTask';
7
7
  import type { TaskRepo } from '../repo/task';
8
8
  import type { TransactionRepo } from '../repo/transaction';
9
9
  import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
10
- import type { ReturnOrderRepo } from '../repo/transaction/returnOrder';
11
10
  import { deleteTransaction } from './transaction/deleteTransaction';
12
11
  import * as PlaceOrderTransactionService from './transaction/placeOrder';
13
12
  import * as ReturnOrderTransactionService from './transaction/returnOrder';
@@ -22,7 +21,6 @@ export type IExportTasksOperation<T> = (repos: {
22
21
  scheduledTask: ScheduledTaskRepo;
23
22
  task: TaskRepo;
24
23
  placeOrder: PlaceOrderRepo;
25
- returnOrder: ReturnOrderRepo;
26
24
  transaction: TransactionRepo;
27
25
  }) => Promise<T>;
28
26
  export declare function exportOneTransactionTasksIfExists(params: {
@@ -70,13 +70,7 @@ function exportOneTransactionTasksIfExists(params) {
70
70
  })(repos);
71
71
  break;
72
72
  case factory_1.factory.transactionType.ReturnOrder:
73
- await ReturnOrderTransactionService.exportTasksById({
74
- id: transaction.id,
75
- ...(typeof params.runsTasksAfterInSeconds === 'number')
76
- ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
77
- : undefined
78
- })(repos);
79
- break;
73
+ throw new factory_1.factory.errors.NotImplemented(`${factory_1.factory.transactionType.ReturnOrder} not implemented`);
80
74
  default:
81
75
  }
82
76
  await repos.transaction.setTasksExportedById({ id: transaction.id });
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": "27.1.0-alpha.8"
91
+ "version": "28.0.0-alpha.0"
92
92
  }
@@ -1,45 +0,0 @@
1
- import type { Connection, FilterQuery } from 'mongoose';
2
- import { factory } from '../../factory';
3
- type IKeyOfProjection = keyof Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf'> | Exclude<keyof factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'id'>;
4
- type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
5
- export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IStartedTransactionFields>;
6
- /**
7
- * 返品取引リポジトリ
8
- */
9
- export declare class ReturnOrderRepo {
10
- private readonly transactionModel;
11
- constructor(connection: Connection);
12
- static CREATE_MONGO_CONDITIONS(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder>): FilterQuery<import("@chevre/factory/lib/chevre/transaction/returnOrder").ITransaction>[];
13
- countReturnOrder(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder>): Promise<{
14
- count: number;
15
- }>;
16
- /**
17
- * 取引を検索する
18
- */
19
- findReturnOrderTransactions(params: factory.transaction.ISearchConditions<factory.transactionType.ReturnOrder> & {
20
- inclusion: IKeyOfProjection[];
21
- }): Promise<(Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IKeyOfProjection> & {
22
- id: string;
23
- })[]>;
24
- /**
25
- * 取引を開始する
26
- */
27
- startReturnOrder(params: factory.transaction.IStartParams<factory.transactionType.ReturnOrder>): Promise<IStartedTransaction>;
28
- /**
29
- * 特定取引検索
30
- */
31
- findReturnOrderById(params: {
32
- typeOf: factory.transactionType.ReturnOrder;
33
- id: string;
34
- }, inclusion: IKeyOfProjection[]): Promise<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>>;
35
- /**
36
- * 取引を確定する
37
- */
38
- confirmReturnOrder(params: {
39
- typeOf: factory.transactionType.ReturnOrder;
40
- id: string;
41
- result: factory.transaction.IResult<factory.transactionType.ReturnOrder>;
42
- potentialActions: factory.transaction.IPotentialActions<factory.transactionType.ReturnOrder>;
43
- }): Promise<void>;
44
- }
45
- export {};
@@ -1,294 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ReturnOrderRepo = void 0;
7
- const moment_1 = __importDefault(require("moment"));
8
- const transaction_1 = require("../../eventEmitter/transaction");
9
- const factory_1 = require("../../factory");
10
- const settings_1 = require("../../settings");
11
- const transaction_2 = require("../mongoose/schemas/transaction");
12
- const AVAILABLE_PROJECT_FIELDS = [
13
- 'project',
14
- 'status',
15
- 'typeOf',
16
- 'agent',
17
- 'recipient',
18
- 'seller',
19
- 'error',
20
- 'result',
21
- 'object',
22
- 'expires',
23
- 'startDate',
24
- 'endDate',
25
- 'tasksExportAction',
26
- 'potentialActions',
27
- // 'instrument'
28
- ];
29
- /**
30
- * 返品取引リポジトリ
31
- */
32
- class ReturnOrderRepo {
33
- transactionModel;
34
- constructor(connection) {
35
- this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
36
- }
37
- static CREATE_MONGO_CONDITIONS(params) {
38
- if (params.typeOf !== factory_1.factory.transactionType.ReturnOrder) {
39
- throw new factory_1.factory.errors.Argument('typeOf', `must be ${factory_1.factory.transactionType.ReturnOrder}`);
40
- }
41
- const andConditions = [];
42
- const projectIdEq = params.project?.id?.$eq;
43
- if (typeof projectIdEq === 'string') {
44
- andConditions.push({ 'project.id': { $eq: projectIdEq } });
45
- }
46
- if (typeof params.typeOf === 'string') {
47
- andConditions.push({ typeOf: { $eq: params.typeOf } });
48
- }
49
- if (params.startFrom !== undefined) {
50
- andConditions.push({
51
- startDate: { $gte: params.startFrom }
52
- });
53
- }
54
- if (params.startThrough !== undefined) {
55
- andConditions.push({
56
- startDate: { $lte: params.startThrough }
57
- });
58
- }
59
- if (params.endFrom !== undefined) {
60
- andConditions.push({
61
- endDate: {
62
- $exists: true,
63
- $gte: params.endFrom
64
- }
65
- });
66
- }
67
- if (params.endThrough !== undefined) {
68
- andConditions.push({
69
- endDate: {
70
- $exists: true,
71
- $lt: params.endThrough
72
- }
73
- });
74
- }
75
- if (Array.isArray(params.ids)) {
76
- andConditions.push({
77
- _id: { $in: params.ids }
78
- });
79
- }
80
- if (Array.isArray(params.statuses)) {
81
- andConditions.push({ status: { $in: params.statuses } });
82
- }
83
- const statusIn = params.status?.$in;
84
- if (Array.isArray(statusIn)) {
85
- andConditions.push({ status: { $in: statusIn } });
86
- }
87
- if (params.agent !== undefined) {
88
- if (params.agent.typeOf !== undefined) {
89
- andConditions.push({
90
- 'agent.typeOf': {
91
- $exists: true,
92
- $eq: params.agent.typeOf
93
- }
94
- });
95
- }
96
- if (Array.isArray(params.agent.ids)) {
97
- andConditions.push({
98
- 'agent.id': {
99
- $exists: true,
100
- $in: params.agent.ids
101
- }
102
- });
103
- }
104
- if (Array.isArray(params.agent.identifiers)) {
105
- andConditions.push({
106
- 'agent.identifier': {
107
- $exists: true,
108
- $in: params.agent.identifiers
109
- }
110
- });
111
- }
112
- }
113
- const tasksExportActionStatusIn = params.tasksExportAction?.actionStatus?.$in;
114
- if (Array.isArray(tasksExportActionStatusIn)) {
115
- andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $in: tasksExportActionStatusIn } });
116
- }
117
- const tasksExportActionStatusEq = params.tasksExportAction?.actionStatus?.$eq;
118
- if (typeof tasksExportActionStatusEq === 'string') {
119
- andConditions.push({ 'tasksExportAction.actionStatus': { $exists: true, $eq: tasksExportActionStatusEq } });
120
- }
121
- if (params.object !== undefined) {
122
- if (params.object.order !== undefined) {
123
- if (Array.isArray(params.object.order.orderNumbers)) {
124
- andConditions.push({
125
- 'object.order.orderNumber': {
126
- $exists: true,
127
- $in: params.object.order.orderNumbers
128
- }
129
- });
130
- }
131
- }
132
- }
133
- return andConditions;
134
- }
135
- async countReturnOrder(params) {
136
- const { limit } = params;
137
- const conditions = ReturnOrderRepo.CREATE_MONGO_CONDITIONS(params);
138
- const query = this.transactionModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {});
139
- if (typeof limit === 'number' && limit >= 0) {
140
- query.limit(limit);
141
- }
142
- const count = await query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
143
- .exec();
144
- return { count };
145
- }
146
- /**
147
- * 取引を検索する
148
- */
149
- async findReturnOrderTransactions(params) {
150
- const { inclusion } = params;
151
- const conditions = ReturnOrderRepo.CREATE_MONGO_CONDITIONS(params);
152
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
153
- if (Array.isArray(inclusion) && inclusion.length > 0) {
154
- positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
155
- }
156
- const projection = {
157
- _id: 0,
158
- id: { $toString: '$_id' },
159
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
160
- };
161
- const query = this.transactionModel.find((conditions.length > 0) ? { $and: conditions } : {})
162
- .select(projection);
163
- if (typeof params.limit === 'number' && params.limit > 0) {
164
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
165
- query.limit(params.limit)
166
- .skip(params.limit * (page - 1));
167
- }
168
- if (params.sort?.startDate !== undefined) {
169
- query.sort({ startDate: params.sort.startDate });
170
- }
171
- // const explainResult = await (<any>query).explain();
172
- // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
173
- return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
174
- .lean()
175
- .exec();
176
- }
177
- /**
178
- * 取引を開始する
179
- */
180
- async startReturnOrder(params) {
181
- const status = factory_1.factory.transactionStatusType.InProgress;
182
- const tasksExportAction = { actionStatus: factory_1.factory.actionStatusType.PotentialActionStatus };
183
- // const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
184
- const startDate = new Date();
185
- let expires;
186
- const { typeOf } = params;
187
- // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
188
- if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
189
- expires = (0, moment_1.default)(startDate)
190
- .add(params.expiresInSeconds, 'seconds')
191
- .toDate();
192
- }
193
- else {
194
- throw new factory_1.factory.errors.ArgumentNull('expiresInSeconds');
195
- }
196
- let creatingTransaction;
197
- if (typeOf === factory_1.factory.transactionType.ReturnOrder) {
198
- const { agent, project, object, seller } = params;
199
- creatingTransaction = {
200
- status, startDate, expires, typeOf, tasksExportAction,
201
- agent, project, seller, object
202
- };
203
- }
204
- else {
205
- throw new factory_1.factory.errors.NotImplemented(`${typeOf} not implemented`);
206
- }
207
- // reimplemnt with insertMany(2024-05-30~)
208
- const result = await this.transactionModel.insertMany(creatingTransaction, { rawResult: true });
209
- const id = result.insertedIds?.[0]?.toHexString();
210
- if (typeof id !== 'string') {
211
- throw new factory_1.factory.errors.Internal('transaction not saved');
212
- }
213
- // 取引開始時にも取引イベントエミッター連携(2024-03-21~)
214
- transaction_1.transactionEventEmitter.emitTransactionStatusChanged({ id, typeOf, status });
215
- return { expires, id, startDate, status }; // minimize response(2024-05-30~)
216
- }
217
- /**
218
- * 特定取引検索
219
- */
220
- async findReturnOrderById(params, inclusion // make required(2024-05-31~)
221
- ) {
222
- let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
223
- if (Array.isArray(inclusion) && inclusion.length > 0) {
224
- positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
225
- }
226
- else {
227
- throw new factory_1.factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
228
- }
229
- const projection = {
230
- _id: 0,
231
- id: { $toString: '$_id' },
232
- ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
233
- };
234
- const doc = await this.transactionModel.findOne({
235
- _id: { $eq: params.id },
236
- typeOf: { $eq: params.typeOf }
237
- }, projection)
238
- .lean() // 2024-08-26~
239
- .exec();
240
- if (doc === null) {
241
- throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
242
- }
243
- return doc;
244
- }
245
- /**
246
- * 取引を確定する
247
- */
248
- async confirmReturnOrder(params) {
249
- const endDate = new Date();
250
- const doc = await this.transactionModel.findOneAndUpdate({
251
- _id: { $eq: params.id },
252
- typeOf: { $eq: params.typeOf },
253
- status: { $eq: factory_1.factory.transactionStatusType.InProgress },
254
- expires: { $gt: endDate } // add expires(2025-02-27~)
255
- }, {
256
- status: factory_1.factory.transactionStatusType.Confirmed, // ステータス変更
257
- endDate,
258
- // 'object.authorizeActions': params.authorizeActions,
259
- result: params.result, // resultを更新
260
- potentialActions: params.potentialActions // resultを更新
261
- }, {
262
- new: true,
263
- projection: { _id: 1 }
264
- })
265
- .lean()
266
- .exec();
267
- // NotFoundであれば取引状態確認
268
- if (doc === null) {
269
- const { expires, status } = await this.findReturnOrderById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
270
- if (status === factory_1.factory.transactionStatusType.Confirmed) {
271
- // すでに確定済の場合スルー
272
- }
273
- else if (status === factory_1.factory.transactionStatusType.Expired) {
274
- throw new factory_1.factory.errors.Argument('Transaction id', 'Already expired');
275
- }
276
- else if (status === factory_1.factory.transactionStatusType.Canceled) {
277
- throw new factory_1.factory.errors.Argument('Transaction id', 'Already canceled');
278
- }
279
- else {
280
- if ((0, moment_1.default)(expires)
281
- .isSameOrBefore((0, moment_1.default)(endDate))) {
282
- throw new factory_1.factory.errors.Argument('Transaction id', 'potentially expired');
283
- }
284
- throw new factory_1.factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory_1.factory.transactionStatusType.InProgress} not found`);
285
- }
286
- }
287
- transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
288
- id: params.id,
289
- typeOf: params.typeOf,
290
- status: factory_1.factory.transactionStatusType.Confirmed
291
- });
292
- }
293
- }
294
- exports.ReturnOrderRepo = ReturnOrderRepo;
@@ -1,19 +0,0 @@
1
- import type { ISetting } from '../../../../repo/setting';
2
- import { factory } from '../../../../factory';
3
- type IReturnOrderPotentialTask = factory.task.IAttributes<factory.taskName.ReturnOrder>;
4
- /**
5
- * 取引のタスクを作成する
6
- * 取引削除タスクを分離(2026-08-02~)
7
- */
8
- export declare function createImmediateTasks(params: {
9
- transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'startDate' | 'object' | 'potentialActions'>;
10
- taskRunsAt: Date;
11
- }): IReturnOrderPotentialTask[];
12
- /**
13
- * 取引のタスクを作成する
14
- * 取引削除タスクを分離(2026-08-02~)
15
- */
16
- export declare function createScheduledTasks(params: {
17
- transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'object'>;
18
- }, setting: Pick<ISetting, 'storage'> | null): factory.task.deleteTransaction.IAttributes;
19
- export {};
@@ -1,104 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createImmediateTasks = createImmediateTasks;
7
- exports.createScheduledTasks = createScheduledTasks;
8
- const moment_1 = __importDefault(require("moment"));
9
- const factory_1 = require("../../../../factory");
10
- /**
11
- * 取引のタスクを作成する
12
- * 取引削除タスクを分離(2026-08-02~)
13
- */
14
- function createImmediateTasks(params) {
15
- const taskAttributes = [];
16
- const transaction = params.transaction;
17
- const taskRunsAt = params.taskRunsAt;
18
- switch (transaction.status) {
19
- case factory_1.factory.transactionStatusType.Confirmed: {
20
- const returnOrderPotentialActions = transaction.potentialActions?.returnOrder;
21
- if (Array.isArray(returnOrderPotentialActions)) {
22
- // 返品タスク
23
- const returnOrderTask = returnOrderPotentialActions.map((r) => {
24
- const { object, potentialActions, typeOf } = transaction;
25
- // data最適化(2023-08-22~)
26
- const returnOrderTaskData = {
27
- agent: r.agent,
28
- object: r.object,
29
- project: transaction.project,
30
- typeOf: r.typeOf,
31
- returnOrderTransaction: { object, potentialActions, typeOf } // add(2026-09-05~)
32
- };
33
- return {
34
- project: transaction.project,
35
- name: factory_1.factory.taskName.ReturnOrder,
36
- status: factory_1.factory.taskStatus.Ready,
37
- runsAt: taskRunsAt,
38
- remainingNumberOfTries: 10,
39
- numberOfTried: 0,
40
- executionResults: [],
41
- data: returnOrderTaskData
42
- };
43
- });
44
- taskAttributes.push(...returnOrderTask);
45
- }
46
- break;
47
- }
48
- case factory_1.factory.transactionStatusType.Expired:
49
- // 特にタスクなし
50
- break;
51
- default:
52
- throw new factory_1.factory.errors.NotImplemented(`Transaction status "${transaction.status}" not implemented.`);
53
- }
54
- return taskAttributes;
55
- }
56
- /**
57
- * 取引のタスクを作成する
58
- * 取引削除タスクを分離(2026-08-02~)
59
- */
60
- function createScheduledTasks(params, setting) {
61
- const transaction = params.transaction;
62
- const confirmedStoragePeriodInDays = setting?.storage?.transactionConfirmedInDays;
63
- const canceledStoragePeriodInDays = setting?.storage?.transactionCanceledInDays;
64
- if (typeof confirmedStoragePeriodInDays !== 'number') {
65
- throw new factory_1.factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
66
- }
67
- if (typeof canceledStoragePeriodInDays !== 'number') {
68
- throw new factory_1.factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
69
- }
70
- // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
71
- let deleteAt = (0, moment_1.default)(transaction.endDate)
72
- .add(confirmedStoragePeriodInDays, 'days')
73
- .toDate();
74
- switch (transaction.status) {
75
- case factory_1.factory.transactionStatusType.Confirmed:
76
- break;
77
- case factory_1.factory.transactionStatusType.Canceled:
78
- case factory_1.factory.transactionStatusType.Expired:
79
- deleteAt = (0, moment_1.default)(transaction.endDate)
80
- .add(canceledStoragePeriodInDays, 'days')
81
- .toDate();
82
- break;
83
- default:
84
- }
85
- return {
86
- project: transaction.project,
87
- name: factory_1.factory.taskName.DeleteTransaction,
88
- status: factory_1.factory.taskStatus.Ready,
89
- runsAt: deleteAt,
90
- remainingNumberOfTries: 3,
91
- numberOfTried: 0,
92
- executionResults: [],
93
- data: {
94
- object: {
95
- specifyingMethod: factory_1.factory.action.update.deleteAction.ObjectAsTransactionSpecifyingMethod.Id,
96
- id: transaction.id,
97
- object: {
98
- order: transaction.object.order
99
- },
100
- typeOf: transaction.typeOf,
101
- }
102
- }
103
- };
104
- }