@chevre/domain 24.0.0-alpha.13 → 24.0.0-alpha.15

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.
@@ -1,6 +1,8 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../../factory';
3
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>;
4
6
  /**
5
7
  * 返品取引リポジトリ
6
8
  */
@@ -19,5 +21,25 @@ export declare class ReturnOrderRepo {
19
21
  }): Promise<(Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, IKeyOfProjection> & {
20
22
  id: string;
21
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>;
22
44
  }
23
45
  export {};
@@ -22,12 +22,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.ReturnOrderRepo = void 0;
27
- // import { transactionEventEmitter } from '../../eventEmitter/transaction';
30
+ const moment_1 = __importDefault(require("moment"));
31
+ const transaction_1 = require("../../eventEmitter/transaction");
28
32
  const factory = __importStar(require("../../factory"));
29
33
  const settings_1 = require("../../settings");
30
- const transaction_1 = require("../mongoose/schemas/transaction");
34
+ const transaction_2 = require("../mongoose/schemas/transaction");
31
35
  const AVAILABLE_PROJECT_FIELDS = [
32
36
  'project',
33
37
  'status',
@@ -45,17 +49,13 @@ const AVAILABLE_PROJECT_FIELDS = [
45
49
  'potentialActions',
46
50
  // 'instrument'
47
51
  ];
48
- // type IOmittedFieldsInProgress = 'tasksExportAction' | 'tasksExportedAt' | 'tasksExportationStatus';
49
- // export type IMoneyTransferTransactionInProgress = Omit<factory.transaction.moneyTransfer.ITransaction, IOmittedFieldsInProgress>;
50
- // type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
51
- // export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType>, IStartedTransactionFields>;
52
52
  /**
53
53
  * 返品取引リポジトリ
54
54
  */
55
55
  class ReturnOrderRepo {
56
56
  transactionModel;
57
57
  constructor(connection) {
58
- this.transactionModel = connection.model(transaction_1.modelName, (0, transaction_1.createSchema)());
58
+ this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
59
59
  }
60
60
  static CREATE_MONGO_CONDITIONS(params) {
61
61
  if (params.typeOf !== factory.transactionType.ReturnOrder) {
@@ -209,5 +209,133 @@ class ReturnOrderRepo {
209
209
  .lean()
210
210
  .exec();
211
211
  }
212
+ /**
213
+ * 取引を開始する
214
+ */
215
+ async startReturnOrder(params) {
216
+ const status = factory.transactionStatusType.InProgress;
217
+ const tasksExportAction = { actionStatus: factory.actionStatusType.PotentialActionStatus };
218
+ // const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
219
+ const startDate = new Date();
220
+ let expires;
221
+ const { typeOf } = params;
222
+ // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
223
+ if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
224
+ expires = (0, moment_1.default)(startDate)
225
+ .add(params.expiresInSeconds, 'seconds')
226
+ .toDate();
227
+ }
228
+ else {
229
+ throw new factory.errors.ArgumentNull('expiresInSeconds');
230
+ }
231
+ let creatingTransaction;
232
+ if (typeOf === factory.transactionType.ReturnOrder) {
233
+ const { agent, project, object, seller } = params;
234
+ creatingTransaction = {
235
+ status, startDate, expires, typeOf, tasksExportAction,
236
+ agent, project, seller, object
237
+ };
238
+ }
239
+ else {
240
+ throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
241
+ }
242
+ // reimplemnt with insertMany(2024-05-30~)
243
+ const result = await this.transactionModel.insertMany(creatingTransaction, { rawResult: true });
244
+ const id = result.insertedIds?.[0]?.toHexString();
245
+ if (typeof id !== 'string') {
246
+ throw new factory.errors.Internal('transaction not saved');
247
+ }
248
+ // 取引開始時にも取引イベントエミッター連携(2024-03-21~)
249
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({ id, typeOf, status });
250
+ return { expires, id, startDate, status }; // minimize response(2024-05-30~)
251
+ }
252
+ /**
253
+ * 特定取引検索
254
+ */
255
+ async findReturnOrderById(params, inclusion // make required(2024-05-31~)
256
+ ) {
257
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
258
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
259
+ positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
260
+ }
261
+ else {
262
+ throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
263
+ }
264
+ const projection = {
265
+ _id: 0,
266
+ id: { $toString: '$_id' },
267
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
268
+ };
269
+ // let projection: { [key in (IKeyOfProjection<T> | '__v' | 'createdAt' | 'updatedAt')]?: AnyExpression } = {};
270
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
271
+ // inclusion.forEach((field) => {
272
+ // projection[field] = 1;
273
+ // });
274
+ // } else {
275
+ // projection = {
276
+ // __v: 0,
277
+ // createdAt: 0,
278
+ // updatedAt: 0
279
+ // };
280
+ // }
281
+ const doc = await this.transactionModel.findOne({
282
+ _id: { $eq: params.id },
283
+ typeOf: { $eq: params.typeOf }
284
+ }, projection)
285
+ .lean() // 2024-08-26~
286
+ .exec();
287
+ if (doc === null) {
288
+ throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
289
+ }
290
+ return doc;
291
+ }
292
+ /**
293
+ * 取引を確定する
294
+ */
295
+ async confirmReturnOrder(params) {
296
+ const endDate = new Date();
297
+ const doc = await this.transactionModel.findOneAndUpdate({
298
+ _id: { $eq: params.id },
299
+ typeOf: { $eq: params.typeOf },
300
+ status: { $eq: factory.transactionStatusType.InProgress },
301
+ expires: { $gt: endDate } // add expires(2025-02-27~)
302
+ }, {
303
+ status: factory.transactionStatusType.Confirmed, // ステータス変更
304
+ endDate,
305
+ // 'object.authorizeActions': params.authorizeActions,
306
+ result: params.result, // resultを更新
307
+ potentialActions: params.potentialActions // resultを更新
308
+ }, {
309
+ new: true,
310
+ projection: { _id: 1 }
311
+ })
312
+ .lean()
313
+ .exec();
314
+ // NotFoundであれば取引状態確認
315
+ if (doc === null) {
316
+ const { expires, status } = await this.findReturnOrderById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
317
+ if (status === factory.transactionStatusType.Confirmed) {
318
+ // すでに確定済の場合スルー
319
+ }
320
+ else if (status === factory.transactionStatusType.Expired) {
321
+ throw new factory.errors.Argument('Transaction id', 'Already expired');
322
+ }
323
+ else if (status === factory.transactionStatusType.Canceled) {
324
+ throw new factory.errors.Argument('Transaction id', 'Already canceled');
325
+ }
326
+ else {
327
+ if ((0, moment_1.default)(expires)
328
+ .isSameOrBefore((0, moment_1.default)(endDate))) {
329
+ throw new factory.errors.Argument('Transaction id', 'potentially expired');
330
+ }
331
+ throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
332
+ }
333
+ }
334
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
335
+ id: params.id,
336
+ typeOf: params.typeOf,
337
+ status: factory.transactionStatusType.Confirmed
338
+ });
339
+ }
212
340
  }
