@chevre/domain 20.2.0-alpha.9 → 20.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +37 -0
  2. package/example/src/chevre/aggregation/aggregateSystem.ts +115 -0
  3. package/example/src/chevre/attendIfNotAttended.ts +22 -0
  4. package/example/src/chevre/createManyEventsIfNotExist.ts +209 -0
  5. package/example/src/chevre/findByOrderNumberAndReservationId.ts +20 -0
  6. package/example/src/chevre/findScreeningRoomsByBranchCode.ts +27 -0
  7. package/example/src/chevre/importEventsFromCOA.ts +8 -1
  8. package/example/src/chevre/migrateEventOffersItemOfferedAvailableChannel.ts +2 -1
  9. package/example/src/chevre/migrateOwnershipInfos2newUserPool.ts +1 -1
  10. package/example/src/chevre/migrateProjectSubscription.ts +51 -0
  11. package/example/src/chevre/ownershipInfosCsv2peopleJson.ts +2 -2
  12. package/example/src/chevre/processReserve.ts +2 -0
  13. package/example/src/chevre/searchEventIds.ts +24 -0
  14. package/example/src/chevre/searchEventTicketOffers.ts +5 -4
  15. package/example/src/chevre/searchEvents.ts +20 -41
  16. package/example/src/chevre/searchOfferCatalogs.ts +30 -0
  17. package/example/src/chevre/searchOffersByCatalog.ts +27 -0
  18. package/example/src/chevre/updateTransaction.ts +38 -0
  19. package/lib/chevre/factory/event.d.ts +2 -0
  20. package/lib/chevre/factory/event.js +2 -0
  21. package/lib/chevre/repo/action.d.ts +77 -1
  22. package/lib/chevre/repo/action.js +249 -6
  23. package/lib/chevre/repo/aggregation.d.ts +38 -0
  24. package/lib/chevre/repo/aggregation.js +68 -0
  25. package/lib/chevre/repo/assetTransaction.d.ts +32 -0
  26. package/lib/chevre/repo/assetTransaction.js +148 -0
  27. package/lib/chevre/repo/code.d.ts +13 -16
  28. package/lib/chevre/repo/code.js +33 -19
  29. package/lib/chevre/repo/creativeWork.js +13 -12
  30. package/lib/chevre/repo/event.d.ts +64 -17
  31. package/lib/chevre/repo/event.js +456 -156
  32. package/lib/chevre/repo/mongoose/model/aggregation.d.ts +7 -0
  33. package/lib/chevre/repo/mongoose/model/aggregation.js +47 -0
  34. package/lib/chevre/repo/mongoose/model/event.js +4 -3
  35. package/lib/chevre/repo/mongoose/model/offer.js +2 -1
  36. package/lib/chevre/repo/mongoose/model/project.js +7 -1
  37. package/lib/chevre/repo/mongoose/model/telemetry.js +4 -28
  38. package/lib/chevre/repo/offer.d.ts +10 -0
  39. package/lib/chevre/repo/offer.js +47 -16
  40. package/lib/chevre/repo/offerCatalog.js +28 -30
  41. package/lib/chevre/repo/order.d.ts +6 -0
  42. package/lib/chevre/repo/order.js +53 -7
  43. package/lib/chevre/repo/place.d.ts +26 -1
  44. package/lib/chevre/repo/place.js +216 -12
  45. package/lib/chevre/repo/product.d.ts +1 -0
  46. package/lib/chevre/repo/product.js +5 -0
  47. package/lib/chevre/repo/project.d.ts +7 -1
  48. package/lib/chevre/repo/project.js +15 -6
  49. package/lib/chevre/repo/reservation.d.ts +7 -8
  50. package/lib/chevre/repo/reservation.js +181 -76
  51. package/lib/chevre/repo/task.d.ts +31 -4
  52. package/lib/chevre/repo/task.js +146 -33
  53. package/lib/chevre/repo/transaction.d.ts +57 -5
  54. package/lib/chevre/repo/transaction.js +228 -34
  55. package/lib/chevre/repo/trip.js +33 -27
  56. package/lib/chevre/repository.d.ts +3 -0
  57. package/lib/chevre/repository.js +5 -1
  58. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +72 -60
  59. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +5 -8
  60. package/lib/chevre/service/aggregation/system.d.ts +100 -0
  61. package/lib/chevre/service/aggregation/system.js +409 -0
  62. package/lib/chevre/service/aggregation.d.ts +2 -0
  63. package/lib/chevre/service/aggregation.js +3 -1
  64. package/lib/chevre/service/assetTransaction/pay/movieTicket/validation.js +5 -1
  65. package/lib/chevre/service/assetTransaction/pay/potentialActions.js +0 -3
  66. package/lib/chevre/service/assetTransaction/pay.d.ts +19 -4
  67. package/lib/chevre/service/assetTransaction/pay.js +65 -32
  68. package/lib/chevre/service/assetTransaction/registerService.js +4 -1
  69. package/lib/chevre/service/assetTransaction/reserve/factory.d.ts +3 -0
  70. package/lib/chevre/service/assetTransaction/reserve/factory.js +33 -2
  71. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +16 -0
  72. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +84 -0
  73. package/lib/chevre/service/assetTransaction/reserve.d.ts +38 -6
  74. package/lib/chevre/service/assetTransaction/reserve.js +120 -94
  75. package/lib/chevre/service/assetTransaction.d.ts +1 -1
  76. package/lib/chevre/service/code.d.ts +2 -3
  77. package/lib/chevre/service/delivery/factory.d.ts +1 -1
  78. package/lib/chevre/service/delivery/product/factory.js +9 -3
  79. package/lib/chevre/service/event.d.ts +2 -4
  80. package/lib/chevre/service/event.js +35 -14
  81. package/lib/chevre/service/offer/event/authorize.d.ts +4 -7
  82. package/lib/chevre/service/offer/event/authorize.js +33 -87
  83. package/lib/chevre/service/offer/event/cancel.js +0 -1
  84. package/lib/chevre/service/offer/event/factory.d.ts +3 -2
  85. package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +14 -7
  86. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +95 -53
  87. package/lib/chevre/service/offer/event/voidTransaction.js +0 -2
  88. package/lib/chevre/service/offer/eventServiceByCOA/factory.d.ts +2 -1
  89. package/lib/chevre/service/offer/eventServiceByCOA.js +10 -2
  90. package/lib/chevre/service/offer/factory.js +10 -3
  91. package/lib/chevre/service/offer/product/searchProductOffers.d.ts +1 -0
  92. package/lib/chevre/service/offer/product/searchProductOffers.js +1 -1
  93. package/lib/chevre/service/offer/product.d.ts +1 -0
  94. package/lib/chevre/service/offer/product.js +7 -2
  95. package/lib/chevre/service/offer.d.ts +13 -2
  96. package/lib/chevre/service/offer.js +68 -46
  97. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +23 -26
  98. package/lib/chevre/service/order/returnOrder.js +6 -4
  99. package/lib/chevre/service/order/sendOrder.js +4 -2
  100. package/lib/chevre/service/payment/any.d.ts +9 -0
  101. package/lib/chevre/service/payment/any.js +16 -1
  102. package/lib/chevre/service/payment/movieTicket.d.ts +2 -2
  103. package/lib/chevre/service/payment/movieTicket.js +8 -2
  104. package/lib/chevre/service/product.js +5 -3
  105. package/lib/chevre/service/report/telemetry.js +1 -1
  106. package/lib/chevre/service/reserve/checkInReservation.js +2 -2
  107. package/lib/chevre/service/reserve/confirmReservation.js +7 -10
  108. package/lib/chevre/service/reserve/potentialActions/onReservationCanceled.js +2 -1
  109. package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +2 -1
  110. package/lib/chevre/service/reserve/potentialActions/onReservationConfirmed.js +2 -1
  111. package/lib/chevre/service/reserve/potentialActions/onReservationUsed.js +32 -35
  112. package/lib/chevre/service/reserve/useReservation.d.ts +0 -3
  113. package/lib/chevre/service/reserve/useReservation.js +58 -33
  114. package/lib/chevre/service/task/confirmPayTransaction.js +20 -1
  115. package/lib/chevre/service/task/confirmReserveTransaction.d.ts +4 -0
  116. package/lib/chevre/service/task/confirmReserveTransaction.js +5 -5
  117. package/lib/chevre/service/task/importEventsFromCOA.js +3 -1
  118. package/lib/chevre/service/task/returnPayTransaction.js +10 -4
  119. package/lib/chevre/service/task.js +6 -9
  120. package/lib/chevre/service/transaction/moneyTransfer.js +9 -1
  121. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.d.ts +1 -1
  122. package/lib/chevre/service/transaction/orderProgramMembership.js +6 -6
  123. package/lib/chevre/service/transaction/placeOrder.js +5 -3
  124. package/lib/chevre/service/transaction/placeOrderInProgress/factory.d.ts +1 -1
  125. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.d.ts +0 -2
  126. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +2 -11
  127. package/lib/chevre/service/transaction/placeOrderInProgress/validation/validateSeller.d.ts +1 -1
  128. package/lib/chevre/service/transaction/placeOrderInProgress.d.ts +3 -8
  129. package/lib/chevre/service/transaction/placeOrderInProgress.js +92 -107
  130. package/lib/chevre/service/transaction/returnOrder.js +8 -6
  131. package/lib/chevre/settings.d.ts +2 -0
  132. package/lib/chevre/settings.js +20 -12
  133. package/package.json +3 -3
  134. package/example/src/chevre/aggregateReservationOnProject.ts +0 -32
  135. package/example/src/chevre/migratePlaceAdditionalProperties.ts +0 -162
  136. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.d.ts +0 -6
  137. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/confirmPay.js +0 -65
@@ -30,34 +30,31 @@ function getOrderWithToken(params) {
30
30
  return params.order;
31
31
  }
32
32
  // 冗長な個人情報をマスク(最低限の情報に)
33
- const customer4orderToken = (params.order.customer.typeOf === factory.organizationType.Organization)
34
- ? {
35
- id: params.order.customer.id,
36
- name: '****',
37
- // project: params.order.customer.project,
38
- typeOf: params.order.customer.typeOf
39
- }
40
- : {
41
- id: params.order.customer.id,
42
- typeOf: params.order.customer.typeOf
43
- };
44
- const seller4orderToken = {
45
- id: params.order.seller.id,
46
- // 最適化(2022-11-15~)
47
- // project: params.order.seller.project,
48
- typeOf: params.order.seller.typeOf
49
- };
33
+ // const customer4orderToken: factory.order.ISimpleCustomer =
34
+ // (params.order.customer.typeOf === factory.organizationType.Organization)
35
+ // ? {
36
+ // id: params.order.customer.id,
37
+ // name: '****',
38
+ // // project: params.order.customer.project,
39
+ // typeOf: params.order.customer.typeOf
40
+ // }
41
+ // : {
42
+ // id: params.order.customer.id,
43
+ // typeOf: params.order.customer.typeOf
44
+ // };
45
+ // const seller4orderToken: Omit<factory.order.ISeller, 'name'> = {
46
+ // id: params.order.seller.id,
47
+ // typeOf: params.order.seller.typeOf
48
+ // };
49
+ // 最適化(2023-01-31~)
50
50
  const order4token = {
51
- // project: params.order.project,
52
51
  typeOf: params.order.typeOf,
53
- seller: seller4orderToken,
54
- customer: customer4orderToken,
55
- // IOrderへ移行(2022-11-17~)
56
- // confirmationNumber: params.order.confirmationNumber,
57
- orderNumber: params.order.orderNumber,
58
- price: params.order.price,
59
- priceCurrency: params.order.priceCurrency,
60
- orderDate: params.order.orderDate
52
+ // seller: seller4orderToken,
53
+ // customer: customer4orderToken,
54
+ orderNumber: params.order.orderNumber
55
+ // price: params.order.price,
56
+ // priceCurrency: params.order.priceCurrency,
57
+ // orderDate: params.order.orderDate
61
58
  };
