@chevre/domain 21.2.0-alpha.4 → 21.2.0-alpha.40

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 (196) hide show
  1. package/example/src/chevre/aggregation/aggregateSystem.ts +58 -31
  2. package/example/src/chevre/countDelayedTasks.ts +17 -0
  3. package/example/src/chevre/countDelayedTransactions.ts +60 -0
  4. package/example/src/chevre/countMoneyTransferTransaction.ts +36 -0
  5. package/example/src/chevre/createManyEventsIfNotExist.ts +4 -1
  6. package/example/src/chevre/lockStockHolder.ts +48 -0
  7. package/example/src/chevre/migrateOrderAdditionalProperties.ts +85 -0
  8. package/example/src/chevre/migrateStockHolderKeys.ts +89 -0
  9. package/example/src/chevre/saveTasks.ts +13 -10
  10. package/example/src/chevre/searchAbortedTasks.ts +36 -0
  11. package/example/src/chevre/task/executeTasks.ts +26 -0
  12. package/example/src/chevre/transaction/findCreditCard.ts +1 -1
  13. package/example/src/chevre/transaction/makeExpired.ts +18 -0
  14. package/example/src/chevre/transaction/orderMembershipService.ts +1 -1
  15. package/example/src/chevre/transaction/startExportTasks.ts +20 -0
  16. package/example/src/chevre/updateTransaction.ts +1 -1
  17. package/lib/chevre/credentials.d.ts +1 -0
  18. package/lib/chevre/credentials.js +2 -1
  19. package/lib/chevre/eventEmitter/assetTransaction.d.ts +21 -0
  20. package/lib/chevre/eventEmitter/assetTransaction.js +25 -0
  21. package/lib/chevre/eventEmitter/task.d.ts +18 -0
  22. package/lib/chevre/eventEmitter/task.js +25 -0
  23. package/lib/chevre/eventEmitter/transaction.d.ts +21 -0
  24. package/lib/chevre/eventEmitter/transaction.js +25 -0
  25. package/lib/chevre/eventEmitter.d.ts +4 -0
  26. package/lib/chevre/eventEmitter.js +9 -0
  27. package/lib/chevre/index.d.ts +3 -2
  28. package/lib/chevre/index.js +5 -3
  29. package/lib/chevre/repo/account.js +0 -4
  30. package/lib/chevre/repo/accountTitle.js +0 -4
  31. package/lib/chevre/repo/accountTransaction.d.ts +0 -10
  32. package/lib/chevre/repo/accountTransaction.js +0 -57
  33. package/lib/chevre/repo/accountingReport.js +0 -4
  34. package/lib/chevre/repo/action.js +0 -4
  35. package/lib/chevre/repo/additionalProperty.js +0 -4
  36. package/lib/chevre/repo/aggregation.js +0 -4
  37. package/lib/chevre/repo/assetTransaction.d.ts +16 -6
  38. package/lib/chevre/repo/assetTransaction.js +174 -50
  39. package/lib/chevre/repo/categoryCode.js +0 -4
  40. package/lib/chevre/repo/code.js +0 -4
  41. package/lib/chevre/repo/comment.d.ts +4 -1
  42. package/lib/chevre/repo/comment.js +20 -9
  43. package/lib/chevre/repo/confirmationNumber.d.ts +0 -1
  44. package/lib/chevre/repo/confirmationNumber.js +3 -15
  45. package/lib/chevre/repo/creativeWork.d.ts +1 -3
  46. package/lib/chevre/repo/creativeWork.js +0 -4
  47. package/lib/chevre/repo/customer.js +0 -4
  48. package/lib/chevre/repo/emailMessage.d.ts +1 -27
  49. package/lib/chevre/repo/emailMessage.js +0 -4
  50. package/lib/chevre/repo/event.d.ts +5 -1
  51. package/lib/chevre/repo/event.js +0 -4
  52. package/lib/chevre/repo/member.js +0 -4
  53. package/lib/chevre/repo/merchantReturnPolicy.d.ts +1 -3
  54. package/lib/chevre/repo/merchantReturnPolicy.js +0 -4
  55. package/lib/chevre/repo/mongoose/schemas/account.d.ts +5 -2
  56. package/lib/chevre/repo/mongoose/schemas/account.js +1 -0
  57. package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +30 -3
  58. package/lib/chevre/repo/mongoose/schemas/accountTitle.js +1 -0
  59. package/lib/chevre/repo/mongoose/schemas/accountTransaction.d.ts +32 -3
  60. package/lib/chevre/repo/mongoose/schemas/accountTransaction.js +2 -1
  61. package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +14 -3
  62. package/lib/chevre/repo/mongoose/schemas/accountingReport.js +1 -0
  63. package/lib/chevre/repo/mongoose/schemas/action.d.ts +44 -3
  64. package/lib/chevre/repo/mongoose/schemas/action.js +2 -1
  65. package/lib/chevre/repo/mongoose/schemas/additionalProperty.d.ts +18 -3
  66. package/lib/chevre/repo/mongoose/schemas/additionalProperty.js +1 -0
  67. package/lib/chevre/repo/mongoose/schemas/aggregation.d.ts +5 -2
  68. package/lib/chevre/repo/mongoose/schemas/aggregation.js +1 -0
  69. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +45 -3
  70. package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +3 -1
  71. package/lib/chevre/repo/mongoose/schemas/authorization.d.ts +20 -3
  72. package/lib/chevre/repo/mongoose/schemas/authorization.js +2 -1
  73. package/lib/chevre/repo/mongoose/schemas/categoryCode.d.ts +26 -3
  74. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +1 -0
  75. package/lib/chevre/repo/mongoose/schemas/comments.d.ts +28 -3
  76. package/lib/chevre/repo/mongoose/schemas/comments.js +2 -1
  77. package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +44 -3
  78. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +1 -0
  79. package/lib/chevre/repo/mongoose/schemas/customer.d.ts +26 -3
  80. package/lib/chevre/repo/mongoose/schemas/customer.js +1 -0
  81. package/lib/chevre/repo/mongoose/schemas/emailMessages.d.ts +22 -3
  82. package/lib/chevre/repo/mongoose/schemas/emailMessages.js +1 -0
  83. package/lib/chevre/repo/mongoose/schemas/event.d.ts +72 -3
  84. package/lib/chevre/repo/mongoose/schemas/event.js +1 -0
  85. package/lib/chevre/repo/mongoose/schemas/member.d.ts +14 -3
  86. package/lib/chevre/repo/mongoose/schemas/member.js +1 -0
  87. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +22 -3
  88. package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +1 -0
  89. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +66 -3
  90. package/lib/chevre/repo/mongoose/schemas/offer.js +1 -0
  91. package/lib/chevre/repo/mongoose/schemas/offerCatalog.d.ts +28 -3
  92. package/lib/chevre/repo/mongoose/schemas/offerCatalog.js +1 -0
  93. package/lib/chevre/repo/mongoose/schemas/order.d.ts +52 -3
  94. package/lib/chevre/repo/mongoose/schemas/order.js +2 -1
  95. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.d.ts +26 -3
  96. package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +2 -1
  97. package/lib/chevre/repo/mongoose/schemas/place.d.ts +50 -3
  98. package/lib/chevre/repo/mongoose/schemas/place.js +1 -0
  99. package/lib/chevre/repo/mongoose/schemas/priceSpecification.d.ts +30 -3
  100. package/lib/chevre/repo/mongoose/schemas/priceSpecification.js +1 -0
  101. package/lib/chevre/repo/mongoose/schemas/product.d.ts +32 -3
  102. package/lib/chevre/repo/mongoose/schemas/product.js +1 -0
  103. package/lib/chevre/repo/mongoose/schemas/project.d.ts +24 -3
  104. package/lib/chevre/repo/mongoose/schemas/project.js +1 -0
  105. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +62 -3
  106. package/lib/chevre/repo/mongoose/schemas/reservation.js +2 -1
  107. package/lib/chevre/repo/mongoose/schemas/role.d.ts +12 -3
  108. package/lib/chevre/repo/mongoose/schemas/role.js +1 -0
  109. package/lib/chevre/repo/mongoose/schemas/seller.d.ts +32 -3
  110. package/lib/chevre/repo/mongoose/schemas/seller.js +1 -0
  111. package/lib/chevre/repo/mongoose/schemas/serviceOutput.d.ts +12 -3
  112. package/lib/chevre/repo/mongoose/schemas/serviceOutput.js +2 -1
  113. package/lib/chevre/repo/mongoose/schemas/task.d.ts +31 -3
  114. package/lib/chevre/repo/mongoose/schemas/task.js +3 -1
  115. package/lib/chevre/repo/mongoose/schemas/telemetry.d.ts +22 -3
  116. package/lib/chevre/repo/mongoose/schemas/telemetry.js +1 -0
  117. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +41 -3
  118. package/lib/chevre/repo/mongoose/schemas/transaction.js +3 -1
  119. package/lib/chevre/repo/mongoose/schemas/trip.d.ts +12 -3
  120. package/lib/chevre/repo/mongoose/schemas/trip.js +1 -0
  121. package/lib/chevre/repo/offer.js +0 -5
  122. package/lib/chevre/repo/offerCatalog.js +0 -4
  123. package/lib/chevre/repo/order.d.ts +25 -0
  124. package/lib/chevre/repo/order.js +5 -4
  125. package/lib/chevre/repo/orderNumber.d.ts +0 -1
  126. package/lib/chevre/repo/orderNumber.js +2 -12
  127. package/lib/chevre/repo/ownershipInfo.js +0 -4
  128. package/lib/chevre/repo/permit.js +0 -4
  129. package/lib/chevre/repo/place.d.ts +5 -1
  130. package/lib/chevre/repo/place.js +1 -10
  131. package/lib/chevre/repo/priceSpecification.js +0 -4
  132. package/lib/chevre/repo/product.js +0 -4
  133. package/lib/chevre/repo/project.js +0 -4
  134. package/lib/chevre/repo/reservation.js +0 -4
  135. package/lib/chevre/repo/role.js +0 -4
  136. package/lib/chevre/repo/seller.js +0 -4
  137. package/lib/chevre/repo/serviceOutput.js +0 -4
  138. package/lib/chevre/repo/serviceOutputIdentifier.d.ts +0 -1
  139. package/lib/chevre/repo/serviceOutputIdentifier.js +2 -12
  140. package/lib/chevre/repo/stockHolder.d.ts +1 -0
  141. package/lib/chevre/repo/stockHolder.js +74 -7
  142. package/lib/chevre/repo/task.d.ts +38 -2
  143. package/lib/chevre/repo/task.js +90 -10
  144. package/lib/chevre/repo/telemetry.js +0 -4
  145. package/lib/chevre/repo/transaction.d.ts +17 -2
  146. package/lib/chevre/repo/transaction.js +176 -56
  147. package/lib/chevre/repo/transactionNumber.d.ts +0 -1
  148. package/lib/chevre/repo/transactionNumber.js +2 -12
  149. package/lib/chevre/repo/trip.js +0 -4
  150. package/lib/chevre/service/aggregation/system.d.ts +67 -22
  151. package/lib/chevre/service/aggregation/system.js +101 -89
  152. package/lib/chevre/service/assetTransaction/cancelReservation.js +1 -5
  153. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  154. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  155. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  156. package/lib/chevre/service/assetTransaction/registerService.js +1 -2
  157. package/lib/chevre/service/assetTransaction/reserve.js +1 -1
  158. package/lib/chevre/service/assetTransaction.d.ts +6 -2
  159. package/lib/chevre/service/assetTransaction.js +9 -5
  160. package/lib/chevre/service/notification.d.ts +3 -1
  161. package/lib/chevre/service/notification.js +2 -6
  162. package/lib/chevre/service/offer/event/voidTransaction.d.ts +2 -0
  163. package/lib/chevre/service/offer/event/voidTransaction.js +17 -1
  164. package/lib/chevre/service/offer.js +1 -1
  165. package/lib/chevre/service/order/onOrderStatusChanged.js +1 -1
  166. package/lib/chevre/service/order/placeOrder.js +1 -1
  167. package/lib/chevre/service/order/returnOrder.js +1 -5
  168. package/lib/chevre/service/order/sendOrder.js +1 -1
  169. package/lib/chevre/service/payment/any/onPaid.js +1 -1
  170. package/lib/chevre/service/payment/any/onRefund.js +1 -1
  171. package/lib/chevre/service/payment/any.js +25 -10
  172. package/lib/chevre/service/product.js +1 -5
  173. package/lib/chevre/service/reserve/cancelReservation.js +0 -2
  174. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.d.ts +0 -3
  175. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +19 -18
  176. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +1 -1
  177. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -31
  178. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +1 -1
  179. package/lib/chevre/service/reserve/useReservation.js +1 -8
  180. package/lib/chevre/service/task/confirmRegisterServiceTransaction.js +1 -1
  181. package/lib/chevre/service/task/returnPayTransaction.js +1 -5
  182. package/lib/chevre/service/task/voidReserveTransaction.js +3 -1
  183. package/lib/chevre/service/task.d.ts +9 -0
  184. package/lib/chevre/service/task.js +43 -4
  185. package/lib/chevre/service/transaction/moneyTransfer.js +1 -3
  186. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +30 -29
  187. package/lib/chevre/service/transaction/placeOrder.js +1 -5
  188. package/lib/chevre/service/transaction/placeOrderInProgress.js +2 -2
  189. package/lib/chevre/service/transaction/returnOrder.js +1 -5
  190. package/lib/chevre/service/transaction.d.ts +6 -0
  191. package/lib/chevre/service/transaction.js +9 -7
  192. package/lib/chevre/settings.d.ts +1 -2
  193. package/lib/chevre/settings.js +3 -8
  194. package/package.json +4 -4
  195. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +0 -96
  196. package/example/src/chevre/migrateMovieAdditionalProperties.ts +0 -98