213
341
  exports.ReturnOrderRepo = ReturnOrderRepo;
@@ -1,6 +1,6 @@
1
1
  import type { Connection, FilterQuery } from 'mongoose';
2
2
  import * as factory from '../factory';
3
- type IKeyOfProjection<T extends factory.transactionType> = keyof Pick<factory.transaction.ITransaction<factory.transactionType>, 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf'> | Exclude<keyof factory.transaction.ITransaction<T>, 'id'>;
3
+ type IKeyOfProjection = keyof Pick<factory.transaction.ITransaction<factory.transactionType.MoneyTransfer>, 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf'> | Exclude<keyof factory.transaction.ITransaction<factory.transactionType.MoneyTransfer>, 'id'>;
4
4
  interface IAggregationByStatus {
5
5
  transactionCount: number;
6
6
  avgDuration: number;
@@ -32,29 +32,29 @@ export declare class TransactionRepo {
32
32
  /**
33
33
  * 取引を開始する
34
34
  */
35
- startNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: factory.transaction.IStartParams<T>): Promise<IStartedTransaction>;
35
+ startMoneyTransfer(params: factory.transaction.IStartParams<factory.transactionType.MoneyTransfer>): Promise<IStartedTransaction>;
36
36
  /**
37
37
  * 特定取引検索
38
38
  */
39
- projectFieldsByIdNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
40
- typeOf: T;
39
+ findMoneyTransferById(params: {
40
+ typeOf: factory.transactionType.MoneyTransfer;
41
41
  id: string;
42
- }, inclusion: IKeyOfProjection<T>[]): Promise<factory.transaction.ITransaction<T>>;
42
+ }, inclusion: IKeyOfProjection[]): Promise<factory.transaction.ITransaction<factory.transactionType.MoneyTransfer>>;
43
43
  /**
44
44
  * 進行中の取引を取得する
45
45
  */
