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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/lib/chevre/repo/transaction/placeOrder.d.ts +56 -4
  2. package/lib/chevre/repo/transaction/placeOrder.js +214 -2
  3. package/lib/chevre/repo/transaction.d.ts +8 -19
  4. package/lib/chevre/repo/transaction.js +87 -58
  5. package/lib/chevre/service/offer/event/authorize.d.ts +0 -2
  6. package/lib/chevre/service/offer/event/authorize.js +1 -1
  7. package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +2 -2
  8. package/lib/chevre/service/offer/event/issueEventOfferTicket.js +1 -1
  9. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.d.ts +0 -2
  10. package/lib/chevre/service/offer/event/voidTransaction/processVoidTransaction4chevre.js +1 -0
  11. package/lib/chevre/service/offer/event/voidTransaction.d.ts +0 -2
  12. package/lib/chevre/service/offer/event/voidTransaction.js +2 -2
  13. package/lib/chevre/service/offer/event/voidTransactionByActionId.d.ts +0 -2
  14. package/lib/chevre/service/offer/event/voidTransactionByActionId.js +1 -1
  15. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.d.ts +0 -2
  16. package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +2 -2
  17. package/lib/chevre/service/offer/eventServiceByCOA/authorize.d.ts +0 -2
  18. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +1 -1
  19. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -1
  20. package/lib/chevre/service/offer/moneyTransfer/authorize.d.ts +0 -2
  21. package/lib/chevre/service/offer/moneyTransfer/authorize.js +4 -1
  22. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.d.ts +2 -2
  23. package/lib/chevre/service/offer/moneyTransfer/voidTransaction.js +4 -1
  24. package/lib/chevre/service/offer/product.d.ts +1 -3
  25. package/lib/chevre/service/offer/product.js +2 -2
  26. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +2 -3
  27. package/lib/chevre/service/payment/any/authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts +2 -3
  28. package/lib/chevre/service/payment/any/fixOrderAsNeeded.d.ts +0 -2
  29. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +2 -2
  30. package/lib/chevre/service/payment/any.d.ts +3 -6
  31. package/lib/chevre/service/payment/any.js +5 -5
  32. package/lib/chevre/service/task/acceptCOAOffer.js +3 -3
  33. package/lib/chevre/service/task/authorizePayment.js +2 -2
  34. package/lib/chevre/service/task/publishPaymentUrl.js +2 -2
  35. package/lib/chevre/service/task/voidMoneyTransferTransaction.js +6 -3
  36. package/lib/chevre/service/task/voidPayTransaction.js +4 -2
  37. package/lib/chevre/service/task/voidRegisterServiceTransaction.js +3 -3
  38. package/lib/chevre/service/task/voidReserveTransaction.js +2 -2
  39. package/lib/chevre/service/transaction/moneyTransfer.js +5 -5
  40. package/lib/chevre/service/transaction/placeOrder/confirm.d.ts +0 -2
  41. package/lib/chevre/service/transaction/placeOrder/confirm.js +2 -2
  42. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +2 -2
  43. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +1 -1
  44. package/lib/chevre/service/transaction/placeOrder/start.d.ts +4 -2
  45. package/lib/chevre/service/transaction/placeOrder/start.js +1 -1
  46. package/lib/chevre/service/transaction/placeOrder/updateAgent.d.ts +23 -0
  47. package/lib/chevre/service/transaction/placeOrder/updateAgent.js +126 -0
  48. package/lib/chevre/service/transaction/returnOrder.js +4 -4
  49. package/lib/chevre/service/transaction.d.ts +4 -22
  50. package/lib/chevre/service/transaction.js +5 -111
  51. package/package.json +1 -1
@@ -1,5 +1,22 @@
1
1
  import type { Connection } from 'mongoose';
2
2
  import * as factory from '../../factory';