@@ -12,17 +12,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../factory");
15
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
16
15
  const transaction_1 = require("./mongoose/schemas/transaction");
16
+ const transaction_2 = require("../eventEmitter/transaction");
17
17
  /**
18
18
  * 取引リポジトリ
19
19
  */
20
20
  class MongoRepository {
21
21
  constructor(connection) {
22
22
  this.transactionModel = connection.model(transaction_1.modelName, transaction_1.schema);
23
- if (connection.get('autoIndex') === true) {
24
- this.transactionModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
25
- }
26
23
  }
27
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
28
25
  static CREATE_MONGO_CONDITIONS(params) {
@@ -267,7 +264,9 @@ class MongoRepository {
267
264
  else {
268
265
  expires = params.expires;
269
266
  }
270
- return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate, endDate: undefined, expires, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
267
+ return this.transactionModel.create(Object.assign(Object.assign({}, params), { typeOf: params.typeOf, status: factory.transactionStatusType.InProgress, startDate, endDate: undefined, expires, tasksExportAction: {
268
+ actionStatus: factory.actionStatusType.PotentialActionStatus
269
+ }, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }))
271
270
  .then((doc) => doc.toObject());
272
271
  });
273
272
  }
@@ -276,10 +275,29 @@ class MongoRepository {
276
275
  */
277
276
  findById(params) {
278
277
  return __awaiter(this, void 0, void 0, function* () {
278
+ let projection = {};
279
+ if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
280
+ params.inclusion.forEach((field) => {
281
+ projection[field] = 1;
282
+ });
283
+ }
284
+ else {
285
+ projection = {
286
+ __v: 0,
287
+ createdAt: 0,
288
+ updatedAt: 0
289
+ };
290
+ if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
291
+ params.exclusion.forEach((field) => {
292
+ projection[field] = 0;
293
+ });
294
+ }
295
+ }
279
296
  const doc = yield this.transactionModel.findOne({
280
297
  _id: { $eq: params.id },
281
298
  typeOf: { $eq: params.typeOf }
282
299
  })
300
+ .select(projection)
283
301
  .exec();
284
302
  if (doc === null) {
285
303
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -347,9 +365,9 @@ class MongoRepository {
347
365
  var _a, _b;
348
366
  return __awaiter(this, void 0, void 0, function* () {
349
367
  const doc = yield this.transactionModel.findOneAndUpdate({
350
- _id: params.id,
351
- typeOf: params.typeOf,
352
- status: factory.transactionStatusType.InProgress
368
+ _id: { $eq: params.id },
369
+ typeOf: { $eq: params.typeOf },
370
+ status: { $eq: factory.transactionStatusType.InProgress }
353
371
  }, {
354
372
  $set: Object.assign(Object.assign({ 'agent.id': params.agent.id }, (typeof params.agent.name === 'string') ? { 'agent.name': params.agent.name } : undefined), (typeof ((_b = (_a = params.object) === null || _a === void 0 ? void 0 : _a.customer) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { 'object.customer': params.object.customer } : undefined)
355
373
  }, {
@@ -367,9 +385,9 @@ class MongoRepository {
367
385
  updateExpires(params) {
368
386
  return __awaiter(this, void 0, void 0, function* () {
369
387
  const doc = yield this.transactionModel.findOneAndUpdate({
370
- _id: params.id,
371
- typeOf: params.typeOf,
372
- status: factory.transactionStatusType.InProgress
388
+ _id: { $eq: params.id },
389
+ typeOf: { $eq: params.typeOf },
390
+ status: { $eq: factory.transactionStatusType.InProgress }
373
391
  }, {
374
392
  $set: {
375
393
  expires: params.expires
@@ -391,9 +409,9 @@ class MongoRepository {
391
409
  var _a;
392
410
  return __awaiter(this, void 0, void 0, function* () {
393
411
  const doc = yield this.transactionModel.findOneAndUpdate({
394
- _id: params.id,
395
- typeOf: params.typeOf,
396
- status: factory.transactionStatusType.InProgress
412
+ _id: { $eq: params.id },
413
+ typeOf: { $eq: params.typeOf },
414
+ status: { $eq: factory.transactionStatusType.InProgress }
397
415
  }, {
398
416
  $set: Object.assign({}, (typeof ((_a = params.object) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? { 'object.name': params.object.name } : undefined)
399
417
  }, {
@@ -411,9 +429,9 @@ class MongoRepository {
411
429
  confirm(params) {
412
430
  return __awaiter(this, void 0, void 0, function* () {
413
431
  const doc = yield this.transactionModel.findOneAndUpdate({
414
- _id: params.id,
415
- typeOf: params.typeOf,
416
- status: factory.transactionStatusType.InProgress
432
+ _id: { $eq: params.id },
433
+ typeOf: { $eq: params.typeOf },
434
+ status: { $eq: factory.transactionStatusType.InProgress }
417
435
  }, {
418
436
  status: factory.transactionStatusType.Confirmed,
419
437
  endDate: new Date(),
@@ -428,43 +446,49 @@ class MongoRepository {
428
446
  // NotFoundであれば取引状態確認
429
447
  if (doc === null) {
430
448
  const transaction = yield this.findById({ typeOf: params.typeOf, id: params.id });
431
- // tslint:disable-next-line:no-single-line-block-comment
432
- /* istanbul ignore next */
433
449
  if (transaction.status === factory.transactionStatusType.Confirmed) {
434
- // すでに確定済の場合
435
- return;
436
- // tslint:disable-next-line:no-single-line-block-comment
437
- /* istanbul ignore next */
450
+ // すでに確定済の場合スルー
438
451
  }
439
452
  else if (transaction.status === factory.transactionStatusType.Expired) {
440
453
  throw new factory.errors.Argument('Transaction id', 'Already expired');
441
- // tslint:disable-next-line:no-single-line-block-comment
442
- /* istanbul ignore next */
443
454
  }
444
455
  else if (transaction.status === factory.transactionStatusType.Canceled) {
445
456
  throw new factory.errors.Argument('Transaction id', 'Already canceled');
446
- // tslint:disable-next-line:no-single-line-block-comment
447
- /* istanbul ignore next */
448
457
  }
449
458
  else {
450
459
  throw new factory.errors.NotFound(this.transactionModel.modelName);
451
460
  }
452
461
  }
453
- // return doc.toObject();
462
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
463
+ id: params.id,
464
+ typeOf: params.typeOf,
465
+ status: factory.transactionStatusType.Confirmed
466
+ });
454
467
  });
455
468
  }
456
469
  /**
457
470
  * タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
458
471
  */
459
472
  startExportTasks(params) {
473
+ var _a;
460
474
  return __awaiter(this, void 0, void 0, function* () {
461
- return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign({}, (params.project !== undefined)
462
- ? {
463
- 'project.id': {
464
- $eq: params.project.id
465
- }
466
- } : undefined), (params.typeOf !== undefined && params.typeOf !== null && Array.isArray(params.typeOf.$in))
467
- ? { typeOf: { $in: params.typeOf.$in } } : undefined), { status: params.status, tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported }), { tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting }, { new: true })
475
+ switch (params.status) {
476
+ case factory.transactionStatusType.InProgress:
477
+ throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
478
+ default:
479
+ // no op
480
+ }
481
+ const typeOfIn = (_a = params.typeOf) === null || _a === void 0 ? void 0 : _a.$in;
482
+ return this.transactionModel.findOneAndUpdate(Object.assign(Object.assign(Object.assign(Object.assign({}, (params.project !== undefined) ? { 'project.id': { $eq: params.project.id } } : undefined), (Array.isArray(typeOfIn)) ? { typeOf: { $in: typeOfIn } } : undefined), { status: { $eq: params.status }, tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported } }), (typeof params.id === 'string') ? { _id: { $eq: params.id } } : undefined), {
483
+ 'tasksExportAction.actionStatus': factory.actionStatusType.ActiveActionStatus,
484
+ 'tasksExportAction.agent': { name: params.tasksExportAction.agent.name },
485
+ 'tasksExportAction.startDate': new Date(),
486
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting
487
+ }, { new: true })
488
+ .select({
489
+ _id: 1,
490
+ typeOf: 1
491
+ })
468
492
  .exec()
469
493
  // tslint:disable-next-line:no-null-keyword
470
494
  .then((doc) => (doc === null) ? null : doc.toObject());
@@ -477,17 +501,80 @@ class MongoRepository {
477
501
  */
478
502
  reexportTasks(params) {
479
503
  return __awaiter(this, void 0, void 0, function* () {
480
- yield this.transactionModel.updateMany({
481
- tasksExportationStatus: factory.transactionTasksExportationStatus.Exporting,
504
+ const reexportingTransactions = yield this.transactionModel.find({
505
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting },
482
506
  updatedAt: {
483
507
  $lt: moment()
484
508
  .add(-params.intervalInMinutes, 'minutes')
485
509
  .toDate()
486
510
  }
487
- }, {
488
- tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
489
511
  })
512
+ .select({
513
+ _id: 1,
514
+ typeOf: 1,
515
+ status: 1
516
+ })
517
+ .setOptions({ maxTimeMS: 10000 })
518
+ .exec();
519
+ if (reexportingTransactions.length > 0) {
520
+ for (const reexportingTransaction of reexportingTransactions) {
521
+ yield this.transactionModel.updateOne({
522
+ _id: { $eq: reexportingTransaction.id },
523
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
524
+ }, {
525
+ tasksExportAction: {
526
+ actionStatus: factory.actionStatusType.PotentialActionStatus
527
+ },
528
+ tasksExportationStatus: factory.transactionTasksExportationStatus.Unexported
529
+ })
530
+ .exec();
531
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
532
+ id: reexportingTransaction.id,
533
+ typeOf: reexportingTransaction.typeOf,
534
+ status: reexportingTransaction.status
535
+ });
536
+ }
537
+ }
538
+ });
539
+ }
540
+ /**
541
+ * タスクエクスポートの遅延している取引について明示的にemitTransactionStatusChangedを実行する
542
+ */
543
+ exportTasks(params) {
544
+ return __awaiter(this, void 0, void 0, function* () {
545
+ const delayedTransactions = yield this.transactionModel.find({
546
+ status: {
547
+ $in: [
548
+ factory.transactionStatusType.Canceled,
549
+ factory.transactionStatusType.Confirmed,
550
+ factory.transactionStatusType.Expired
551
+ ]
552
+ },
553
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Unexported },
554
+ endDate: {
555
+ $exists: true,
556
+ $lt: moment(params.now)
557
+ .add(-params.delayInSeconds, 'seconds')
558
+ .toDate()
559
+ }
560
+ })
561
+ .select({
562
+ _id: 1,
563
+ typeOf: 1,
564
+ status: 1
565
+ })
566
+ .setOptions({ maxTimeMS: 10000 })
490
567
  .exec();
568
+ if (delayedTransactions.length > 0) {
569
+ delayedTransactions.forEach((delayedTransaction) => {
570
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
571
+ id: delayedTransaction.id,
572
+ typeOf: delayedTransaction.typeOf,
573
+ status: delayedTransaction.status
574
+ });
575
+ });
576
+ }
577
+ return delayedTransactions;
491
578
  });
492
579
  }
493
580
  /**
@@ -496,9 +583,15 @@ class MongoRepository {
496
583
  */
497
584
  setTasksExportedById(params) {
498
585
  return __awaiter(this, void 0, void 0, function* () {
499
- yield this.transactionModel.findByIdAndUpdate(params.id, {
586
+ const endDate = new Date();
587
+ yield this.transactionModel.updateOne({
588
+ _id: { $eq: params.id },
589
+ tasksExportationStatus: { $eq: factory.transactionTasksExportationStatus.Exporting }
590
+ }, {
500
591
  tasksExportationStatus: factory.transactionTasksExportationStatus.Exported,
501
- tasksExportedAt: new Date()
592
+ tasksExportedAt: endDate,
593
+ 'tasksExportAction.actionStatus': factory.actionStatusType.CompletedActionStatus,
594
+ 'tasksExportAction.endDate': endDate
502
595
  })
503
596
  .exec();
504
597
  });
@@ -508,15 +601,36 @@ class MongoRepository {
508
601
  */
509
602
  makeExpired(params) {
510
603
  return __awaiter(this, void 0, void 0, function* () {
511
- // ステータスと期限を見て更新
512
- yield this.transactionModel.updateMany({
513
- status: factory.transactionStatusType.InProgress,
604
+ // IDをemitしたいのでまずリスト検索(2023-04-27~)
605
+ const expiringTransactions = yield this.transactionModel.find({
606
+ status: { $eq: factory.transactionStatusType.InProgress },
514
607
  expires: { $lt: params.expires }
515
- }, {
516
- status: factory.transactionStatusType.Expired,
517
- endDate: new Date()
518
608
  })
609
+ .select({
610
+ _id: 1,
611
+ typeOf: 1
612
+ })
613
+ .setOptions({ maxTimeMS: 10000 })
519
614
  .exec();
615
+ if (expiringTransactions.length > 0) {
616
+ // ステータスと期限を見て更新
617
+ yield this.transactionModel.updateMany({
618
+ _id: { $in: expiringTransactions.map((t) => t.id) },
619
+ status: { $eq: factory.transactionStatusType.InProgress },
620
+ expires: { $lt: params.expires }
621
+ }, {
622
+ status: factory.transactionStatusType.Expired,
623
+ endDate: new Date()
624
+ })
625
+ .exec();
626
+ expiringTransactions.forEach((expiringTransaction) => {
627
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
628
+ id: expiringTransaction.id,
629
+ typeOf: expiringTransaction.typeOf,
630
+ status: factory.transactionStatusType.Expired
631
+ });
632
+ });
633
+ }
520
634
  });
521
635
  }
522
636
  /**
@@ -541,11 +655,8 @@ class MongoRepository {
541
655
  // NotFoundであれば取引状態確認
542
656
  if (doc === null) {
543
657
  const transaction = yield this.findById(params);
544
- // tslint:disable-next-line:no-single-line-block-comment
545
- /* istanbul ignore next */
546
658
  if (transaction.status === factory.transactionStatusType.Canceled) {
547
- // すでに中止済の場合
548
- return;
659
+ // すでに中止済の場合スルー
549
660
  }
550
661
  else if (transaction.status === factory.transactionStatusType.Expired) {
551
662
  throw new factory.errors.Argument('Transaction id', 'Transaction already expired');
@@ -557,7 +668,11 @@ class MongoRepository {
557
668
  throw new factory.errors.NotFound(this.transactionModel.modelName);
558
669
  }
559
670
  }
560
- // return doc.toObject();
671
+ transaction_2.transactionEventEmitter.emitTransactionStatusChanged({
672
+ id: params.id,
673
+ typeOf: params.typeOf,
674
+ status: factory.transactionStatusType.Canceled
675
+ });
561
676
  });
562
677
  }
563
678
  count(params) {
@@ -615,9 +730,12 @@ class MongoRepository {
615
730
  /**
616
731
  * 特定の取引を更新する(汎用)
617
732
  */
618
- findByIdAndUpdate(params) {
733
+ findByIdAndUpdateInProgress(params) {
619
734
  return __awaiter(this, void 0, void 0, function* () {
620
- yield this.transactionModel.findOneAndUpdate({ _id: params.id }, params.update, {
735
+ yield this.transactionModel.findOneAndUpdate({
736
+ _id: { $eq: params.id },
737
+ status: { $eq: factory.transactionStatusType.InProgress }
738
+ }, params.update, {
621
739
  // new: true,
622
740
  projection: { _id: 1 }
623
741
  })
@@ -632,7 +750,8 @@ class MongoRepository {
632
750
  saveOrderNumberIfNotExist(params) {
633
751
  return __awaiter(this, void 0, void 0, function* () {
634
752
  yield this.transactionModel.updateOne({
635
- _id: params.id,
753
+ _id: { $eq: params.id },
754
+ status: { $eq: factory.transactionStatusType.InProgress },
636
755
  'object.orderNumber': { $exists: false }
637
756
  }, { 'object.orderNumber': params.orderNumber })
638
757
  .exec();
@@ -641,7 +760,8 @@ class MongoRepository {
641
760
  saveConfirmationNumberIfNotExist(params) {
642
761
  return __awaiter(this, void 0, void 0, function* () {
643
762
  yield this.transactionModel.updateOne({
644
- _id: params.id,
763
+ _id: { $eq: params.id },
764
+ status: { $eq: factory.transactionStatusType.InProgress },
645
765
  'object.confirmationNumber': { $exists: false }
646
766
  }, { 'object.confirmationNumber': params.confirmationNumber })
647
767
  .exec();
@@ -6,7 +6,6 @@ interface IPublishResult {
6
6
  * 取引番号リポジトリ
7
7
  */
8
8
  export declare class RedisRepository {
9
- private static readonly REDIS_KEY_PREFIX_NEW;
10
9
  private static readonly REDIS_KEY_PREFIX;
11
10
  private readonly redisClient;
12
11
  constructor(redisClient: RedisClientType);
@@ -16,7 +16,6 @@ const util = require("util");
16
16
  // tslint:disable-next-line:no-require-imports no-var-requires
17
17
  const fpe = require('node-fpe');
18
18
  const factory = require("../factory");
19
- const settings_1 = require("../settings");
20
19
  /**
21
20
  * 取引番号リポジトリ
22
21
  */
@@ -25,15 +24,7 @@ class RedisRepository {
25
24
  this.redisClient = redisClient;
26
25
  }
27
26
  static createKey(params) {
28
- const useNewKey = params.startDate instanceof Date
29
- && moment(params.startDate)
30
- .isSameOrAfter(settings_1.USE_NEW_ORDER_NUMBER_KEY_FROM);
31
- if (useNewKey) {
32
- return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX_NEW, params.timestamp);
33
- }
34
- else {
35
- return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.timestamp);
36
- }
27
+ return util.format('%s:%s', RedisRepository.REDIS_KEY_PREFIX, params.timestamp);
37
28
  }
38
29
  /**
39
30
  * タイムスタンプから発行する
@@ -68,6 +59,5 @@ class RedisRepository {
68
59
  });
69
60
  }
70
61
  }
71
- RedisRepository.REDIS_KEY_PREFIX_NEW = 'transactionNumber';
72
- RedisRepository.REDIS_KEY_PREFIX = 'chevre:transactionNumber';
62
+ RedisRepository.REDIS_KEY_PREFIX = 'transactionNumber';
73
63
  exports.RedisRepository = RedisRepository;
@@ -22,7 +22,6 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
24
  const factory = require("../factory");
25
- const onIndexCreated_1 = require("./mongoose/onIndexCreated");
26
25
  const trip_1 = require("./mongoose/schemas/trip");
27
26
  /**
28
27
  * トリップリポジトリ
@@ -30,9 +29,6 @@ const trip_1 = require("./mongoose/schemas/trip");
30
29
  class MongoRepository {
31
30
  constructor(connection) {
32
31
  this.tripModel = connection.model(trip_1.modelName, trip_1.schema);
33
- if (connection.get('autoIndex') === true) {
34
- this.tripModel.on(onIndexCreated_1.INDEX_EVENT, onIndexCreated_1.onIndexCreated);
35
- }
36
32
  }
37
33
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
38
34
  static CREATE_MONGO_CONDITIONS(conditions) {
@@ -4,97 +4,142 @@ import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransac
4
4
  import { MongoRepository as EventRepo } from '../../repo/event';
5
5
  import { MongoRepository as TasKRepo } from '../../repo/task';
6
6
  import { MongoRepository as TransactionRepo } from '../../repo/transaction';
7
+ type AggregateDurationUnit = 'days' | 'hours';
7
8
  declare function aggregateEvent(params: {
8
- aggregationDays: number;
9
+ aggregateDurationUnit: AggregateDurationUnit;
10
+ aggregationCount: number;
9
11
  excludedProjectId?: string;
10
12
  }): (repos: {
11
13
  agregation: AggregationRepo;
12
14
  event: EventRepo;
13
- }) => Promise<void>;
15
+ }) => Promise<{
16
+ aggregationCount: number;
17
+ aggregateDuration: string;
18
+ }>;
14
19
  /**
15
20
  * 注文取引集計
16
21
  */
17
22
  declare function aggregatePlaceOrder(params: {
18
- aggregationDays: number;
23
+ aggregateDurationUnit: AggregateDurationUnit;
24
+ aggregationCount: number;
19
25
  excludedProjectId?: string;
20
26
  clientIds?: string[];
21
27
  }): (repos: {
22
28
  agregation: AggregationRepo;
23
29
  transaction: TransactionRepo;
24
- }) => Promise<void>;
30
+ }) => Promise<{
31
+ aggregationCount: number;
32
+ aggregateDuration: string;
33
+ }>;
25
34
  /**
26
35
  * 興行オファー承認アクション集計
27
36
  */
28
37
  declare function aggregateAuthorizeEventServiceOfferAction(params: {
29
- aggregationDays: number;
38
+ aggregateDurationUnit: AggregateDurationUnit;
39
+ aggregationCount: number;
30
40
  excludedProjectId?: string;
31
41
  }): (repos: {
32
42
  agregation: AggregationRepo;
33
43
  action: ActionRepo;
34
- }) => Promise<void>;
44
+ }) => Promise<{
45
+ aggregationCount: number;
46
+ aggregateDuration: string;
47
+ }>;
35
48
  /**
36
49
  * 決済承認アクション集計
37
50
  */
38
51
  declare function aggregateAuthorizePaymentAction(params: {
39
- aggregationDays: number;
52
+ aggregateDurationUnit: AggregateDurationUnit;
53
+ aggregationCount: number;
40
54
  excludedProjectId?: string;
41
55
  }): (repos: {
42
56
  agregation: AggregationRepo;
43
57
  action: ActionRepo;
44
- }) => Promise<void>;
58
+ }) => Promise<{
59
+ aggregationCount: number;
60
+ aggregateDuration: string;
61
+ }>;
45
62
  declare function aggregateAuthorizeOrderAction(params: {
46
- aggregationDays: number;
63
+ aggregateDurationUnit: AggregateDurationUnit;
64
+ aggregationCount: number;
47
65
  excludedProjectId?: string;
48
66
  }): (repos: {
49
67
  agregation: AggregationRepo;
50
68
  action: ActionRepo;
51
- }) => Promise<void>;
69
+ }) => Promise<{
70
+ aggregationCount: number;
71
+ aggregateDuration: string;
72
+ }>;
52
73
  /**
53
74
  * 使用アクション集計
54
75
  */
55
76
  declare function aggregateUseAction(params: {
56
- aggregationDays: number;
77
+ aggregateDurationUnit: AggregateDurationUnit;
78
+ aggregationCount: number;
57
79
  excludedProjectId?: string;
58
80
  }): (repos: {
59
81
  agregation: AggregationRepo;
60
82
  action: ActionRepo;
61
- }) => Promise<void>;
83
+ }) => Promise<{
84
+ aggregationCount: number;
85
+ aggregateDuration: string;
86
+ }>;
62
87
  declare function aggregateCheckMovieTicketAction(params: {
63
- aggregationDays: number;
88
+ aggregateDurationUnit: AggregateDurationUnit;
89
+ aggregationCount: number;
64
90
  excludedProjectId?: string;
65
91
  }): (repos: {
66
92
  agregation: AggregationRepo;
67
93
  action: ActionRepo;
68
- }) => Promise<void>;
94
+ }) => Promise<{
95
+ aggregationCount: number;
96
+ aggregateDuration: string;
97
+ }>;
69
98
  declare function aggregatePayMovieTicketAction(params: {
70
- aggregationDays: number;
99
+ aggregateDurationUnit: AggregateDurationUnit;
100
+ aggregationCount: number;
71
101
  excludedProjectId?: string;
72
102
  }): (repos: {
73
103
  agregation: AggregationRepo;
74
104
  action: ActionRepo;
75
- }) => Promise<void>;
105
+ }) => Promise<{
106
+ aggregationCount: number;
107
+ aggregateDuration: string;
108
+ }>;
76
109
  declare function aggregatePayTransaction(params: {
77
- aggregationDays: number;
110
+ aggregateDurationUnit: AggregateDurationUnit;
111
+ aggregationCount: number;
78
112
  excludedProjectId?: string;
79
113
  }): (repos: {
80
114
  agregation: AggregationRepo;
81
115
  assetTransaction: AssetTransactionRepo;
82
- }) => Promise<void>;
116
+ }) => Promise<{
117
+ aggregationCount: number;
118
+ aggregateDuration: string;
119
+ }>;
83
120
  /**
84
121
  * 予約集計
85
122
  */
86
123
  declare function aggregateReserveTransaction(params: {
87
- aggregationDays: number;
124
+ aggregateDurationUnit: AggregateDurationUnit;
125
+ aggregationCount: number;
88
126
  excludedProjectId?: string;
89
127
  }): (repos: {
90
128
  agregation: AggregationRepo;
91
129
  assetTransaction: AssetTransactionRepo;
92
- }) => Promise<void>;
130
+ }) => Promise<{
131
+ aggregationCount: number;
132
+ aggregateDuration: string;
133
+ }>;
93
134
  declare function aggregateTask(params: {
94
- aggregationDays: number;
135
+ aggregateDurationUnit: AggregateDurationUnit;
136
+ aggregationCount: number;
95
137
  excludedProjectId?: string;
96
138
  }): (repos: {
97
139
  agregation: AggregationRepo;
98
140
  task: TasKRepo;
99
- }) => Promise<void>;
141
+ }) => Promise<{
142
+ aggregationCount: number;
143
+ aggregateDuration: string;
144
+ }>;
100
145
  export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateCheckMovieTicketAction, aggregateEvent, aggregatePayMovieTicketAction, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };