@chevre/domain 23.1.0-alpha.28 → 23.1.0-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,15 @@
1
- /**
2
- * ペイメントカード決済取引バリデーション
3
- */
1
+ import * as factory from '../../../factory';
4
2
  import type { EventRepo } from '../../../repo/event';
5
3
  import type { EventSeriesRepo } from '../../../repo/eventSeries';
6
- import * as factory from '../../../factory';
7
4
  /**
8
5
  * 必要あらば関連リソースの対応決済方法を検証する
9
6
  */
10
7
  export declare function validateAcceptedPaymentMethodIfNeeded(params: Pick<factory.assetTransaction.pay.IStartParamsWithoutDetail, 'object'> | {
11
- object: factory.action.accept.pay.IPayObject;
8
+ object: factory.action.accept.pay.IPayObject & {
9
+ paymentMethod: factory.action.accept.pay.IPaymentMethod & {
10
+ movieTickets: never;
11
+ };
12
+ };
12
13
  }): (repos: {
13
14
  event: EventRepo;
14
15
  eventSeries: EventSeriesRepo;
@@ -10,32 +10,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.validateAcceptedPaymentMethodIfNeeded = validateAcceptedPaymentMethodIfNeeded;
13
+ /**
14
+ * ペイメントカード決済取引バリデーション
15
+ */
16
+ const createDebug = require("debug");
13
17
  const factory = require("../../../factory");
18
+ const debug = createDebug('chevre-domain:service:assetTransaction:pay');
14
19
  /**
15
20
  * 必要あらば関連リソースの対応決済方法を検証する
16
21
  */
17
22
  function validateAcceptedPaymentMethodIfNeeded(params) {
18
23
  return (repos) => __awaiter(this, void 0, void 0, function* () {
19
24
  var _a, _b;
20
- const orderedItems = (_a = params.object.serviceOutput) === null || _a === void 0 ? void 0 : _a.referencesOrder.orderedItem;
21
- if (Array.isArray(orderedItems)) {
22
- const eventIds = orderedItems.map((orderedItem) => orderedItem.orderedItem.serviceOutput.reservationFor.id);
23
- if (eventIds.length === 0) {
25
+ /**
26
+ * 検証対象のイベントIDリスト
27
+ */
28
+ let checkingEventIds;
29
+ const paymentServiceType = params.object.typeOf;
30
+ // CreditCard or MovieTicket?
31
+ if (paymentServiceType === factory.service.paymentService.PaymentServiceType.CreditCard) {
32
+ const orderedItems = (_a = params.object.serviceOutput) === null || _a === void 0 ? void 0 : _a.referencesOrder.orderedItem;
33
+ if (Array.isArray(orderedItems)) {
34
+ checkingEventIds = orderedItems.map((orderedItem) => orderedItem.orderedItem.serviceOutput.reservationFor.id);
35
+ }
36
+ }
37
+ else if (paymentServiceType === factory.service.paymentService.PaymentServiceType.MovieTicket) {
38
+ const movieTickets = params.object.paymentMethod.movieTickets;
39
+ if (Array.isArray(movieTickets)) {
40
+ checkingEventIds = [...new Set(movieTickets.map((ticket) => ticket.serviceOutput.reservationFor.id))];
41
+ // イベントがひとつに特定されているかどうか確認
42
+ if (checkingEventIds.length !== 1) {
43
+ throw new factory.errors.Argument('movieTickets', 'Number of events must be 1');
44
+ }
45
+ }
46
+ }
47
+ else {
48
+ // 対面決済ではひとまず対応決済方法検証なし
49
+ }
50
+ debug('validateAcceptedPaymentMethodIfNeeded: checkingEventIds:', checkingEventIds, paymentServiceType);
51
+ if (Array.isArray(checkingEventIds)) {
52
+ if (checkingEventIds.length === 0) {
24
53
  throw new factory.errors.ArgumentNull('object.serviceOutput.referencesOrder.orderedItem');
25
54
  }
26
55
  // 指定された全イベントについて、施設コンテンツの対応決済方法を検証する
27
56
  const eventSeriesIds = (yield repos.event.projectEventFields({
28
- limit: eventIds.length,
57
+ limit: checkingEventIds.length,
29
58
  page: 1,
30
- id: { $in: eventIds },
59
+ id: { $in: checkingEventIds },
31
60
  typeOf: factory.eventType.ScreeningEvent
32
61
  }, ['superEvent'])).map((event) => event.superEvent.id);
33
- if (eventSeriesIds.length !== eventIds.length) {
62
+ if (eventSeriesIds.length !== checkingEventIds.length) {
34
63
  throw new factory.errors.NotFound(factory.eventType.ScreeningEvent);
35
64
  }
36
65
  const uniqueEventSeriesIds = [...new Set(eventSeriesIds)];
37
- // tslint:disable-next-line:no-console
38
- console.log('validateAcceptedPaymentMethodIfNeeded: eventSeries with AggregateOffer?', uniqueEventSeriesIds);
66
+ debug('validateAcceptedPaymentMethodIfNeeded: eventSeries with AggregateOffer?', uniqueEventSeriesIds);
39
67
  for (const eventSeriesId of uniqueEventSeriesIds) {
40
68
  const eventSeries = (yield repos.eventSeries.projectEventSeriesFields({
41
69
  limit: 1,
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "23.1.0-alpha.28"
118
+ "version": "23.1.0-alpha.29"
119
119
  }