46
46
  findMoneyTransferInProgressById(params: {
47
47
  typeOf: factory.transactionType.MoneyTransfer;
48
48
  id: string;
49
- }, inclusion: IKeyOfProjection<factory.transactionType.MoneyTransfer>[]): Promise<IMoneyTransferTransactionInProgress>;
49
+ }, inclusion: IKeyOfProjection[]): Promise<IMoneyTransferTransactionInProgress>;
50
50
  /**
51
51
  * 取引を確定する
52
52
  */
53
- confirmNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
54
- typeOf: T;
53
+ confirmMoneyTransfer(params: {
54
+ typeOf: factory.transactionType.MoneyTransfer;
55
55
  id: string;
56
- result: factory.transaction.IResult<T>;
57
- potentialActions: factory.transaction.IPotentialActions<T>;
56
+ result: factory.transaction.IResult<factory.transactionType.MoneyTransfer>;
57
+ potentialActions: factory.transaction.IPotentialActions<factory.transactionType.MoneyTransfer>;
58
58
  }): Promise<void>;
59
59
  countPotentiallyExportTasks(params: {
60
60
  endDate: {
@@ -144,8 +144,8 @@ export declare class TransactionRepo {
144
144
  /**
145
145
  * 取引を中止する
146
146
  */
147
- cancelNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
148
- typeOf: T;
147
+ cancelMoneyTransfer(params: {
148
+ typeOf: factory.transactionType.MoneyTransfer;
149
149
  id: string;
150
150
  }): Promise<void>;
151
151
  countMoneyTransfer<T extends factory.transactionType.MoneyTransfer>(params: factory.transaction.ISearchConditions<T>): Promise<{
@@ -154,7 +154,7 @@ export declare class TransactionRepo {
154
154
  /**
155
155
  * 取引を検索する
156
156
  */
157
- findMoneyTransferTransactions<T extends factory.transactionType.MoneyTransfer, F extends IKeyOfProjection<T>>(params: factory.transaction.ISearchConditions<T> & {
157
+ findMoneyTransferTransactions<T extends factory.transactionType.MoneyTransfer, F extends IKeyOfProjection>(params: factory.transaction.ISearchConditions<T> & {
158
158
  inclusion: F[];
159
159
  }): Promise<(Pick<factory.transaction.ITransaction<T>, F> & {
160
160
  id: string;
@@ -47,7 +47,7 @@ const AVAILABLE_PROJECT_FIELDS = [
47
47
  'endDate',
48
48
  'tasksExportAction',
49
49
  'potentialActions',
50
- 'instrument'
50
+ // 'instrument'
51
51
  ];
52
52
  /**
53
53
  * 取引リポジトリ
@@ -185,27 +185,27 @@ class TransactionRepo {
185
185
  /**
186
186
  * 取引を開始する
187
187
  */
188
- async startNoPlaceOrder(params) {
188
+ // public async startNoPlaceOrder<
189
+ async startMoneyTransfer(params) {
189
190
  const status = factory.transactionStatusType.InProgress;
190
191
  const tasksExportAction = { actionStatus: factory.actionStatusType.PotentialActionStatus };
191
192
  // const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
192
193
  const startDate = new Date();
193
- let expires;
194
+ // let expires: Date;
194
195
  const { typeOf } = params;
195
- if (typeOf === factory.transactionType.ReturnOrder) {
196
- // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
197
- if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
198
- expires = (0, moment_1.default)(startDate)
199
- .add(params.expiresInSeconds, 'seconds')
200
- .toDate();
201
- }
202
- else {
203
- throw new factory.errors.ArgumentNull('expiresInSeconds');
204
- }
205
- }
206
- else {
207
- expires = params.expires;
208
- }
196
+ // if (typeOf === factory.transactionType.ReturnOrder) {
197
+ // // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
198
+ // if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
199
+ // expires = moment(startDate)
200
+ // .add(params.expiresInSeconds, 'seconds')
201
+ // .toDate();
202
+ // } else {
203
+ // throw new factory.errors.ArgumentNull('expiresInSeconds');
204
+ // }
205
+ // } else {
206
+ // expires = params.expires;
207
+ // }
208
+ const expires = params.expires;
209
209
  let creatingTransaction;
210
210
  if (typeOf === factory.transactionType.MoneyTransfer) {
211
211
  const { agent, project, object, seller, recipient } = params;
@@ -213,13 +213,12 @@ class TransactionRepo {
213
213
  status, startDate, expires, typeOf, tasksExportAction,
214
214
  agent, project, seller, object, recipient
215
215
  };
216
- }
217
- else if (typeOf === factory.transactionType.ReturnOrder) {
218
- const { agent, project, object, seller } = params;
219
- creatingTransaction = {
220
- status, startDate, expires, typeOf, tasksExportAction,
221
- agent, project, seller, object
222
- };
216
+ // } else if (typeOf === factory.transactionType.ReturnOrder) {
217
+ // const { agent, project, object, seller } = params;
218
+ // creatingTransaction = {
219
+ // status, startDate, expires, typeOf, tasksExportAction,
220
+ // agent, project, seller, object
221
+ // };
223
222
  }
224
223
  else {
225
224
  throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
@@ -237,7 +236,7 @@ class TransactionRepo {
237
236
  /**
238
237
  * 特定取引検索
239
238
  */
240
- async projectFieldsByIdNoPlaceOrder(params, inclusion // make required(2024-05-31~)
239
+ async findMoneyTransferById(params, inclusion // make required(2024-05-31~)
241
240
  ) {
242
241
  let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
243
242
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -528,7 +527,8 @@ class TransactionRepo {
528
527
  /**
529
528
  * 取引を確定する
530
529
  */
531
- async confirmNoPlaceOrder(params) {
530
+ // public async confirmNoPlaceOrder<
531
+ async confirmMoneyTransfer(params) {
532
532
  const endDate = new Date();
533
533
  const doc = await this.transactionModel.findOneAndUpdate({
534
534
  _id: { $eq: params.id },
@@ -549,7 +549,7 @@ class TransactionRepo {
549
549
  .exec();
550
550
  // NotFoundであれば取引状態確認
551
551
  if (doc === null) {
552
- const { expires, status } = await this.projectFieldsByIdNoPlaceOrder({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
552
+ const { expires, status } = await this.findMoneyTransferById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
553
553
  if (status === factory.transactionStatusType.Confirmed) {
554
554
  // すでに確定済の場合スルー
555
555
  }
@@ -897,7 +897,7 @@ class TransactionRepo {
897
897
  /**
898
898
  * 取引を中止する
899
899
  */
900
- async cancelNoPlaceOrder(params) {
900
+ async cancelMoneyTransfer(params) {
901
901
  const endDate = new Date();
902
902
  // 進行中ステータスの取引を中止する
903
903
  const doc = await this.transactionModel.findOneAndUpdate({
@@ -915,7 +915,7 @@ class TransactionRepo {
915
915
  .exec();
916
916
  // NotFoundであれば取引状態確認
917
917
  if (doc === null) {
918
- const { status } = await this.projectFieldsByIdNoPlaceOrder(params, ['status']);
918
+ const { status } = await this.findMoneyTransferById(params, ['status']);
919
919
  if (status === factory.transactionStatusType.Canceled) {
920
920
  // すでに中止済の場合スルー
921
921
  }
@@ -2,13 +2,14 @@ import * as factory from '../../factory';
2
2
  import type { ActionRepo } from '../../repo/action';
3
3
  import type { PotentialActionRepo } from '../../repo/potentialAction';
4
4
  import type { SettingRepo } from '../../repo/setting';
5
+ interface ITriggerWebhookRepos {
6
+ action: ActionRepo;
7
+ potentialAction: PotentialActionRepo;
8
+ setting: SettingRepo;
9
+ }
5
10
  declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook> & {
6
11
  project: {
7
12
  id: string;
8
13
  };
9
- }): (repos: {
10
- action: ActionRepo;
11
- potentialAction: PotentialActionRepo;
12
- setting: SettingRepo;
13
- }) => Promise<void>;
14
- export { triggerWebhook };
14
+ }): (repos: ITriggerWebhookRepos) => Promise<void>;
15
+ export { ITriggerWebhookRepos, triggerWebhook };
@@ -40,4 +40,4 @@ declare function voidTransactionByActionId(params: factory.task.IData<factory.ta
40
40
  id: string;
41
41
  };
42
42
  }): (repos: IVoidTransactionByActionIdRepos, settings: Settings) => Promise<void>;
43
- export { voidTransactionByActionId };
43
+ export { IVoidTransactionByActionIdRepos, voidTransactionByActionId };
@@ -1,14 +1,13 @@
1
1
  import * as factory from '../../../factory';
2
2
  import type { SettingRepo } from '../../../repo/setting';
3
3
  import type { TaskRepo } from '../../../repo/task';
4
- type IPlaceOrderTransaction = Pick<factory.transaction.placeOrder.ITransaction, 'id' | 'project' | 'typeOf' | 'potentialActions'>;
4
+ interface IOnOrderDeliveredRepos {
5
+ setting: SettingRepo;
6
+ task: TaskRepo;
7
+ }
5
8
  declare function onOrderDelivered(params: {
6
9
  order: Pick<factory.order.IOrder, 'id' | 'customer' | 'orderDate' | 'orderNumber' | 'project' | 'typeOf' | 'price' | 'priceCurrency'> & {
7
10
  orderStatus: factory.orderStatus.OrderDelivered;
8
11
  };
9
- placeOrderTransaction?: IPlaceOrderTransaction;
10
- }): (repos: {
11
- setting: SettingRepo;
12
- task: TaskRepo;
13
- }) => Promise<void>;
14
- export { onOrderDelivered };
12
+ }): (repos: IOnOrderDeliveredRepos) => Promise<void>;
13
+ export { IOnOrderDeliveredRepos, onOrderDelivered };
@@ -1,10 +1,11 @@
1
1
  import type { SettingRepo } from '../../../repo/setting';
2
2
  import type { TaskRepo } from '../../../repo/task';
3
3
  import { IInTransitOrder } from './onOrderDeliveredPartially/factory';
4
- declare function onOrderDeliveredPartially(params: {
5
- order: IInTransitOrder;
6
- }): (repos: {
4
+ interface IOnOrderDeliveredPartiallyRepos {
7
5
  setting: SettingRepo;
8
6
  task: TaskRepo;
9
- }) => Promise<void>;
10
- export { onOrderDeliveredPartially };
7
+ }
8
+ declare function onOrderDeliveredPartially(params: {
9
+ order: IInTransitOrder;
10
+ }): (repos: IOnOrderDeliveredPartiallyRepos) => Promise<void>;
11
+ export { IOnOrderDeliveredPartiallyRepos, onOrderDeliveredPartially };
@@ -30,7 +30,7 @@ exports.sendOrder = sendOrder;
30
30
  const debug_1 = __importDefault(require("debug"));
31
31
  // import { createMaskedCustomer } from '../../factory/order';
32
32
  const factory_1 = require("../delivery/factory");
33
- const findPlaceOrderTransaction_1 = require("./findPlaceOrderTransaction");
33
+ // import { findPlaceOrderTransaction } from './findPlaceOrderTransaction';
34
34
  const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
35
35
  const factory = __importStar(require("../../factory"));
36
36
  // import { Settings } from '../../settings';
@@ -60,11 +60,11 @@ function sendOrder(params) {
60
60
  try {
61
61
  const orderNumber = params.object.orderNumber;
62
62
  const confirmationNumber = params.object.confirmationNumber;
63
- const placeOrderTransaction = await (0, findPlaceOrderTransaction_1.findPlaceOrderTransaction)({
64
- project: { id: params.project.id },
65
- confirmationNumber,
66
- orderNumber
67
- })(repos);
63
+ // const placeOrderTransaction = await findPlaceOrderTransaction({
64
+ // project: { id: params.project.id },
65
+ // confirmationNumber,
66
+ // orderNumber
67
+ // })(repos);
68
68
  // 注文取得
69
69
  let order = await repos.order.projectFieldsByOrderNumber({
70
70
  orderNumber,
@@ -182,8 +182,8 @@ function sendOrder(params) {
182
182
  orderStatus: factory.orderStatus.OrderDelivered,
183
183
  price: order.price,
184
184
  priceCurrency: order.priceCurrency
185
- },
186
- placeOrderTransaction
185
+ }
186
+ // placeOrderTransaction
187
187
  })(repos);
188
188
  }
189
189
  else {
@@ -5,9 +5,13 @@ import * as factory from '../../../factory';
5
5
  import type { AccountingReportRepo } from '../../../repo/accountingReport';
6
6
  import type { ActionRepo } from '../../../repo/action';
7
7
  import type { TaskRepo } from '../../../repo/task';
8
- declare function onPayActionCompleted(payAction: Pick<factory.action.trade.pay.IAction, 'id' | 'object' | 'potentialActions' | 'project' | 'purpose' | 'typeOf'>): (repos: {
8
+ interface IOnPayActionCompletedRepos {
9
9
  action: ActionRepo;
10
10
  accountingReport: AccountingReportRepo;
11
11
  task: TaskRepo;
12
- }) => Promise<void>;
13
- export { onPayActionCompleted };
12
+ }
13
+ /**
14
+ * 決済アクション完了時処理
15
+ */
16
+ declare function onPayActionCompleted(payAction: Pick<factory.action.trade.pay.IAction, 'id' | 'object' | 'potentialActions' | 'project' | 'purpose' | 'typeOf'>): (repos: IOnPayActionCompletedRepos) => Promise<void>;
17
+ export { IOnPayActionCompletedRepos, onPayActionCompleted };
@@ -30,6 +30,9 @@ exports.onPayActionCompleted = onPayActionCompleted;
30
30
  const factory = __importStar(require("../../../factory"));
31
31
  const factory_1 = require("./factory");
32
32
  const onPaymentStatusChanged_1 = require("./onPaymentStatusChanged");
33
+ /**
34
+ * 決済アクション完了時処理
35
+ */
33
36
  function onPayActionCompleted(payAction) {
34
37
  return async (repos) => {
35
38
  const aciton4inform = (0, factory_1.optimizeAction4inform)(payAction);
@@ -72,7 +72,7 @@ function start(params) {
72
72
  const { transactionNumber } = await repos.transactionNumber.publishByTimestamp({ startDate: new Date() });
73
73
  // 取引開始
74
74
  const startParams = (0, factory_2.createStartParams)(params, passport, seller, amount, fromLocation, toLocation, transactionNumber);
75
- const transaction = await repos.transaction.startNoPlaceOrder(startParams);
75
+ const transaction = await repos.transaction.startMoneyTransfer(startParams);
76
76
  await authorizePaymentCard({
77
77
  transaction: {
78
78
  ...transaction,
@@ -566,7 +566,7 @@ function validateToLocation(project, toLocationBeforeStart, issuedThrough) {
566
566
  function confirm(params) {
567
567
  return async (repos) => {
568
568
  const now = new Date();
569
- const transaction = await repos.transaction.projectFieldsByIdNoPlaceOrder({
569
+ const transaction = await repos.transaction.findMoneyTransferById({
570
570
  typeOf: factory.transactionType.MoneyTransfer,
571
571
  id: params.id
572
572
  }, ['typeOf', 'status', 'project']);
@@ -591,7 +591,7 @@ function confirm(params) {
591
591
  // ポストアクションを作成
592
592
  const potentialActions = await (0, potentialActions_1.createPotentialActions)({ authorizeActions, transaction });
593
593
  // 取引確定
594
- await repos.transaction.confirmNoPlaceOrder({
594
+ await repos.transaction.confirmMoneyTransfer({
595
595
  typeOf: factory.transactionType.MoneyTransfer,
596
596
  id: transaction.id,
597
597
  result: {},
@@ -625,7 +625,7 @@ function exportTasksById(params) {
625
625
  return async (repos
626
626
  // settings: Settings
627
627
  ) => {
628
- const transaction = await repos.transaction.projectFieldsByIdNoPlaceOrder({
628
+ const transaction = await repos.transaction.findMoneyTransferById({
629
629
  typeOf: factory.transactionType.MoneyTransfer,
630
630
  id: params.id
631
631
  }, ['endDate', 'status', 'project', 'startDate', 'typeOf', 'object', 'potentialActions']);
@@ -31,4 +31,4 @@ declare function preStart(params: factory.transaction.returnOrder.IStartParamsWi
31
31
  seller: IFixedSeller;
32
32
  expiresInSeconds: number;
33
33
  }>;
34
- export { preStart };
34
+ export { IPreStartOperationRepos, preStart };
@@ -13,7 +13,7 @@ import type { SellerRepo } from '../../repo/seller';
13
13
  import type { SellerReturnPolicyRepo } from '../../repo/sellerReturnPolicy';
14
14
  import type { SettingRepo } from '../../repo/setting';
15
15
  import type { TaskRepo } from '../../repo/task';
16
- import type { IStartedTransaction, TransactionRepo } from '../../repo/transaction';
16
+ import type { IStartedTransaction, ReturnOrderRepo } from '../../repo/transaction/returnOrder';
17
17
  import { preStart } from './returnOrder/preStart';
18
18
  interface IStartOperationRepos {
19
19
  acceptedOffer: AcceptedOfferRepo;
@@ -26,18 +26,27 @@ interface IStartOperationRepos {
26
26
  reservation: ReservationRepo;
27
27
  seller: SellerRepo;
28
28
  sellerReturnPolicy: SellerReturnPolicyRepo;
29
- transaction: TransactionRepo;
29
+ returnOrder: ReturnOrderRepo;
30
30
  }
31
31
  type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
32
- type ITaskAndTransactionOperation<T> = (repos: {
32
+ interface IExportTasksByIdRepos {
33
33
  setting: SettingRepo;
34
34
  task: TaskRepo;
35
- transaction: TransactionRepo;
36
- }) => Promise<T>;
35
+ returnOrder: ReturnOrderRepo;
36
+ }
37
+ type ITaskAndTransactionOperation<T> = (repos: IExportTasksByIdRepos) => Promise<T>;
37
38
  /**
38
39
  * 返品取引開始
39
40
  */
40
41
  declare function start(params: factory.transaction.returnOrder.IStartParamsWithoutDetail): IStartOperation<IStartedTransaction>;
42
+ interface IConfirmRepos {
43
+ acceptedOffer: AcceptedOfferRepo;
44
+ emailMessage?: EmailMessageRepo;
45
+ message: MessageRepo;
46
+ order: OrderRepo;
47
+ setting: SettingRepo;
48
+ returnOrder: ReturnOrderRepo;
49
+ }
41
50
  /**
42
51
  * 取引確定
43
52
  */
@@ -47,14 +56,7 @@ declare function confirm(params: factory.transaction.returnOrder.IConfirmParams
47
56
  dateReturned: Date;
48
57
  };
49
58
  };
50
- }): (repos: {
51
- acceptedOffer: AcceptedOfferRepo;
52
- emailMessage?: EmailMessageRepo;
53
- message: MessageRepo;
54
- order: OrderRepo;
55
- setting: SettingRepo;
56
- transaction: TransactionRepo;
57
- }) => Promise<import("@chevre/factory/lib/transaction/returnOrder").IResult | undefined>;
59
+ }): (repos: IConfirmRepos) => Promise<import("@chevre/factory/lib/transaction/returnOrder").IResult | undefined>;
58
60
  /**
59
61
  * 取引のタスクを出力します
60
62
  * 複数タスクが生成されます
@@ -67,4 +69,4 @@ declare function exportTasksById(params: {
67
69
  */
68
70
  runsTasksAfterInSeconds?: number;
69
71
  }): ITaskAndTransactionOperation<void>;
70
- export { preStart, start, confirm, exportTasksById };
72
+ export { IStartOperationRepos, IConfirmRepos, IExportTasksByIdRepos, preStart, start, confirm, exportTasksById };
@@ -60,7 +60,7 @@ function start(params) {
60
60
  };
61
61
  let returnOrderTransaction;
62
62
  try {
63
- returnOrderTransaction = await repos.transaction.startNoPlaceOrder(returnOrderAttributes);
63
+ returnOrderTransaction = await repos.returnOrder.startReturnOrder(returnOrderAttributes);
64
64
  }
65
65
  catch (error) {
66
66
  if (await (0, errorHandler_1.isMongoError)(error)) {
@@ -108,7 +108,7 @@ function confirm(params) {
108
108
  return async (repos
109
109
  // settings: Settings
110
110
  ) => {
111
- const transaction = await repos.transaction.projectFieldsByIdNoPlaceOrder({ typeOf: factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result']);
111
+ const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'agent', 'object', 'result']);
112
112
  if (transaction.status === factory.transactionStatusType.Confirmed) {
113
113
  // すでに確定済の場合
114
114
  return transaction.result;
@@ -169,7 +169,7 @@ function confirm(params) {
169
169
  order: { orderNumber: returningOrders[0].orderNumber }, seller: { id: returningOrders[0].seller.id }, emailMessages
170
170
  })(repos);
171
171
  // ステータス変更
172
- await repos.transaction.confirmNoPlaceOrder({
172
+ await repos.returnOrder.confirmReturnOrder({
173
173
  typeOf: transaction.typeOf,
174
174
  id: transaction.id,
175
175
  result, potentialActions
@@ -186,7 +186,7 @@ function exportTasksById(params) {
186
186
  return async (repos
187
187
  // settings: Settings
188
188
  ) => {
189
- const transaction = await repos.transaction.projectFieldsByIdNoPlaceOrder({ typeOf: factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
189
+ const transaction = await repos.returnOrder.findReturnOrderById({ typeOf: factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
190
190
  // タスク実行日時バッファの指定があれば調整
191
191
  let taskRunsAt = new Date();
192
192
  if (typeof params.runsTasksAfterInSeconds === 'number') {
@@ -6,6 +6,7 @@ import type { SettingRepo } from '../repo/setting';
6
6
  import type { TaskRepo } from '../repo/task';
7
7
  import type { TransactionRepo } from '../repo/transaction';
8
8
  import type { PlaceOrderRepo } from '../repo/transaction/placeOrder';
9
+ import type { ReturnOrderRepo } from '../repo/transaction/returnOrder';
9
10
  import { deleteTransaction } from './transaction/deleteTransaction';
10
11
  import * as MoneyTransferTransactionService from './transaction/moneyTransfer';
11
12
  import * as PlaceOrderTransactionService from './transaction/placeOrder';
@@ -21,6 +22,7 @@ export type IExportTasksOperation<T> = (repos: {
21
22
  setting: SettingRepo;
22
23
  task: TaskRepo;
23
24
  placeOrder: PlaceOrderRepo;
25
+ returnOrder: ReturnOrderRepo;
24
26
  transaction: TransactionRepo;
25
27
  }) => Promise<T>;
26
28
  export declare function exportOneTransactionTasksIfExists(params: {
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.13"
102
+ "version": "24.0.0-alpha.15"
103
103
  }