62
59
  const token = yield new Promise((resolve, reject) => {
63
60
  // 所有権を暗号化する
@@ -21,7 +21,7 @@ function returnOrder(params) {
21
21
  ? params.object.dateReturned
22
22
  : new Date();
23
23
  const returner = params.agent;
24
- let order = yield repos.order.findByOrderNumber({ orderNumber });
24
+ let order = yield repos.order.findByOrderNumber({ orderNumber, inclusion: [], exclusion: [] });
25
25
  // プロジェクト条件検証
26
26
  if (order.project.id !== params.project.id) {
27
27
  throw new factory.errors.NotFound('Order');
@@ -202,8 +202,10 @@ function onReturn(returnActionAttributes) {
202
202
  }
203
203
  }
204
204
  // タスク保管
205
- yield Promise.all(taskAttributes.map((taskAttribute) => __awaiter(this, void 0, void 0, function* () {
206
- return repos.task.save(taskAttribute);
207
- })));
205
+ // saveManyに変更(2023-02-01~)
206
+ yield repos.task.saveMany(taskAttributes);
207
+ // await Promise.all(taskAttributes.map(async (taskAttribute) => {
208
+ // return repos.task.save(taskAttribute);
209
+ // }));
208
210
  });
209
211
  }
@@ -31,7 +31,7 @@ function sendOrder(params) {
31
31
  orderNumber
32
32
  })({ transaction: repos.transaction });
33
33
  // 注文取得
34
- let order = yield repos.order.findByOrderNumber({ orderNumber });
34
+ let order = yield repos.order.findByOrderNumber({ orderNumber, inclusion: [], exclusion: [] });
35
35
  // プロジェクト条件検証