3
+ type IKeyOfProjection = 'agent' | 'endDate' | 'expires' | 'project' | 'startDate' | 'status' | 'typeOf' | 'instrument' | 'object' | 'seller' | 'result';
4
+ export type ITransactionInProgress = Pick<factory.transaction.placeOrder.ITransaction, IKeyOfProjection> & {
5
+ /**
6
+ * 取引ID
7
+ * 常にprojectされる
8
+ */
9
+ id: string;
10
+ };
11
+ export type IPlaceOrder = Pick<factory.transaction.placeOrder.ITransaction, IKeyOfProjection> & {
12
+ /**
13
+ * 取引ID
14
+ * 常にprojectされる
15
+ */
16
+ id: string;
17
+ };
18
+ type IStartedPlaceOrderFields = 'expires' | 'id' | 'startDate' | 'status';
19
+ export type IStartedPlaceOrder = Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, IStartedPlaceOrderFields>;
3
20
  /**
4
21
  * 注文取引リポジトリ
5
22
  */
@@ -30,8 +47,8 @@ export declare class PlaceOrderRepo {
30
47
  /**
31
48
  * 取引期限変更
32
49
  */
33
- updateExpires<T extends factory.transactionType>(params: {
34
- typeOf: T;
50
+ updateExpires(params: {
51
+ typeOf: factory.transactionType.PlaceOrder;
35
52
  id: string;
36
53
  expires: Date;
37
54
  }): Promise<void>;
@@ -39,8 +56,8 @@ export declare class PlaceOrderRepo {
39
56
  * 取引オブジェクトを更新
40
57
  * 注文名称など
41
58
  */
42
- updateObject<T extends factory.transactionType>(params: {
43
- typeOf: T;
59
+ updateObject(params: {
60
+ typeOf: factory.transactionType.PlaceOrder;
44
61
  id: string;
45
62
  object?: {
46
63
  name?: string;
@@ -73,4 +90,39 @@ export declare class PlaceOrderRepo {
73
90
  };
74
91
  confirmationNumber: string;
75
92
  }): Promise<void>;
93
+ /**
94
+ * 進行中の注文取引を取得する
95
+ */
96
+ findPlaceOrderInProgressById(params: {
97
+ typeOf: factory.transactionType.PlaceOrder;
98
+ id: string;
99
+ }, inclusion: IKeyOfProjection[]): Promise<ITransactionInProgress>;
100
+ /**
101
+ * 特定注文取引参照
102
+ */
103
+ findPlaceOrderById(params: {
104
+ typeOf: factory.transactionType.PlaceOrder;
105
+ id: string;
106
+ }, inclusion: IKeyOfProjection[]): Promise<IPlaceOrder>;
107
+ /**
108
+ * 取引を開始する
109
+ */
110
+ startPlaceOrder(params: factory.transaction.IStartParams<factory.transactionType.PlaceOrder>): Promise<IStartedPlaceOrder>;
111
+ /**
112
+ * 取引を確定する
113
+ */
114
+ confirmPlaceOrder(params: {
115
+ typeOf: factory.transactionType.PlaceOrder;
116
+ id: string;
117
+ result: factory.transaction.IResult<factory.transactionType.PlaceOrder>;
118
+ potentialActions: factory.transaction.IPotentialActions<factory.transactionType.PlaceOrder>;
119
+ }): Promise<void>;
120
+ /**
121
+ * 取引を中止する
122
+ */
123
+ cancelPlaceOrder(params: {
124
+ typeOf: factory.transactionType.PlaceOrder;
125
+ id: string;
126
+ }): Promise<void>;
76
127
  }
128
+ export {};
@@ -22,18 +22,40 @@ 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.PlaceOrderRepo = void 0;
30
+ const moment_1 = __importDefault(require("moment"));
31
+ const transaction_1 = require("../../eventEmitter/transaction");
27
32
  const factory = __importStar(require("../../factory"));
28
33
  // import { MONGO_MAX_TIME_MS } from '../../settings';
29
- const transaction_1 = require("../mongoose/schemas/transaction");
34
+ const transaction_2 = require("../mongoose/schemas/transaction");
35
+ const AVAILABLE_PROJECT_FIELDS = [
36
+ 'project',
37
+ 'status',
38
+ 'typeOf',
39
+ 'agent',
40
+ 'seller',
41
+ 'object',
42
+ 'expires',
43
+ 'startDate',
44
+ 'endDate',
45
+ 'instrument',
46
+ 'result',
47
+ // 'recipient',
48
+ // 'error',
49
+ // 'tasksExportAction',
50
+ // 'potentialActions',
51
+ ];
30
52
  /**
31
53
  * 注文取引リポジトリ
32
54
  */
33
55
  class PlaceOrderRepo {
34
56
  transactionModel;
35
57
  constructor(connection) {
36
- this.transactionModel = connection.model(transaction_1.modelName, (0, transaction_1.createSchema)());
58
+ this.transactionModel = connection.model(transaction_2.modelName, (0, transaction_2.createSchema)());
37
59
  }
38
60
  /**
39
61
  * 進行中取引に保管された採用済決済方法を検索する
@@ -166,5 +188,195 @@ class PlaceOrderRepo {
166
188
  }, { $set: { 'object.confirmationNumber': params.confirmationNumber } })
167
189
  .exec();
168
190
  }
191
+ /**
192
+ * 進行中の注文取引を取得する
193
+ */
194
+ async findPlaceOrderInProgressById(params, inclusion // make required(2024-05-29~)
195
+ ) {
196
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
197
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
198
+ positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
199
+ }
200
+ else {
201
+ throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
202
+ }
203
+ const projection = {
204
+ _id: 0,
205
+ id: { $toString: '$_id' },
206
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
207
+ };
208
+ const filter = {
209
+ _id: { $eq: params.id },
210
+ typeOf: { $eq: params.typeOf },
211
+ status: { $eq: factory.transactionStatusType.InProgress },
212
+ // expiresを条件に追加(2023-05-12~),
213
+ expires: { $gt: new Date() }
214
+ };
215
+ const doc = await this.transactionModel.findOne(filter, projection)
216
+ .lean()
217
+ .exec();
218
+ if (doc === null) {
219
+ throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
220
+ }
221
+ return doc;
222
+ }
223
+ /**
224
+ * 特定注文取引参照
225
+ */
226
+ async findPlaceOrderById(params, inclusion // make required(2024-05-31~)
227
+ ) {
228
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
229
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
230
+ positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(key));
231
+ }
232
+ else {
233
+ throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
234
+ }
235
+ const projection = {
236
+ _id: 0,
237
+ id: { $toString: '$_id' },
238
+ ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
239
+ };
240
+ const doc = await this.transactionModel.findOne({
241
+ _id: { $eq: params.id },
242
+ typeOf: { $eq: params.typeOf }
243
+ }, projection)
244
+ .lean() // 2024-08-26~
245
+ .exec();
246
+ if (doc === null) {
247
+ throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} not found`);
248
+ }
249
+ return doc;
250
+ }
251
+ /**
252
+ * 取引を開始する
253
+ */
254
+ async startPlaceOrder(params) {
255
+ const status = factory.transactionStatusType.InProgress;
256
+ const tasksExportAction = { actionStatus: factory.actionStatusType.PotentialActionStatus };
257
+ // const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
258
+ const startDate = new Date();
259
+ let expires;
260
+ const { typeOf } = params;
261
+ // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
262
+ if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
263
+ expires = (0, moment_1.default)(startDate)
264
+ .add(params.expiresInSeconds, 'seconds')
265
+ .toDate();
266
+ }
267
+ else {
268
+ throw new factory.errors.ArgumentNull('expiresInSeconds');
269
+ }
270
+ let creatingTransaction;
271
+ if (typeOf === factory.transactionType.PlaceOrder) {
272
+ const { agent, project, object, seller, instrument } = params;
273
+ creatingTransaction = {
274
+ status, startDate, expires, typeOf, tasksExportAction,
275
+ agent, project, seller, object,
276
+ ...(typeof instrument?.id === 'string') ? { instrument } : undefined
277
+ };
278
+ }
279
+ else {
280
+ throw new factory.errors.NotImplemented(`${typeOf} not implemented`);
281
+ }
282
+ // reimplemnt with insertMany(2024-05-30~)
283
+ const result = await this.transactionModel.insertMany(creatingTransaction, { rawResult: true });
284
+ const id = result.insertedIds?.[0]?.toHexString();
285
+ if (typeof id !== 'string') {
286
+ throw new factory.errors.Internal('transaction not saved');
287
+ }
288
+ // 取引開始時にも取引イベントエミッター連携(2024-03-21~)
289
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({ id, typeOf, status });
290
+ return { expires, id, startDate, status }; // minimize response(2024-05-30~)
291
+ }
292
+ /**
293
+ * 取引を確定する
294
+ */
295
+ async confirmPlaceOrder(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.findPlaceOrderById({ 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
+ }
340
+ /**
341
+ * 取引を中止する
342
+ */
343
+ async cancelPlaceOrder(params) {
344
+ const endDate = new Date();
345
+ // 進行中ステータスの取引を中止する
346
+ const doc = await this.transactionModel.findOneAndUpdate({
347
+ typeOf: params.typeOf,
348
+ _id: params.id,
349
+ status: factory.transactionStatusType.InProgress
350
+ }, {
351
+ status: factory.transactionStatusType.Canceled,
352
+ endDate: endDate
353
+ }, {
354
+ new: true,
355
+ projection: { _id: 1 }
356
+ })
357
+ .lean()
358
+ .exec();
359
+ // NotFoundであれば取引状態確認
360
+ if (doc === null) {
361
+ const { status } = await this.findPlaceOrderById(params, ['status']);
362
+ if (status === factory.transactionStatusType.Canceled) {
363
+ // すでに中止済の場合スルー
364
+ }
365
+ else if (status === factory.transactionStatusType.Expired) {
366
+ throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
367
+ }
368
+ else if (status === factory.transactionStatusType.Confirmed) {
369
+ throw new factory.errors.Argument('Transaction id', 'Confirmed transaction unable to cancel');
370
+ }
371
+ else {
372
+ throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
373
+ }
374
+ }
375
+ transaction_1.transactionEventEmitter.emitTransactionStatusChanged({
376
+ id: params.id,
377
+ typeOf: params.typeOf,
378
+ status: factory.transactionStatusType.Canceled
379
+ });
380
+ }
169
381
  }
170
382
  exports.PlaceOrderRepo = PlaceOrderRepo;
@@ -19,7 +19,7 @@ export interface IAggregatePlaceOrder {
19
19
  statuses: IStatus[];
20
20
  }
21
21
  type IOmittedFieldsInProgress = 'tasksExportAction' | 'tasksExportedAt' | 'tasksExportationStatus';
22
- export type ITransactionInProgress<T extends factory.transactionType> = T extends factory.transactionType.MoneyTransfer ? Omit<factory.transaction.moneyTransfer.ITransaction, IOmittedFieldsInProgress> : T extends factory.transactionType.PlaceOrder ? Omit<factory.transaction.placeOrder.ITransaction, IOmittedFieldsInProgress> : T extends factory.transactionType.ReturnOrder ? Omit<factory.transaction.returnOrder.ITransaction, IOmittedFieldsInProgress> : never;
22
+ export type IMoneyTransferTransactionInProgress = Omit<factory.transaction.moneyTransfer.ITransaction, IOmittedFieldsInProgress>;
23
23
  type IStartedTransactionFields = 'expires' | 'id' | 'startDate' | 'status';
24
24
  export type IStartedTransaction = Pick<factory.transaction.ITransaction<factory.transactionType>, IStartedTransactionFields>;
25
25
  /**
@@ -32,36 +32,25 @@ export declare class TransactionRepo {
32
32
  /**
33
33
  * 取引を開始する
34
34
  */
35
- start<T extends factory.transactionType>(params: factory.transaction.IStartParams<T>): Promise<IStartedTransaction>;
35
+ startNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: factory.transaction.IStartParams<T>): Promise<IStartedTransaction>;
36
36
  /**
37
37
  * 特定取引検索
38
38
  */
39
- projectFieldsById<T extends factory.transactionType>(params: {
39
+ projectFieldsByIdNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
40
40
  typeOf: T;
41
41
  id: string;
42
42
  }, inclusion: IKeyOfProjection<T>[]): Promise<factory.transaction.ITransaction<T>>;
43
43
  /**
44
44
  * 進行中の取引を取得する
45
45
  */
46
- projectFieldsInProgressById<T extends factory.transactionType>(params: {
47
- typeOf: T;
46
+ findMoneyTransferInProgressById(params: {
47
+ typeOf: factory.transactionType.MoneyTransfer;
48
48
  id: string;
49
- }, inclusion: IKeyOfProjection<T>[]): Promise<ITransactionInProgress<T>>;
50
- /**
51
- * 取引進行者プロフィールを更新
52
- */
53
- updateAgent<T extends factory.transactionType>(params: {
54
- typeOf: T;
55
- id: string;
56
- agent: Pick<factory.transaction.IAgent, 'id'>;
57
- object?: {
58
- customer?: factory.order.ICustomer;
59
- };
60
- }): Promise<void>;
49
+ }, inclusion: IKeyOfProjection<factory.transactionType.MoneyTransfer>[]): Promise<IMoneyTransferTransactionInProgress>;
61
50
  /**
62
51
  * 取引を確定する
63
52
  */
64
- confirm<T extends factory.transactionType>(params: {
53
+ confirmNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
65
54
  typeOf: T;
66
55
  id: string;
67
56
  result: factory.transaction.IResult<T>;
@@ -155,7 +144,7 @@ export declare class TransactionRepo {
155
144
  /**
156
145
  * 取引を中止する
157
146
  */
158
- cancel<T extends factory.transactionType>(params: {
147
+ cancelNoPlaceOrder<T extends factory.transactionType.MoneyTransfer | factory.transactionType.ReturnOrder>(params: {
159
148
  typeOf: T;
160
149
  id: string;
161
150
  }): Promise<void>;
@@ -212,15 +212,14 @@ class TransactionRepo {
212
212
  /**
213
213
  * 取引を開始する
214
214
  */
215
- async start(params) {
215
+ async startNoPlaceOrder(params) {
216
216
  const status = factory.transactionStatusType.InProgress;
217
217
  const tasksExportAction = { actionStatus: factory.actionStatusType.PotentialActionStatus };
218
218
  // const tasksExportationStatus = factory.transactionTasksExportationStatus.Unexported; // discontinue(2024-06-20~)
219
219
  const startDate = new Date();
220
220
  let expires;
221
221
  const { typeOf } = params;
222
- if (typeOf === factory.transactionType.PlaceOrder
223
- || typeOf === factory.transactionType.ReturnOrder) {
222
+ if (typeOf === factory.transactionType.ReturnOrder) {
224
223
  // expiresInSecondsの指定があれば優先して適用する(2022-11-25~)
225
224
  if (typeof params.expiresInSeconds === 'number' && params.expiresInSeconds > 0) {
226
225
  expires = (0, moment_1.default)(startDate)
@@ -242,14 +241,6 @@ class TransactionRepo {
242
241
  agent, project, seller, object, recipient
243
242
  };
244
243
  }
245
- else if (typeOf === factory.transactionType.PlaceOrder) {
246
- const { agent, project, object, seller, instrument } = params;
247
- creatingTransaction = {
248
- status, startDate, expires, typeOf, tasksExportAction,
249
- agent, project, seller, object,
250
- ...(typeof instrument?.id === 'string') ? { instrument } : undefined
251
- };
252
- }
253
244
  else if (typeOf === factory.transactionType.ReturnOrder) {
254
245
  const { agent, project, object, seller } = params;
255
246
  creatingTransaction = {
@@ -273,7 +264,7 @@ class TransactionRepo {
273
264
  /**
274
265
  * 特定取引検索
275
266
  */
276
- async projectFieldsById(params, inclusion // make required(2024-05-31~)
267
+ async projectFieldsByIdNoPlaceOrder(params, inclusion // make required(2024-05-31~)
277
268
  ) {
278
269
  let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
279
270
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -313,7 +304,7 @@ class TransactionRepo {
313
304
  /**
314
305
  * 進行中の取引を取得する
315
306
  */
316
- async projectFieldsInProgressById(params, inclusion // make required(2024-05-29~)
307
+ async findMoneyTransferInProgressById(params, inclusion // make required(2024-05-29~)
317
308
  ) {
318
309
  let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
319
310
  if (Array.isArray(inclusion) && inclusion.length > 0) {
@@ -327,24 +318,6 @@ class TransactionRepo {
327
318
  id: { $toString: '$_id' },
328
319
  ...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
329
320
  };
330
- // let projection: { [key in (IKeyOfProjection<T> | '__v' | 'createdAt' | 'updatedAt')]?: ProjectionElementType } = {};
331
- // if (Array.isArray(inclusion) && inclusion.length > 0) {
332
- // inclusion.forEach((field) => {
333
- // projection[field] = 1;
334
- // });
335
- // } else {
336
- // // minimize(2024-05-29~)
337
- // projection = {
338
- // __v: 0,
339
- // createdAt: 0,
340
- // updatedAt: 0,
341
- // tasksExportAction: 0,
342
- // ...{
343
- // tasksExportedAt: 0,
344
- // tasksExportationStatus: 0
345
- // }
346
- // };
347
- // }
348
321
  const filter = {
349
322
  _id: { $eq: params.id },
350
323
  typeOf: { $eq: params.typeOf },
@@ -361,6 +334,48 @@ class TransactionRepo {
361
334
  return doc;
362
335
  }
363
336
  // /**
337
+ // * 進行中の取引を取得する
338
+ // */
339
+ // public async projectFieldsInProgressById<T extends factory.transactionType.MoneyTransfer>(
340
+ // params: {
341
+ // typeOf: T;
342
+ // id: string;
343
+ // },
344
+ // inclusion: IKeyOfProjection<T>[] // make required(2024-05-29~)
345
+ // ): Promise<ITransactionInProgress<T>> {
346
+ // let positiveProjectionFields: (IKeyOfProjection<factory.transactionType.MoneyTransfer>
347
+ // | IKeyOfProjection<factory.transactionType.PlaceOrder>
348
+ // | IKeyOfProjection<factory.transactionType.ReturnOrder>
349
+ // )[] = AVAILABLE_PROJECT_FIELDS;
350
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
351
+ // positiveProjectionFields = positiveProjectionFields.filter((key) => inclusion.includes(<IKeyOfProjection<T>>key));
352
+ // } else {
353
+ // throw new factory.errors.NotImplemented('inclusion must be specified'); // 2024-08-26~
354
+ // }
355
+ // const projection: ProjectionType<factory.transaction.ITransaction<T>> = {
356
+ // _id: 0,
357
+ // id: { $toString: '$_id' },
358
+ // ...Object.fromEntries<1>(positiveProjectionFields.map((key) => ([key, 1])))
359
+ // };
360
+ // const filter: FilterQuery<factory.transaction.ITransaction<T>> = {
361
+ // _id: { $eq: params.id },
362
+ // typeOf: { $eq: params.typeOf },
363
+ // status: { $eq: factory.transactionStatusType.InProgress },
364
+ // // expiresを条件に追加(2023-05-12~),
365
+ // expires: { $gt: new Date() }
366
+ // };
367
+ // const doc = await this.transactionModel.findOne(filter, projection)
368
+ // .lean<factory.transaction.ITransaction<T>>() // 2024-08-26~
369
+ // .exec();
370
+ // if (doc === null) {
371
+ // throw new factory.errors.NotFound(
372
+ // this.transactionModel.modelName,
373
+ // `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`
374
+ // );
375
+ // }
376
+ // return doc;
377
+ // }
378
+ // /**
364
379
  // * 進行中取引に保管された採用済決済方法を検索する
365
380
  // */
366
381
  // public async findInProgressPaymentMethodId(params: {
@@ -433,29 +448,43 @@ class TransactionRepo {
433
448
  // }
434
449
  // return doc.object.confirmationNumber;
435
450
  // }
436
- /**
437
- * 取引進行者プロフィールを更新
438
- */
439
- async updateAgent(params) {
440
- const doc = await this.transactionModel.findOneAndUpdate({
441
- _id: { $eq: params.id },
442
- typeOf: { $eq: params.typeOf },
443
- status: { $eq: factory.transactionStatusType.InProgress }
444
- }, {
445
- $set: {
446
- 'agent.id': params.agent.id,
447
- // ...(typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined,
448
- ...(typeof params.object?.customer?.typeOf === 'string') ? { 'object.customer': params.object.customer } : undefined
449
- }
450
- }, {
451
- projection: { _id: 1 }
452
- })
453
- .lean()
454
- .exec();
455
- if (doc === null) {
456
- throw new factory.errors.NotFound(this.transactionModel.modelName, `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`);
457
- }
458
- }
451
+ // /**
452
+ // * 取引進行者プロフィールを更新
453
+ // */
454
+ // public async updateAgent<T extends factory.transactionType>(params: {
455
+ // typeOf: T;
456
+ // id: string;
457
+ // agent: Pick<factory.transaction.IAgent, 'id'>;
458
+ // object?: {
459
+ // customer?: factory.order.ICustomer;
460
+ // };
461
+ // }): Promise<void> {
462
+ // const doc = await this.transactionModel.findOneAndUpdate(
463
+ // {
464
+ // _id: { $eq: params.id },
465
+ // typeOf: { $eq: params.typeOf },
466
+ // status: { $eq: factory.transactionStatusType.InProgress }
467
+ // },
468
+ // {
469
+ // $set: {
470
+ // 'agent.id': params.agent.id,
471
+ // // ...(typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined,
472
+ // ...(typeof params.object?.customer?.typeOf === 'string') ? { 'object.customer': params.object.customer } : undefined
473
+ // }
474
+ // },
475
+ // {
476
+ // projection: { _id: 1 }
477
+ // }
478
+ // )
479
+ // .lean<{ _id: ObjectId }>()
480
+ // .exec();
481
+ // if (doc === null) {
482
+ // throw new factory.errors.NotFound(
483
+ // this.transactionModel.modelName,
484
+ // `${params.typeOf} ${factory.transactionStatusType.InProgress} not found`
485
+ // );
486
+ // }
487
+ // }
459
488
  // /**
460
489
  // * 取引期限変更
461
490
  // */
@@ -526,7 +555,7 @@ class TransactionRepo {
526
555
  /**
527
556
  * 取引を確定する
528
557
  */
529
- async confirm(params) {
558
+ async confirmNoPlaceOrder(params) {
530
559
  const endDate = new Date();
531
560
  const doc = await this.transactionModel.findOneAndUpdate({
532
561
  _id: { $eq: params.id },
@@ -547,7 +576,7 @@ class TransactionRepo {
547
576
  .exec();
548
577
  // NotFoundであれば取引状態確認
549
578
  if (doc === null) {
550
- const { expires, status } = await this.projectFieldsById({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
579
+ const { expires, status } = await this.projectFieldsByIdNoPlaceOrder({ typeOf: params.typeOf, id: params.id }, ['expires', 'status']);
551
580
  if (status === factory.transactionStatusType.Confirmed) {
552
581
  // すでに確定済の場合スルー
553
582
  }
@@ -895,7 +924,7 @@ class TransactionRepo {
895
924
  /**
896
925
  * 取引を中止する
897
926
  */
898
- async cancel(params) {
927
+ async cancelNoPlaceOrder(params) {
899
928
  const endDate = new Date();
900
929
  // 進行中ステータスの取引を中止する
901
930
  const doc = await this.transactionModel.findOneAndUpdate({
@@ -913,7 +942,7 @@ class TransactionRepo {
913
942
  .exec();
914
943
  // NotFoundであれば取引状態確認
915
944
  if (doc === null) {
916
- const { status } = await this.projectFieldsById(params, ['status']);
945
+ const { status } = await this.projectFieldsByIdNoPlaceOrder(params, ['status']);
917
946
  if (status === factory.transactionStatusType.Canceled) {
918
947
  // すでに中止済の場合スルー
919
948
  }
@@ -26,7 +26,6 @@ import type { SettingRepo } from '../../../repo/setting';
26
26
  import type { StockHolderRepo } from '../../../repo/stockHolder';
27
27
  import type { TaskRepo } from '../../../repo/task';
28
28
  import type { TicketRepo } from '../../../repo/ticket';
29
- import type { TransactionRepo } from '../../../repo/transaction';
30
29
  import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
31
30
  import type { TransactionNumberRepo } from '../../../repo/transactionNumber';
32
31
  interface IAuthorizeRepos {
@@ -57,7 +56,6 @@ interface IAuthorizeRepos {
57
56
  task: TaskRepo;
58
57
  ticket: TicketRepo;
59
58
  placeOrder: PlaceOrderRepo;
60
- transaction: TransactionRepo;
61
59
  transactionNumber: TransactionNumberRepo;
62
60
  }
63
61
  type IAuthorizeOperation<T> = (repos: IAuthorizeRepos, settings: Settings) => Promise<T>;
@@ -106,7 +106,7 @@ function authorize(params, options) {
106
106
  }
107
107
  function validateCreateRequest(params) {
108
108
  return async (repos) => {
109
- const transaction = await repos.transaction.projectFieldsInProgressById({
109
+ const transaction = await repos.placeOrder.findPlaceOrderInProgressById({
110
110
  typeOf: factory.transactionType.PlaceOrder,
111
111
  id: params.transaction.id
112
112
  }, ['agent', 'expires', 'project', 'seller', 'typeOf', 'instrument']);
@@ -8,7 +8,7 @@ import type { MemberRepo } from '../../../repo/member';
8
8
  import type { MemberProgramRepo } from '../../../repo/memberProgram';
9
9
  import type { ProductOfferRepo } from '../../../repo/productOffer';
10
10
  import type { TicketRepo } from '../../../repo/ticket';
11
- import type { TransactionRepo } from '../../../repo/transaction';
11
+ import type { PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
12
12
  declare function issueEventOfferTicket(params: {
13
13
  now: Date;
14
14
  audience: Pick<factory.action.authorize.offer.eventService.IPurpose, 'id'>;
@@ -41,7 +41,7 @@ declare function issueEventOfferTicket(params: {
41
41
  memberProgram: MemberProgramRepo;
42
42
  productOffer: ProductOfferRepo;
43
43
  ticket: TicketRepo;
44
- transaction: TransactionRepo;
44
+ placeOrder: PlaceOrderRepo;
45
45
  }) => Promise<{
46
46
  ticketToken: string;
47
47
  }>;
@@ -86,7 +86,7 @@ function issueEventOfferTicket(params) {
86
86
  return async (repos) => {
87
87
  const { now, audience, eventId, eventOfferId, ticketedOffer, author, project, instrument } = params;
88
88
  // 取引は存在するか
89
- const transaction = await repos.transaction.projectFieldsInProgressById({ typeOf: factory.transactionType.PlaceOrder, id: audience.id }, ['expires', 'typeOf', 'seller']);
89
+ const transaction = await repos.placeOrder.findPlaceOrderInProgressById({ typeOf: factory.transactionType.PlaceOrder, id: audience.id }, ['expires', 'typeOf', 'seller']);
90
90
  // イベントは存在するか
91
91
  const event = await repos.event.projectEventFieldsById({ id: eventId }, ['project', 'offers', 'identifier']);
92
92
  // 取引番号発行