36
36
  if (order.project.id !== params.project.id) {
37
37
  throw new factory.errors.NotFound('Order');
@@ -100,7 +100,9 @@ function sendOrder(params) {
100
100
  let throwsError = true;
101
101
  // すでにOrderReturnedだった場合、OrderDelivered->OrderReturnedの処理自体は成功しているので、後処理を続行する
102
102
  const currentOrder = yield repos.order.findByOrderNumber({
103
- orderNumber: params.object.orderNumber
103
+ orderNumber: params.object.orderNumber,
104
+ inclusion: ['orderStatus'],
105
+ exclusion: []
104
106
  });
105
107
  if ((currentOrder === null || currentOrder === void 0 ? void 0 : currentOrder.orderStatus) === factory.orderStatus.OrderReturned) {
106
108
  throwsError = false;
@@ -47,7 +47,12 @@ declare function invalidatePaymentUrl(params: factory.task.IData<factory.taskNam
47
47
  */
48
48
  declare function processVoidPayTransaction(params: factory.task.IData<factory.taskName.VoidPayTransaction>): (repos: {
49
49
  action: ActionRepo;
50
+ accountingReport: AccountingReportRepo;
50
51
  assetTransaction: AssetTransactionRepo;
52
+ product: ProductRepo;
53
+ project: ProjectRepo;
54
+ seller: SellerRepo;
55
+ task: TaskRepo;
51
56
  transaction: TransactionRepo;
52
57
  }) => Promise<void>;
53
58
  interface IAuthorizeRepos {
@@ -103,5 +108,9 @@ declare function authorize(params: {
103
108
  purpose: factory.action.authorize.paymentMethod.any.IPurpose;
104
109
  paymentServiceType: factory.service.paymentService.PaymentServiceType;
105
110
  location?: factory.action.trade.pay.ILocation;
111
+ /**
112
+ * アクション失敗時に即時に決済取引を中止するかどうか
113
+ */
114
+ useCancelPayTransactionOnFailed: boolean;
106
115
  }): IAuthorizeOperation<IAuthorizePaymentAction>;
107
116
  export { onPaymentStatusChanged, authorize, invalidatePaymentUrl, voidPayTransaction, person2username, processVoidPayTransaction, publishPaymentUrl };
@@ -189,7 +189,7 @@ function publishPaymentUrl(params) {
189
189
  };
190
190
  yield repos.transaction.findByIdAndUpdate({
191
191
  id: transaction.id,
192
- update: { 'object.paymentMethods': paymentMethodByPaymentUrl }
192
+ update: { $set: { 'object.paymentMethods': paymentMethodByPaymentUrl } }
193
193
  });
194
194
  return result;
195
195
  });
@@ -268,6 +268,15 @@ function authorize(params) {
268
268
  catch (__) {
269
269
  // no op
270
270
  }
271
+ // 即時に決済取引を中止するか?(2023-02-03~)
272
+ if (params.useCancelPayTransactionOnFailed) {
273
+ yield processVoidPayTransaction({
274
+ project: action.project,
275
+ agent: { id: action.project.id },
276
+ id: action.id,
277
+ purpose: action.purpose
278
+ })(repos);
279
+ }
271
280
  throw error;
272
281
  }
273
282
  // アクションを完了
@@ -288,6 +297,12 @@ function validateFromLocation(params) {
288
297
  agent: { id: params.project.id, typeOf: factory.organizationType.Project },
289
298
  token: fromLocation
290
299
  })(repos);
300
+ if (paymentCardOwnershipInfo.typeOf !== 'OwnershipInfo') {
301
+ throw new factory.errors.Argument('fromLocation', 'must be OwnershipInfo');
302
+ }
303
+ if (paymentCardOwnershipInfo.typeOfGood.typeOf !== factory.permit.PermitType.Permit) {
304
+ throw new factory.errors.Argument('fromLocation', 'must be Permit');
305
+ }
291
306
  accountId = paymentCardOwnershipInfo.typeOfGood.identifier;
292
307
  }
293
308
  return { accountId };
@@ -1,6 +1,6 @@
1
1
  import { MongoRepository as AccountingReportRepo } from '../../repo/accountingReport';
2
2
  import { MongoRepository as ActionRepo } from '../../repo/action';
3
- import { MongoRepository as EventRepo } from '../../repo/event';
3
+ import { IMinimizedIndividualEvent, MongoRepository as EventRepo } from '../../repo/event';
4
4
  import { MongoRepository as ProductRepo } from '../../repo/product';
5
5
  import { MongoRepository as ProjectRepo } from '../../repo/project';
6
6
  import { MongoRepository as SellerRepo } from '../../repo/seller';
@@ -50,7 +50,7 @@ declare function checkMovieTicket(params: factory.action.check.paymentMethod.mov
50
50
  declare function checkByIdentifier(params: {
51
51
  movieTickets: IMovieTicket[];
52
52
  seller: factory.seller.ISeller;
53
- screeningEvent: factory.event.IEvent<factory.eventType.ScreeningEvent>;
53
+ screeningEvent: IMinimizedIndividualEvent<factory.eventType.ScreeningEvent>;
54
54
  paymentServiceId: string;
55
55
  }): (repos: {
56
56
  product: ProductRepo;
@@ -53,7 +53,11 @@ function checkMovieTicket(params) {
53
53
  }
54
54
  // イベント情報取得
55
55
  let screeningEvent;
56
- screeningEvent = yield repos.event.findById({
56
+ // イベント取得属性最適化(2023-01-23~)
57
+ // screeningEvent = await repos.event.findById<factory.eventType.ScreeningEvent>({
58
+ // id: eventIds[0]
59
+ // });
60
+ screeningEvent = yield repos.event.findMinimizedIndividualEventById({
57
61
  id: eventIds[0]
58
62
  });
59
63
  // ショップ情報取得
@@ -432,7 +436,9 @@ function payActionParams2seatInfoSyncIn(params) {
432
436
  if (eventIds.length !== 1) {
433
437
  throw new factory.errors.Argument('movieTickets', 'Number of events must be 1');
434
438
  }
435
- const event = yield repos.event.findById({ id: eventIds[0] });
439
+ // イベント取得属性最適化(2023-01-23~)
440
+ // const event = await repos.event.findById<factory.eventType.ScreeningEvent>({ id: eventIds[0] });
441
+ const event = yield repos.event.findMinimizedIndividualEventById({ id: eventIds[0] });
436
442
  const seller = yield repos.seller.findById({ id: String((_d = params.recipient) === null || _d === void 0 ? void 0 : _d.id) });
437
443
  // 全購入管理番号のMovieTicketをマージ
438
444
  const movieTickets = params.object.reduce((a, b) => [...a, ...(Array.isArray(b.movieTickets)) ? b.movieTickets : []], []);
@@ -77,8 +77,10 @@ function onRegistered(actionAttributes, __) {
77
77
  }
78
78
  }
79
79
  // タスク保管
80
- yield Promise.all(taskAttributes.map((taskAttribute) => __awaiter(this, void 0, void 0, function* () {
81
- return repos.task.save(taskAttribute);
82
- })));
80
+ // saveManyに変更(2023-02-01~)
81
+ yield repos.task.saveMany(taskAttributes);
82
+ // await Promise.all(taskAttributes.map(async (taskAttribute) => {
83
+ // return repos.task.save(taskAttribute);
84
+ // }));
83
85
  });
84
86
  }
@@ -181,7 +181,7 @@ function createSellerFlow(measuredFrom, measuredThrough, sellerId) {
181
181
  const actionsOnExpiredTransactions = yield repos.action.search({
182
182
  typeOf: { $eq: factory.actionType.AuthorizeAction },
183
183
  purpose: { id: { $in: expiredTransactionIds } }
184
- });
184
+ }, [], []);
185
185
  debug(actionsOnExpiredTransactions.length, 'actionsOnExpiredTransactions found.');
186
186
  const numbersOfActionsOnExpired = expiredTransactionIds.map((transactionId) => {
187
187
  return actionsOnExpiredTransactions.filter((action) => action.purpose.id === transactionId).length;
@@ -17,11 +17,11 @@ function checkInRerservation(params) {
17
17
  // 発券処理(Array対応)
18
18
  let checkedInReservationIds;
19
19
  if (Array.isArray(params.object.ids) && params.object.ids.length > 0) {
20
- yield repos.reservation.checkIn({ id: { $in: params.object.ids }, now });
20
+ yield repos.reservation.checkInIfNot({ id: { $in: params.object.ids }, now });
21
21
  checkedInReservationIds = params.object.ids;
22
22
  }
23
23
  if (Array.isArray(params.object.reservationNumbers) && params.object.reservationNumbers.length > 0) {
24
- yield repos.reservation.checkIn({ reservationNumber: { $in: params.object.reservationNumbers }, now });
24
+ yield repos.reservation.checkInIfNot({ reservationNumber: { $in: params.object.reservationNumbers }, now });
25
25
  // 予約番号リストを予約IDリストに変換
26
26
  checkedInReservationIds = yield repos.reservation.searchIdsByReservationNumber({
27
27
  reservationNumber: { $in: params.object.reservationNumbers }
@@ -37,17 +37,14 @@ function confirmReservation(actionAttributesList) {
37
37
  });
38
38
  }
39
39
  else {
40
+ // 廃止(2023-01-18)
41
+ throw new factory.errors.Forbidden(`${reservation.typeOf} not acceptable`);
40
42
  // 予約を確定状態に変更する
41
- // reservation = await repos.reservation.confirm<factory.reservationType.EventReservation>({
42
- yield repos.reservation.confirm({
43
- // 更新属性をwhitelist化(2022-06-13~)
44
- // ...actionAttributes.object,
45
- id: reservation.id,
46
- previousReservationStatus: reservation.reservationStatus,
47
- underName: reservation.underName
48
- // issuedThroughは予約取引開始時に確定しているので更新不要(2022-12-21~)
49
- // reservedTicket: reservation.reservedTicket
50
- });
43
+ // await repos.reservation.confirm<factory.reservationType.EventReservation>({
44
+ // id: reservation.id,
45
+ // previousReservationStatus: reservation.reservationStatus,
46
+ // underName: reservation.underName
47
+ // });
51
48
  // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
52
49
  // delete (<any>reservation)._id;
53
50
  // confirmedReservations.push(reservation);
@@ -96,7 +96,8 @@ function onReservationCanceled(canceledReservations, useInformReservation) {
96
96
  // 冗長な作成を避ける
97
97
  yield (0, offer_1.createAggregateScreeningEventIfNotExist)({
98
98
  project,
99
- reservationFor: { id: canceledReservations[0].reservationFor.id }
99
+ reservationFor: [{ id: canceledReservations[0].reservationFor.id }],
100
+ force: false
100
101
  })({ task: repos.task });
101
102
  }
102
103
  });
@@ -116,7 +116,8 @@ function onReservationCheckedIn(params) {
116
116
  yield Promise.all(reservationForIds.map((reservationForId) => __awaiter(this, void 0, void 0, function* () {
117
117
  yield (0, offer_1.createAggregateScreeningEventIfNotExist)({
118
118
  project: { id: params.project.id },
119
- reservationFor: { id: reservationForId }
119
+ reservationFor: [{ id: reservationForId }],
120
+ force: false
120
121
  })({ task: repos.task });
121
122
  })));
122
123
  }
@@ -98,7 +98,8 @@ function onReservationConfirmed(confirmedReservations) {
98
98
  if (Array.isArray(confirmedReservations) && confirmedReservations.length > 0) {
99
99
  yield (0, offer_1.createAggregateScreeningEventIfNotExist)({
100
100
  project: confirmedReservations[0].project,
101
- reservationFor: { id: confirmedReservations[0].reservationFor.id }
101
+ reservationFor: [{ id: confirmedReservations[0].reservationFor.id }],
102
+ force: false
102
103
  })({ task: repos.task });
103
104
  const now = new Date();
104
105
  const taskAttributes = [];
@@ -8,7 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var _a;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.onReservationUsed = void 0;
14
13
  /**
@@ -20,7 +19,6 @@ const settings_1 = require("../../../settings");
20
19
  const offer_1 = require("../../offer");
21
20
  const factory_1 = require("../factory");
22
21
  const informReservations = settings_1.settings.onReservationStatusChanged.informReservation;
23
- const informUseReservations = (_a = settings_1.settings.onReservationUsed) === null || _a === void 0 ? void 0 : _a.informAction;
24
22
  const INFORM_TASK_DELAY_IN_SECONDS = 30;
25
23
  /**
26
24
  * 予約使用
@@ -28,41 +26,39 @@ const INFORM_TASK_DELAY_IN_SECONDS = 30;
28
26
  function onReservationUsed(action, attendedReservation) {
29
27
  // tslint:disable-next-line:max-func-body-length
30
28
  return (repos) => __awaiter(this, void 0, void 0, function* () {
31
- // const reservation = action.object[0];
32
29
  const tasks = [];
33
30
  const now = new Date();
31
+ // INFORM_USE_RESERVATION_URL廃止(2023-01-30~)
34
32
  // アクション通知タスク作成
35
- if (Array.isArray(informUseReservations)) {
36
- informUseReservations.filter((informUseReservation) => {
37
- var _a;
38
- return typeof ((_a = informUseReservation.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string'
39
- && informUseReservation.recipient.url.length > 0;
40
- })
41
- .forEach((informUseReservation) => {
42
- var _a, _b;
43
- const triggerWebhookTask = {
44
- project: action.project,
45
- name: factory.taskName.TriggerWebhook,
46
- status: factory.taskStatus.Ready,
47
- runsAt: now,
48
- remainingNumberOfTries: 3,
49
- numberOfTried: 0,
50
- executionResults: [],
51
- data: {
52
- project: action.project,
53
- typeOf: factory.actionType.InformAction,
54
- agent: action.project,
55
- recipient: {
56
- typeOf: factory.personType.Person,
57
- id: String((_a = informUseReservation.recipient) === null || _a === void 0 ? void 0 : _a.url),
58
- url: String((_b = informUseReservation.recipient) === null || _b === void 0 ? void 0 : _b.url)
59
- },
60
- object: action
61
- }
62
- };
63
- tasks.push(triggerWebhookTask);
64
- });
65
- }
33
+ // if (Array.isArray(informUseReservations)) {
34
+ // informUseReservations.filter((informUseReservation) => {
35
+ // return typeof informUseReservation.recipient?.url === 'string'
36
+ // && informUseReservation.recipient.url.length > 0;
37
+ // })
38
+ // .forEach((informUseReservation) => {
39
+ // const triggerWebhookTask: factory.task.triggerWebhook.IAttributes = {
40
+ // project: action.project,
41
+ // name: factory.taskName.TriggerWebhook,
42
+ // status: factory.taskStatus.Ready,
43
+ // runsAt: now,
44
+ // remainingNumberOfTries: 3,
45
+ // numberOfTried: 0,
46
+ // executionResults: [],
47
+ // data: {
48
+ // project: action.project,
49
+ // typeOf: factory.actionType.InformAction,
50
+ // agent: action.project,
51
+ // recipient: {
52
+ // typeOf: factory.personType.Person,
53
+ // id: String(informUseReservation.recipient?.url),
54
+ // url: String(informUseReservation.recipient?.url)
55
+ // },
56
+ // object: action
57
+ // }
58
+ // };
59
+ // tasks.push(triggerWebhookTask);
60
+ // });
61
+ // }
66
62
  // inform galobally
67
63
  if (Array.isArray(informReservations)) {
68
64
  // やや遅延させる(確定通知が未達の可能性を考慮して)
@@ -134,7 +130,8 @@ function onReservationUsed(action, attendedReservation) {
134
130
  // 冗長な作成を避ける
135
131
  yield (0, offer_1.createAggregateScreeningEventIfNotExist)({
136
132
  project: attendedReservation.project,
137
- reservationFor: { id: attendedReservation.reservationFor.id }
133
+ reservationFor: [{ id: attendedReservation.reservationFor.id }],
134
+ force: false
138
135
  })({ task: repos.task });
139
136
  });
140
137
  }
@@ -11,9 +11,6 @@ import { IUseReservationAction } from './potentialActions/onReservationUsed';
11
11
  * 予約使用
12
12
  */
13
13
  export declare function useReservation(params: {
14
- project: {
15
- id: string;
16
- };
17
14
  agent: factory.action.consume.use.reservation.IAgent;
18
15
  object: {
19
16
  /**
@@ -15,7 +15,7 @@ exports.useReservation = void 0;
15
15
  */
16
16
  const factory = require("../../factory");
17
17
  const code_1 = require("../code");
18
- const factory_1 = require("./factory");
18
+ // import { maskUnderName } from './factory';
19
19
  const onReservationUsed_1 = require("./potentialActions/onReservationUsed");
20
20
  function verifyToken4reservation(params) {
21
21
  return (repos) => __awaiter(this, void 0, void 0, function* () {
@@ -26,8 +26,18 @@ function verifyToken4reservation(params) {
26
26
  })({});
27
27
  switch (payload.typeOf) {
28
28
  case factory.order.OrderType.Order:
29
+ // reservationIdを含む注文の存在を確認するだけでよい(2023-01-31~)
30
+ const order = yield repos.order.findByOrderNumberAndReservationId({
31
+ orderNumber: payload.orderNumber,
32
+ reservationId: params.reservationId
33
+ });
29
34
  // 注文検索
30
- const order = yield repos.order.findByOrderNumber({ orderNumber: payload.orderNumber });
35
+ // const order: Pick<factory.order.IOrder, 'orderStatus' | 'acceptedOffers'> =
36
+ // await repos.order.findByOrderNumber({
37
+ // orderNumber: payload.orderNumber,
38
+ // inclusion: ['orderStatus', 'acceptedOffers'],
39
+ // exclusion: []
40
+ // });
31
41
  // ステータス検証
32
42
  switch (order.orderStatus) {
33
43
  case factory.orderStatus.OrderDelivered:
@@ -35,15 +45,17 @@ function verifyToken4reservation(params) {
35
45
  default:
36
46
  throw new factory.errors.Argument('token', `invalid orderStatus '${order.orderStatus}'`);
37
47
  }
38
- const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
39
- const reservationExistsInOrder = acceptedOffers.some((offer) => {
40
- return (offer.itemOffered.typeOf === factory.reservationType.EventReservation
41
- || offer.itemOffered.typeOf === factory.reservationType.BusReservation)
42
- && offer.itemOffered.id === params.reservationId;
43
- });
44
- if (!reservationExistsInOrder) {
45
- throw new factory.errors.NotFound('AcceptedOffer');
46
- }
48
+ // const acceptedOffers = (Array.isArray(order.acceptedOffers)) ? order.acceptedOffers : [];
49
+ // const reservationExistsInOrder = acceptedOffers.some((offer) => {
50
+ // return (
51
+ // offer.itemOffered.typeOf === factory.reservationType.EventReservation
52
+ // || offer.itemOffered.typeOf === factory.reservationType.BusReservation
53
+ // )
54
+ // && offer.itemOffered.id === params.reservationId;
55
+ // });
56
+ // if (!reservationExistsInOrder) {
57
+ // throw new factory.errors.NotFound('AcceptedOffer');
58
+ // }
47
59
  break;
48
60
  default:
49
61
  throw new factory.errors.NotImplemented(`Payload type ${payload.typeOf} not implemented`);
@@ -53,54 +65,67 @@ function verifyToken4reservation(params) {
53
65
  /**
54
66
  * 予約使用
55
67
  */
56
- // export function useReservation(actionAttributes: factory.action.consume.use.reservation.IAttributes) {
68
+ // tslint:disable-next-line:max-func-body-length
57
69
  function useReservation(params) {
58
70
  return (repos) => __awaiter(this, void 0, void 0, function* () {
59
- var _a, _b, _c;
71
+ var _a, _b;
60
72
  const now = new Date();
73
+ const reservationId = params.object.id;
61
74
  // 予約検索
62
- let reservation = yield repos.reservation.findById({ id: params.object.id });
75
+ // 取得属性最適化(2023-01-30~)
76
+ const reservation = yield repos.reservation.findById({
77
+ id: reservationId,
78
+ inclusion: ['id', 'issuedThrough', 'project', 'reservationFor', 'reservationNumber', 'reservedTicket', 'typeOf']
79
+ });
63
80
  // instrument?.tokenを検証
64
81
  const token = (_a = params === null || params === void 0 ? void 0 : params.instrument) === null || _a === void 0 ? void 0 : _a.token;
65
82
  if (typeof token === 'string') {
66
83
  yield verifyToken4reservation({
67
- project: { id: params.project.id },
84
+ project: { id: reservation.project.id },
68
85
  agent: params.agent,
69
- reservationId: params.object.id,
86
+ reservationId,
70
87
  token
71
88
  })({ order: repos.order });
72
89
  }
73
90
  // UseActionを作成する
74
- const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), {
75
- typeOf: factory.action.check.token.ObjectType.Ticket
76
- }),
91
+ const reservationAsObject = {
92
+ id: reservation.id,
93
+ issuedThrough: reservation.issuedThrough,
94
+ reservationFor: reservation.reservationFor,
95
+ reservationNumber: reservation.reservationNumber,
96
+ reservedTicket: reservation.reservedTicket,
97
+ typeOf: reservation.typeOf
98
+ };
99
+ const actionAttributes = Object.assign({ project: reservation.project, typeOf: factory.actionType.UseAction, agent: params.agent, instrument: Object.assign(Object.assign({}, (typeof token === 'string') ? { token } : undefined), { typeOf: factory.action.check.token.ObjectType.Ticket }),
100
+ // object最適化(2023-01-30~)
77
101
  // どの予約を
78
102
  // mask
79
- object: [(0, factory_1.maskUnderName)(reservation)] }, (typeof ((_b = params.location) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
103
+ // object: [maskUnderName(reservation)],
104
+ object: [reservationAsObject] }, (typeof ((_b = params.location) === null || _b === void 0 ? void 0 : _b.identifier) === 'string')
80
105
  ? {
81
106
  location: {
82
107
  typeOf: factory.placeType.Place,
83
108
  identifier: params.location.identifier
84
109
  }
85
110
  }
86
- : undefined
87
- // purpose: params.purpose
88
- );
111
+ : undefined);
89
112
  let action = yield repos.action.start(actionAttributes);
90
113
  // ひとまず予約数:1に限定する
91
114
  if (actionAttributes.object.length !== 1) {
92
115
  throw new factory.errors.Argument('object', 'number of using reservations must be 1');
93
116
  }
94
- reservation = actionAttributes.object[0];
117
+ let attendedReservation;
95
118
  try {
96
- reservation = (yield repos.reservation.attend({ id: reservation.id, now }));
97
- // 使用日時がなければ追加
98
- if (((_c = reservation.reservedTicket) === null || _c === void 0 ? void 0 : _c.dateUsed) === undefined) {
99
- reservation = yield repos.reservation.updatePartiallyById({
100
- id: reservation.id,
101
- update: { 'reservedTicket.dateUsed': now }
102
- });
103
- }
119
+ // 使用日時と同時更新(2023-01-30~)
120
+ attendedReservation = (yield repos.reservation.attendIfNotAttended({ id: reservationId, now }));
121
+ // attendedReservation = <IEventReservation>await repos.reservation.attend({ id: reservationId, now });
122
+ // // 使用日時がなければ追加
123
+ // if (attendedReservation.reservedTicket?.dateUsed === undefined) {
124
+ // attendedReservation = await repos.reservation.updatePartiallyById({
125
+ // id: attendedReservation.id,
126
+ // update: { 'reservedTicket.dateUsed': now }
127
+ // });
128
+ // }
104
129
  }
105
130
  catch (error) {
106
131
  // actionにエラー結果を追加
@@ -115,7 +140,7 @@ function useReservation(params) {
115
140
  }
116
141
  // アクション完了
117
142
  action = (yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: {} }));
118
- yield (0, onReservationUsed_1.onReservationUsed)(action, reservation)({ task: repos.task });
143
+ yield (0, onReservationUsed_1.onReservationUsed)(action, attendedReservation)({ task: repos.task });
119
144
  return action;
120
145
  });
121
146
  }
@@ -10,9 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
+ const accountingReport_1 = require("../../repo/accountingReport");
13
14
  const action_1 = require("../../repo/action");
14
15
  const assetTransaction_1 = require("../../repo/assetTransaction");
16
+ const event_1 = require("../../repo/event");
15
17
  const order_1 = require("../../repo/order");
18
+ const product_1 = require("../../repo/product");
19
+ const project_1 = require("../../repo/project");
20
+ const seller_1 = require("../../repo/seller");
21
+ const task_1 = require("../../repo/task");
16
22
  const PayTransactionService = require("../assetTransaction/pay");
17
23
  /**
18
24
  * タスク実行関数
@@ -22,6 +28,12 @@ function call(data) {
22
28
  const actionRepo = new action_1.MongoRepository(settings.connection);
23
29
  const assetTransactionRepo = new assetTransaction_1.MongoRepository(settings.connection);
24
30
  const orderRepo = new order_1.MongoRepository(settings.connection);
31
+ const accountingReportRepo = new accountingReport_1.MongoRepository(settings.connection);
32
+ const eventRepo = new event_1.MongoRepository(settings.connection);
33
+ const productRepo = new product_1.MongoRepository(settings.connection);
34
+ const projectRepo = new project_1.MongoRepository(settings.connection);
35
+ const sellerRepo = new seller_1.MongoRepository(settings.connection);
36
+ const taskRepo = new task_1.MongoRepository(settings.connection);
25
37
  // アクション開始
26
38
  const action = yield actionRepo.start(data);
27
39
  try {
@@ -38,8 +50,15 @@ function call(data) {
38
50
  }
39
51
  }
40
52
  })({
53
+ action: actionRepo,
54
+ accountingReport: accountingReportRepo,
41
55
  assetTransaction: assetTransactionRepo,
42
- order: orderRepo
56
+ event: eventRepo,
57
+ order: orderRepo,
58
+ product: productRepo,
59
+ project: projectRepo,
60
+ seller: sellerRepo,
61
+ task: taskRepo
43
62
  });
44
63
  }
45
64
  }
@@ -3,6 +3,8 @@ import * as factory from '../../factory';
3
3
  import { MongoRepository as ActionRepo } from '../../repo/action';
4
4
  import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
5
5
  import { MongoRepository as OrderRepo } from '../../repo/order';
6
+ import { MongoRepository as ReservationRepo } from '../../repo/reservation';
7
+ import { MongoRepository as TaskRepo } from '../../repo/task';
6
8
  /**
7
9
  * タスク実行関数
8
10
  */
@@ -14,4 +16,6 @@ export declare function confirmReserveTransaction(params: factory.action.interac
14
16
  action: ActionRepo;
15
17
  assetTransaction: AssetTransactionRepo;
16
18
  order: OrderRepo;
19
+ reservation: ReservationRepo;
20
+ task: TaskRepo;
17
21
  }) => Promise<void>;