@chevre/domain 20.2.0-alpha.33 → 20.2.0-alpha.35

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.
@@ -95,6 +95,14 @@ async function main() {
95
95
  agregation: aggregationRepo,
96
96
  action: actionRepo
97
97
  });
98
+
99
+ await chevre.service.aggregation.system.aggregateCheckMovieTicketAction({
100
+ aggregationDays: AGGREGATE_DAYS,
101
+ excludedProjectId: EXCLUDED_PROJECT_ID
102
+ })({
103
+ agregation: aggregationRepo,
104
+ action: actionRepo
105
+ });
98
106
  }
99
107
 
100
108
  main()
@@ -23,7 +23,8 @@ async function main() {
23
23
 
24
24
  const { ticketOffers } = await chevre.service.offer.event.searchEventTicketOffers({
25
25
  event: { id: 'al9ew43f5' },
26
- onlyValid: true
26
+ onlyValid: true,
27
+ sort: true
27
28
  // ...(typeof sellerId === 'string') ? { seller: { id: sellerId } } : undefined,
28
29
  // ...(typeof availableAtId === 'string') ? { store: { id: availableAtId } } : undefined
29
30
  })({
@@ -15,7 +15,8 @@ async function main() {
15
15
  offerCatalog: {
16
16
  id: '0001'
17
17
  // id: 'xxx'
18
- }
18
+ },
19
+ sort: true
19
20
  });
20
21
  console.log(offers.map((o) => o.id));
21
22
  console.log(offers.length);
@@ -164,5 +164,14 @@ export declare class MongoRepository {
164
164
  startThrough: Date;
165
165
  typeOf: factory.actionType;
166
166
  }): Promise<IAggregateAction>;
167
+ aggregateCheckMovieTicketAction(params: {
168
+ project?: {
169
+ id?: {
170
+ $ne?: string;
171
+ };
172
+ };
173
+ startFrom: Date;
174
+ startThrough: Date;
175
+ }): Promise<IAggregateAction>;
167
176
  private agggregateByStatus;
168
177
  }
@@ -762,6 +762,28 @@ class MongoRepository {
762
762
  return { statuses };
763
763
  });
764
764
  }
765
+ aggregateCheckMovieTicketAction(params) {
766
+ return __awaiter(this, void 0, void 0, function* () {
767
+ const statuses = yield Promise.all([
768
+ factory.actionStatusType.CompletedActionStatus,
769
+ factory.actionStatusType.CanceledActionStatus,
770
+ factory.actionStatusType.FailedActionStatus
771
+ ].map((actionStatus) => __awaiter(this, void 0, void 0, function* () {
772
+ var _a, _b;
773
+ const matchConditions = Object.assign({ startDate: {
774
+ $gte: params.startFrom,
775
+ $lte: params.startThrough
776
+ }, typeOf: { $eq: factory.actionType.CheckAction }, 'object.typeOf': {
777
+ $exists: true,
778
+ $eq: factory.service.paymentService.PaymentServiceType.MovieTicket
779
+ }, actionStatus: { $eq: actionStatus } }, (typeof ((_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$ne) === 'string')
780
+ ? { 'project.id': { $ne: params.project.id.$ne } }
781
+ : undefined);
782
+ return this.agggregateByStatus({ matchConditions, actionStatus });
783
+ })));
784
+ return { statuses };
785
+ });
786
+ }
765
787
  // tslint:disable-next-line:max-func-body-length
766
788
  agggregateByStatus(params) {
767
789
  return __awaiter(this, void 0, void 0, function* () {
@@ -4,6 +4,7 @@ export declare enum AggregationType {
4
4
  AggregateAuthorizeEventServiceOfferAction = "AggregateAuthorizeEventServiceOfferAction",
5
5
  AggregateAuthorizeOrderAction = "AggregateAuthorizeOrderAction",
6
6
  AggregateAuthorizePaymentAction = "AggregateAuthorizePaymentAction",
7
+ AggregateCheckMovieTicketAction = "AggregateCheckMovieTicketAction",
7
8
  AggregateEvent = "AggregateEvent",
8
9
  AggregatePay = "AggregatePay",
9
10
  AggregatePlaceOrder = "AggregatePlaceOrder",
@@ -27,6 +27,7 @@ var AggregationType;
27
27
  AggregationType["AggregateAuthorizeEventServiceOfferAction"] = "AggregateAuthorizeEventServiceOfferAction";
28
28
  AggregationType["AggregateAuthorizeOrderAction"] = "AggregateAuthorizeOrderAction";
29
29
  AggregationType["AggregateAuthorizePaymentAction"] = "AggregateAuthorizePaymentAction";
30
+ AggregationType["AggregateCheckMovieTicketAction"] = "AggregateCheckMovieTicketAction";
30
31
  AggregationType["AggregateEvent"] = "AggregateEvent";
31
32
  AggregationType["AggregatePay"] = "AggregatePay";
32
33
  AggregationType["AggregatePlaceOrder"] = "AggregatePlaceOrder";
@@ -20,6 +20,9 @@ export declare class MongoRepository {
20
20
  offerCatalog: {
21
21
  id: string;
22
22
  };
23
+ availableAtOrFrom?: {
24
+ id?: string;
25
+ };
23
26
  limit?: number;
24
27
  page?: number;
25
28
  sort: boolean;
@@ -301,6 +301,7 @@ class MongoRepository {
301
301
  * カタログに登録されたオファーの順序は保証される
302
302
  */
303
303
  findOffersByOfferCatalogId(params) {
304
+ var _a;
304
305
  return __awaiter(this, void 0, void 0, function* () {
305
306
  // aggregateで再実装(2023-01-26~)
306
307
  const matchStages = [{ $match: { _id: { $eq: params.offerCatalog.id } } }];
@@ -345,7 +346,9 @@ class MongoRepository {
345
346
  // }
346
347
  let offers = [];
347
348
  if (sortedOfferIds.length > 0) {
348
- offers = yield this.search({ id: { $in: sortedOfferIds } });
349
+ offers = yield this.search(Object.assign({ id: { $in: sortedOfferIds } }, (typeof ((_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id) === 'string')
350
+ ? { availableAtOrFrom: { id: { $eq: params.availableAtOrFrom.id } } }
351
+ : undefined));
349
352
  if (params.sort) {
350
353
  // sorting
351
354
  offers = offers.sort((a, b) => sortedOfferIds.indexOf(String(a.id)) - sortedOfferIds.indexOf(String(b.id)));
@@ -59,6 +59,13 @@ declare function aggregateUseAction(params: {
59
59
  agregation: AggregationRepo;
60
60
  action: ActionRepo;
61
61
  }) => Promise<void>;
62
+ declare function aggregateCheckMovieTicketAction(params: {
63
+ aggregationDays: number;
64
+ excludedProjectId?: string;
65
+ }): (repos: {
66
+ agregation: AggregationRepo;
67
+ action: ActionRepo;
68
+ }) => Promise<void>;
62
69
  declare function aggregatePayTransaction(params: {
63
70
  aggregationDays: number;
64
71
  excludedProjectId?: string;
@@ -83,4 +90,4 @@ declare function aggregateTask(params: {
83
90
  agregation: AggregationRepo;
84
91
  task: TasKRepo;
85
92
  }) => Promise<void>;
86
- export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateEvent, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
93
+ export { aggregateAuthorizeEventServiceOfferAction, aggregateAuthorizeOrderAction, aggregateAuthorizePaymentAction, aggregateCheckMovieTicketAction, aggregateEvent, aggregatePayTransaction, aggregatePlaceOrder, aggregateReserveTransaction, aggregateTask, aggregateUseAction };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.aggregateUseAction = exports.aggregateTask = exports.aggregateReserveTransaction = exports.aggregatePlaceOrder = exports.aggregatePayTransaction = exports.aggregateEvent = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
12
+ exports.aggregateUseAction = exports.aggregateTask = exports.aggregateReserveTransaction = exports.aggregatePlaceOrder = exports.aggregatePayTransaction = exports.aggregateEvent = exports.aggregateCheckMovieTicketAction = exports.aggregateAuthorizePaymentAction = exports.aggregateAuthorizeOrderAction = exports.aggregateAuthorizeEventServiceOfferAction = void 0;
13
13
  const createDebug = require("debug");
14
14
  const moment = require("moment-timezone");
15
15
  const factory = require("../../factory");
@@ -242,6 +242,38 @@ function aggregateUseAction(params) {
242
242
  });
243
243
  }
244
244
  exports.aggregateUseAction = aggregateUseAction;
245
+ function aggregateCheckMovieTicketAction(params) {
246
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
247
+ var _a;
248
+ const aggregateDate = new Date();
249
+ const aggregateDuration = moment.duration(1, 'days')
250
+ .toISOString();
251
+ let i = -1;
252
+ while (i < params.aggregationDays) {
253
+ i += 1;
254
+ const startFrom = moment()
255
+ .utc()
256
+ // .tz('Asia/Tokyo')
257
+ .add(-i, 'days')
258
+ .startOf('day')
259
+ .toDate();
260
+ const startThrough = moment()
261
+ .utc()
262
+ // .tz('Asia/Tokyo')
263
+ .add(-i, 'days')
264
+ .endOf('day')
265
+ .toDate();
266
+ const aggregateResult = yield repos.action.aggregateCheckMovieTicketAction({
267
+ project: { id: { $ne: params.excludedProjectId } },
268
+ startFrom,
269
+ startThrough
270
+ });
271
+ debug('aggregateCheckMovieTicketAction:result', aggregateResult, (_a = aggregateResult.statuses[0]) === null || _a === void 0 ? void 0 : _a.aggregation.percentilesDuration, startFrom);
272
+ yield repos.agregation.saveAggregation(Object.assign({ typeOf: aggregation_1.AggregationType.AggregateCheckMovieTicketAction, project: { id: '*', typeOf: factory.organizationType.Project }, aggregateDuration, aggregateStart: startFrom, aggregateDate }, aggregateResult));
273
+ }
274
+ });
275
+ }
276
+ exports.aggregateCheckMovieTicketAction = aggregateCheckMovieTicketAction;
245
277
  function aggregatePayTransaction(params) {
246
278
  return (repos) => __awaiter(this, void 0, void 0, function* () {
247
279
  var _a;
@@ -0,0 +1,16 @@
1
+ import * as factory from '../../../factory';
2
+ import { IMinimizedIndividualEvent } from '../../../factory/event';
3
+ declare function validateStartRequest(params: {
4
+ object: factory.assetTransaction.reserve.IObjectWithoutDetail;
5
+ event: IMinimizedIndividualEvent<factory.eventType.Event | factory.eventType.ScreeningEvent>;
6
+ validateEventOfferPeriod?: boolean;
7
+ validateEvent?: boolean;
8
+ now: Date;
9
+ store?: {
10
+ /**
11
+ * 販売アプリケーションID
12
+ */
13
+ id?: string;
14
+ };
15
+ }): void;
16
+ export { validateStartRequest };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateStartRequest = void 0;
4
+ const moment = require("moment");
5
+ const factory = require("../../../factory");
6
+ function validateStartRequest(params) {
7
+ var _a;
8
+ const now = params.now;
9
+ const event = params.event;
10
+ if (params.validateEventOfferPeriod === true) {
11
+ if (typeof ((_a = params.store) === null || _a === void 0 ? void 0 : _a.id) !== 'string') {
12
+ throw new factory.errors.NotFound('store.id');
13
+ }
14
+ validateEventOfferPeriod({ event, now, availableAt: { id: params.store.id } });
15
+ }
16
+ if (params.validateEvent === true) {
17
+ validateEvent({ event, object: params.object });
18
+ }
19
+ }
20
+ exports.validateStartRequest = validateStartRequest;
21
+ /**
22
+ * イベントのオファー有効期間を検証する
23
+ */
24
+ function validateEventOfferPeriod(params) {
25
+ const acceptedDate = moment(params.now);
26
+ const eventOffers = params.event.offers;
27
+ // アプリケーションごとの設定を参照する(2022-11-19~)
28
+ const makesOfferOnApplication = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.seller.makesOffer.find((offer) => {
29
+ return Array.isArray(offer.availableAtOrFrom) && offer.availableAtOrFrom[0].id === params.availableAt.id;
30
+ });
31
+ if (makesOfferOnApplication === undefined) {
32
+ throw new factory.errors.Argument('reservationFor.id', `seller makes no available offer at ${params.availableAt.id}`);
33
+ }
34
+ const validFrom = makesOfferOnApplication.validFrom;
35
+ const validThrough = makesOfferOnApplication.validThrough;
36
+ // const validFrom = eventOffers?.validFrom;
37
+ // const validThrough = eventOffers?.validThrough;
38
+ if (validFrom !== undefined && validFrom !== null) {
39
+ if (acceptedDate.isBefore(moment(validFrom))) {
40
+ throw new factory.errors.Argument('reservationFor.id', `Offer of ${params.event.id} is valid from ${validFrom}`);
41
+ }
42
+ }
43
+ if (validThrough !== undefined && validThrough !== null) {
44
+ if (acceptedDate.isAfter(moment(validThrough))) {
45
+ throw new factory.errors.Argument('reservationFor.id', `Offer of ${params.event.id} is valid through ${validThrough}`);
46
+ }
47
+ }
48
+ }
49
+ /**
50
+ * イベントの上限座席数を検証する
51
+ */
52
+ function validateEvent(params) {
53
+ var _a, _b;
54
+ // const acceptedDate = moment(params.now);
55
+ const eventOffers = params.event.offers;
56
+ // const validFrom = eventOffers?.validFrom;
57
+ // const validThrough = eventOffers?.validThrough;
58
+ // if (validFrom !== undefined && validFrom !== null) {
59
+ // if (acceptedDate.isBefore(moment(validFrom))) {
60
+ // throw new factory.errors.Argument(
61
+ // 'reservationFor.id',
62
+ // `Offer of ${params.event.id} is valid from ${validFrom}`
63
+ // );
64
+ // }
65
+ // }
66
+ // if (validThrough !== undefined && validThrough !== null) {
67
+ // if (acceptedDate.isAfter(moment(validThrough))) {
68
+ // throw new factory.errors.Argument(
69
+ // 'reservationFor.id',
70
+ // `Offer of ${params.event.id} is valid through ${validThrough}`
71
+ // );
72
+ // }
73
+ // }
74
+ // イベントのmaxValueを検証
75
+ const maxValue = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.maxValue;
76
+ if (typeof maxValue === 'number') {
77
+ const numAcceptedOffers = (_b = params.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.length;
78
+ if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
79
+ if (numAcceptedOffers > maxValue) {
80
+ throw new factory.errors.Argument('reservationFor.id', `Maximum number of offers exceeded`);
81
+ }
82
+ }
83
+ }
84
+ }
@@ -1,7 +1,7 @@
1
1
  import * as factory from '../../factory';
2
2
  import { MongoRepository as ActionRepo } from '../../repo/action';
3
3
  import { MongoRepository as AssetTransactionRepo } from '../../repo/assetTransaction';
4
- import { MongoRepository as EventRepo } from '../../repo/event';
4
+ import { IMinimizedIndividualEvent, MongoRepository as EventRepo } from '../../repo/event';
5
5
  import { RedisRepository as ScreeningEventAvailabilityRepo } from '../../repo/itemAvailability/screeningEvent';
6
6
  import { MongoRepository as OfferRepo } from '../../repo/offer';
7
7
  import { MongoRepository as OfferCatalogRepo } from '../../repo/offerCatalog';
@@ -62,12 +62,39 @@ interface IConfirmRepo {
62
62
  task: TaskRepo;
63
63
  }
64
64
  export declare type IConfirmOperation<T> = (repos: IConfirmRepo) => Promise<T>;
65
+ declare type IStartParams = factory.assetTransaction.reserve.IStartParamsWithoutDetail & {
66
+ /**
67
+ * 承認アクションを介した場合に検索済のイベント
68
+ */
69
+ preSearchedEvent?: IMinimizedIndividualEvent<factory.eventType.Event | factory.eventType.ScreeningEvent>;
70
+ /**
71
+ * 承認アクションを介した場合に検索済のオファーリスト
72
+ */
73
+ preSearchedTicketOffers?: factory.product.ITicketOffer[];
74
+ /**
75
+ * 承認アクションを介した場合に検索済の単価オファーリスト
76
+ */
77
+ preSearchedUnitPriceOffers?: factory.unitPriceOffer.IUnitPriceOffer[];
78
+ /**
79
+ * 販売アプリケーション
80
+ */
81
+ availableAtOrFrom?: {
82
+ id?: string;
83
+ };
84
+ /**
85
+ * イベントの販売期間を検証するかどうか
86
+ */
87
+ validateEventOfferPeriod: boolean;
88
+ /**
89
+ * イベントのオファー(最大予約座席数)を検証するかどうか
90
+ */
91
+ validateEvent: boolean;
92
+ validateAppliesToMovieTicket: boolean;
93
+ };
65
94
  /**
66
95
  * 取引開始
67
96
  */
68
- export declare function start(params: factory.assetTransaction.reserve.IStartParamsWithoutDetail & {
69
- validateAppliesToMovieTicket: boolean;
70
- }): IStartOperation<factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>>;
97
+ export declare function start(params: IStartParams): IStartOperation<factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>>;
71
98
  /**
72
99
  * 取引確定
73
100
  */
@@ -21,17 +21,39 @@ const cancelReservation_1 = require("../reserve/cancelReservation");
21
21
  const confirmReservation_1 = require("../reserve/confirmReservation");
22
22
  const settings_1 = require("../../settings");
23
23
  const factory_1 = require("./reserve/factory");
24
+ const validateStartRequest_1 = require("./reserve/validateStartRequest");
24
25
  /**
25
26
  * 取引開始
26
27
  */
27
28
  function start(params) {
28
29
  return (repos) => __awaiter(this, void 0, void 0, function* () {
29
- var _a;
30
+ var _a, _b, _c, _d, _e;
31
+ const now = new Date();
30
32
  // 自動発行廃止(2022-05-17~)
31
33
  const reservationNumber = params.transactionNumber;
32
34
  if (typeof reservationNumber !== 'string' || reservationNumber.length === 0) {
33
35
  throw new factory.errors.ArgumentNull('transactionNumber');
34
36
  }
37
+ // eventをfix
38
+ if (typeof ((_a = params.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id) !== 'string' || params.object.reservationFor.id.length === 0) {
39
+ throw new factory.errors.ArgumentNull('object.reservationFor.id');
40
+ }
41
+ let event;
42
+ if (typeof ((_b = params.preSearchedEvent) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') {
43
+ event = params.preSearchedEvent;
44
+ }
45
+ else {
46
+ event = yield repos.event.findMinimizedIndividualEventById({ id: params.object.reservationFor.id });
47
+ }
48
+ // validationを承認アクション開始前から移行(2023-01-27~)
49
+ (0, validateStartRequest_1.validateStartRequest)({
50
+ object: params.object,
51
+ event,
52
+ validateEventOfferPeriod: params.validateEventOfferPeriod,
53
+ validateEvent: params.validateEvent,
54
+ now,
55
+ store: { id: (_c = params.availableAtOrFrom) === null || _c === void 0 ? void 0 : _c.id }
56
+ });
35
57
  const startParams = (0, factory_1.createStartParams)(Object.assign(Object.assign({}, params), { reservationNumber: reservationNumber }));
36
58
  // 取引作成
37
59
  let transaction;
@@ -47,10 +69,14 @@ function start(params) {
47
69
  throw error;
48
70
  }
49
71
  // 指定があれば予約追加
50
- if (typeof ((_a = params.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id) === 'string') {
72
+ if (typeof ((_d = params.object.reservationFor) === null || _d === void 0 ? void 0 : _d.id) === 'string') {
51
73
  transaction = yield addReservations({
52
74
  id: transaction.id,
53
75
  object: params.object,
76
+ event,
77
+ preSearchedTicketOffers: params.preSearchedTicketOffers,
78
+ preSearchedUnitPriceOffers: params.preSearchedUnitPriceOffers,
79
+ availableAtOrFrom: { id: (_e = params.availableAtOrFrom) === null || _e === void 0 ? void 0 : _e.id },
54
80
  validateAppliesToMovieTicket: params.validateAppliesToMovieTicket
55
81
  })(repos);
56
82
  }
@@ -67,21 +93,8 @@ function addReservations(params) {
67
93
  var _a;
68
94
  const now = new Date();
69
95
  let transaction = yield repos.assetTransaction.findById({ typeOf: factory.assetTransactionType.Reserve, id: params.id });
70
- // イベント存在確認
71
- if (typeof ((_a = params.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id) !== 'string' || params.object.reservationFor.id.length === 0) {
72
- throw new factory.errors.ArgumentNull('object.reservationFor.id');
73
- }
74
96
  const acceptedOffers = (Array.isArray(params.object.acceptedOffer)) ? params.object.acceptedOffer : [];
75
- // イベント取得属性最適化(2023-01-23~)
76
- const event = yield repos.event.findMinimizedIndividualEventById({ id: params.object.reservationFor.id });
77
- // const event = await repos.event.findById(
78
- // { id: params.object.reservationFor.id },
79
- // {
80
- // // 予約データに不要な属性は取得しない
81
- // aggregateReservation: 0, aggregateOffer: 0, attendeeCount: 0,
82
- // checkInCount: 0, maximumAttendeeCapacity: 0, remainingAttendeeCapacity: 0
83
- // }
84
- // );
97
+ const event = params.event;
85
98
  if (event.typeOf !== factory.eventType.ScreeningEvent && event.typeOf !== factory.eventType.Event) {
86
99
  throw new factory.errors.Argument('object.reservationFor.id', `invalid event type ${event.typeOf}`);
87
100
  }
@@ -90,14 +103,26 @@ function addReservations(params) {
90
103
  }
91
104
  // 受け入れたオファーIDだけ取得する(2023-01-26~)
92
105
  const acceptedOfferIds = [...new Set(acceptedOffers.map((o) => String(o.id)))];
93
- // イベントオファー検索
94
- const { ticketOffers, unitPriceOffers } = yield OfferService.event.searchEventTicketOffers({
95
- ids: acceptedOfferIds,
96
- event: { id: event.id },
97
- sort: false // ソート不要(2023-01-27~)
98
- })(repos);
106
+ let ticketOffers;
107
+ let availableOffers;
108
+ // 承認アクションを介した予約取引開始時の冗長なオファー検索処理について最適化(2023-01-27~)
109
+ if (Array.isArray(params.preSearchedTicketOffers) && Array.isArray(params.preSearchedUnitPriceOffers)) {
110
+ ticketOffers = params.preSearchedTicketOffers;
111
+ availableOffers = params.preSearchedUnitPriceOffers;
112
+ }
113
+ else {
114
+ // イベントオファー検索
115
+ const searchEventTicketOffersResult = yield OfferService.event.searchEventTicketOffers({
116
+ ids: acceptedOfferIds,
117
+ event: { id: event.id },
118
+ // 対応アプリケーション条件追加(2023-01-27~)
119
+ store: { id: (_a = params.availableAtOrFrom) === null || _a === void 0 ? void 0 : _a.id },
120
+ sort: false // ソート不要(2023-01-27~)
121
+ })(repos);
122
+ ticketOffers = searchEventTicketOffersResult.ticketOffers;
123
+ availableOffers = searchEventTicketOffersResult.unitPriceOffers;
124
+ }
99
125
  // 冗長なfindOffersByOfferCatalogId処理を削除(2023-01-26~)
100
- const availableOffers = unitPriceOffers;
101
126
  // let availableOffers: factory.unitPriceOffer.IUnitPriceOffer[] = [];
102
127
  // // 興行設定があれば興行のカタログを参照する(2022-08-31~)
103
128
  // const eventOffers = <factory.event.screeningEvent.IOffer | undefined>event.offers;
@@ -37,7 +37,7 @@ declare type IAuthorizeOfferAction = factory.action.authorize.offer.seatReservat
37
37
  /**
38
38
  * イベントオファー承認
39
39
  */
40
- export declare function authorize(params: {
40
+ declare function authorize(params: {
41
41
  project: {
42
42
  id: string;
43
43
  typeOf: factory.organizationType.Project;
@@ -49,11 +49,8 @@ export declare function authorize(params: {
49
49
  transaction: {
50
50
  id: string;
51
51
  };
52
- validateEventOfferPeriod?: boolean;
53
- validateEvent?: boolean;
54
- /**
55
- * どの店舗に対して
56
- */
52
+ validateEventOfferPeriod: boolean;
53
+ validateEvent: boolean;
57
54
  store: {
58
55
  /**
59
56
  * 販売アプリケーションID
@@ -61,4 +58,4 @@ export declare function authorize(params: {
61
58
  id: string;
62
59
  };
63
60
  }): IAuthorizeOperation<IAuthorizeOfferAction>;
64
- export {};
61
+ export { authorize };
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.authorize = void 0;
13
- const moment = require("moment");
14
13
  const factory = require("../../../factory");
15
14
  const ReserveTransactionService = require("../../assetTransaction/reserve");
16
15
  const CodeService = require("../../code");
@@ -22,9 +21,8 @@ const factory_1 = require("./factory");
22
21
  function authorize(params) {
23
22
  // tslint:disable-next-line:max-func-body-length
24
23
  return (repos) => __awaiter(this, void 0, void 0, function* () {
25
- const now = new Date();
26
- const { transaction, event, bookingServiceIdentifire } = yield validateCreateRequest(Object.assign(Object.assign({}, params), { now, store: params.store }))({ event: repos.event, transaction: repos.transaction });
27
- const acceptedOffers = yield validateAcceptedOffers({
24
+ const { transaction, event, bookingServiceIdentifire } = yield validateCreateRequest(params)({ event: repos.event, transaction: repos.transaction });
25
+ const { acceptedOffers, ticketOffers, unitPriceOffers } = yield validateAcceptedOffers({
28
26
  object: params.object,
29
27
  event,
30
28
  seller: { typeOf: transaction.seller.typeOf, id: String(transaction.seller.id) },
@@ -63,7 +61,12 @@ function authorize(params) {
63
61
  action,
64
62
  event,
65
63
  transactionNumber,
66
- transaction
64
+ transaction,
65
+ availableAtOrFrom: { id: params.store.id },
66
+ ticketOffers,
67
+ unitPriceOffers,
68
+ validateEvent: params.validateEvent === true,
69
+ validateEventOfferPeriod: params.validateEventOfferPeriod === true
67
70
  })(repos);
68
71
  // requestBody = processStartReserveResult.requestBody;
69
72
  // responseBody = processStartReserveResult.responseBody;
@@ -113,7 +116,6 @@ exports.authorize = authorize;
113
116
  function validateCreateRequest(params) {
114
117
  return (repos) => __awaiter(this, void 0, void 0, function* () {
115
118
  var _a, _b;
116
- const now = params.now;
117
119
  const transaction = yield repos.transaction.findInProgressById({
118
120
  typeOf: factory.transactionType.PlaceOrder,
119
121
  id: params.transaction.id
@@ -134,14 +136,6 @@ function validateCreateRequest(params) {
134
136
  offeredThrough = { typeOf: 'WebAPI', identifier: factory.service.webAPI.Identifier.Chevre };
135
137
  }
136
138
  const bookingServiceIdentifire = offeredThrough.identifier;
137
- if (bookingServiceIdentifire === factory.service.webAPI.Identifier.Chevre) {
138
- if (params.validateEventOfferPeriod === true) {
139
- validateEventOfferPeriod({ event, now, availableAt: { id: params.store.id } });
140
- }
141
- if (params.validateEvent === true) {
142
- validateEvent({ event, object: params.object });
143
- }
144
- }
145
139
  return { transaction, event, bookingServiceIdentifire };
146
140
  });
147
141
  }
@@ -168,7 +162,7 @@ function processStartReserve4chevre(params) {
168
162
  // requestBody = startParams;
169
163
  const startParamObject = yield validateObjectWithoutDetail(startParams)(repos);
170
164
  // 予約取引開始
171
- responseBody = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject, validateAppliesToMovieTicket: true }))(repos);
165
+ responseBody = yield ReserveTransactionService.start(Object.assign(Object.assign({}, startParams), { object: startParamObject, preSearchedEvent: event, preSearchedTicketOffers: params.ticketOffers, preSearchedUnitPriceOffers: params.unitPriceOffers, availableAtOrFrom: { id: params.availableAtOrFrom.id }, validateEvent: params.validateEvent, validateEventOfferPeriod: params.validateEventOfferPeriod, validateAppliesToMovieTicket: true }))(repos);
172
166
  // 予約取引からオファー情報を生成する
173
167
  acceptedOffers4result = (0, factory_1.responseBody2acceptedOffers4result)({
174
168
  responseBody: responseBody,
@@ -209,70 +203,6 @@ function validateObjectWithoutDetail(params) {
209
203
  return objectWithoutDetail;
210
204
  });
211
205
  }
212
- /**
213
- * イベントのオファー有効期間を検証する
214
- */
215
- function validateEventOfferPeriod(params) {
216
- const acceptedDate = moment(params.now);
217
- const eventOffers = params.event.offers;
218
- // アプリケーションごとの設定を参照する(2022-11-19~)
219
- const makesOfferOnApplication = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.seller.makesOffer.find((offer) => {
220
- return Array.isArray(offer.availableAtOrFrom) && offer.availableAtOrFrom[0].id === params.availableAt.id;
221
- });
222
- if (makesOfferOnApplication === undefined) {
223
- throw new factory.errors.Argument('reservationFor.id', `seller makes no available offer at ${params.availableAt.id}`);
224
- }
225
- const validFrom = makesOfferOnApplication.validFrom;
226
- const validThrough = makesOfferOnApplication.validThrough;
227
- // const validFrom = eventOffers?.validFrom;
228
- // const validThrough = eventOffers?.validThrough;
229
- if (validFrom !== undefined && validFrom !== null) {
230
- if (acceptedDate.isBefore(moment(validFrom))) {
231
- throw new factory.errors.Argument('reservationFor.id', `Offer of ${params.event.id} is valid from ${validFrom}`);
232
- }
233
- }
234
- if (validThrough !== undefined && validThrough !== null) {
235
- if (acceptedDate.isAfter(moment(validThrough))) {
236
- throw new factory.errors.Argument('reservationFor.id', `Offer of ${params.event.id} is valid through ${validThrough}`);
237
- }
238
- }
239
- }
240
- /**
241
- * イベントの上限座席数を検証する
242
- */
243
- function validateEvent(params) {
244
- var _a, _b;
245
- // const acceptedDate = moment(params.now);
246
- const eventOffers = params.event.offers;
247
- // const validFrom = eventOffers?.validFrom;
248
- // const validThrough = eventOffers?.validThrough;
249
- // if (validFrom !== undefined && validFrom !== null) {
250
- // if (acceptedDate.isBefore(moment(validFrom))) {
251
- // throw new factory.errors.Argument(
252
- // 'reservationFor.id',
253
- // `Offer of ${params.event.id} is valid from ${validFrom}`
254
- // );
255
- // }
256
- // }
257
- // if (validThrough !== undefined && validThrough !== null) {
258
- // if (acceptedDate.isAfter(moment(validThrough))) {
259
- // throw new factory.errors.Argument(
260
- // 'reservationFor.id',
261
- // `Offer of ${params.event.id} is valid through ${validThrough}`
262
- // );
263
- // }
264
- // }
265
- // イベントのmaxValueを検証
266
- const maxValue = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.maxValue;
267
- if (typeof maxValue === 'number') {
268
- const numAcceptedOffers = (_b = params.object.acceptedOffer) === null || _b === void 0 ? void 0 : _b.length;
269
- if (typeof numAcceptedOffers === 'number' && numAcceptedOffers > 0) {
270
- if (numAcceptedOffers > maxValue) {
271
- throw new factory.errors.Argument('reservationFor.id', `Maximum number of offers exceeded`);
272
- }
273
- }
274
- }
275
- }
276
206
  /**
277
207
  * 受け入れらたオファーの内容を検証
278
208
  */
@@ -283,11 +213,11 @@ function validateAcceptedOffers(params) {
283
213
  ? [...new Set(acceptedOffersWithoutDetail.map((o) => o.id))]
284
214
  : [];
285
215
  // 利用可能なチケットオファーを検索
286
- const { ticketOffers } = yield (0, searchEventTicketOffers_1.searchEventTicketOffers)({
216
+ const { ticketOffers, unitPriceOffers } = yield (0, searchEventTicketOffers_1.searchEventTicketOffers)({
287
217
  // 受け入れたオファーIDだけ取得する(2023-01-26~)
288
218
  ids: offerIds,
289
219
  event: { id: params.event.id },
290
- seller: params.seller,
220
+ // seller: params.seller,
291
221
  store: params.store,
292
222
  sort: false // ソート不要(2023-01-27~)
293
223
  })(repos);
@@ -333,7 +263,7 @@ function validateAcceptedOffers(params) {
333
263
  }
334
264
  }
335
265
  });
336
- return acceptedOffers;
266
+ return { acceptedOffers, ticketOffers, unitPriceOffers };
337
267
  });
338
268
  }
339
269
  function acceptedOfferWithoutDetail2acceptedOffer(params) {
@@ -29,12 +29,10 @@ declare function searchEventTicketOffers(params: {
29
29
  };
30
30
  /**
31
31
  * どの販売者に対して
32
+ * 不要なので廃止(2023-01-27~)
32
33
  */
33
- seller?: {
34
- id?: string;
35
- };
36
34
  /**
37
- * どの店舗に対して
35
+ * どのアプリケーションに対して
38
36
  */
39
37
  store?: {
40
38
  id?: string;
@@ -19,7 +19,7 @@ const factory_1 = require("../factory");
19
19
  function searchTransportationEventTicketOffers(params) {
20
20
  // tslint:disable-next-line:max-func-body-length
21
21
  return (repos) => __awaiter(this, void 0, void 0, function* () {
22
- var _a, _b, _c;
22
+ var _a, _b, _c, _d;
23
23
  const screeningEvent = params.event;
24
24
  const soundFormatTypes = [];
25
25
  const videoFormatTypes = [];
@@ -32,6 +32,7 @@ function searchTransportationEventTicketOffers(params) {
32
32
  availableOffers = yield repos.offer.findOffersByOfferCatalogId({
33
33
  ids: params.ids,
34
34
  offerCatalog: { id: transportation.hasOfferCatalog.id },
35
+ availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
35
36
  sort: params.sort
36
37
  });
37
38
  }
@@ -109,9 +110,12 @@ function searchTransportationEventTicketOffers(params) {
109
110
  const offerAddOn = [];
110
111
  if (Array.isArray(offer.addOn)) {
111
112
  for (const addOn of offer.addOn) {
112
- const productId = (_c = addOn.itemOffered) === null || _c === void 0 ? void 0 : _c.id;
113
+ const productId = (_d = addOn.itemOffered) === null || _d === void 0 ? void 0 : _d.id;
113
114
  if (typeof productId === 'string') {
114
- const productOffers = yield searchAddOns({ product: { id: productId } })(repos);
115
+ const productOffers = yield searchAddOns({
116
+ product: { id: productId },
117
+ store: params.store
118
+ })(repos);
115
119
  offerAddOn.push(...productOffers);
116
120
  }
117
121
  }
@@ -130,7 +134,7 @@ function searchTransportationEventTicketOffers(params) {
130
134
  function searchScreeningEventTicketOffers(params) {
131
135
  // tslint:disable-next-line:max-func-body-length
132
136
  return (repos) => __awaiter(this, void 0, void 0, function* () {
133
- var _a, _b, _c;
137
+ var _a, _b, _c, _d;
134
138
  // イベント取得属性最適化(2023-01-23~)
135
139
  // const screeningEvent = await repos.event.findById<factory.eventType.ScreeningEvent>({ id: params.eventId });
136
140
  const screeningEvent = params.event;
@@ -147,6 +151,7 @@ function searchScreeningEventTicketOffers(params) {
147
151
  availableOffers = yield repos.offer.findOffersByOfferCatalogId({
148
152
  ids: params.ids,
149
153
  offerCatalog: { id: eventService.hasOfferCatalog.id },
154
+ availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
150
155
  sort: params.sort
151
156
  });
152
157
  }
@@ -224,7 +229,7 @@ function searchScreeningEventTicketOffers(params) {
224
229
  const offerAddOn = [];
225
230
  if (Array.isArray(offer.addOn)) {
226
231
  for (const addOn of offer.addOn) {
227
- const productId = (_c = addOn.itemOffered) === null || _c === void 0 ? void 0 : _c.id;
232
+ const productId = (_d = addOn.itemOffered) === null || _d === void 0 ? void 0 : _d.id;
228
233
  if (typeof productId === 'string') {
229
234
  const productOffers = yield searchAddOns({ product: { id: productId } })(repos);
230
235
  offerAddOn.push(...productOffers);
@@ -326,7 +331,7 @@ function checkAvailability(params) {
326
331
  */
327
332
  function searchAddOns(params) {
328
333
  return (repos) => __awaiter(this, void 0, void 0, function* () {
329
- var _a, _b;
334
+ var _a, _b, _c;
330
335
  let offers = [];
331
336
  const productId = (_a = params.product) === null || _a === void 0 ? void 0 : _a.id;
332
337
  if (typeof productId === 'string') {
@@ -335,6 +340,7 @@ function searchAddOns(params) {
335
340
  if (typeof offerCatalogId === 'string') {
336
341
  offers = yield repos.offer.findOffersByOfferCatalogId({
337
342
  offerCatalog: { id: offerCatalogId },
343
+ availableAtOrFrom: { id: (_c = params.store) === null || _c === void 0 ? void 0 : _c.id },
338
344
  sort: true
339
345
  });
340
346
  offers = offers.map((o) => {
@@ -358,7 +364,6 @@ function searchAddOns(params) {
358
364
  function searchEventTicketOffers(params) {
359
365
  // tslint:disable-next-line:max-func-body-length
360
366
  return (repos) => __awaiter(this, void 0, void 0, function* () {
361
- var _a;
362
367
  const now = moment();
363
368
  let event;
364
369
  // イベント取得属性最適化(2023-01-23~)
@@ -384,6 +389,7 @@ function searchEventTicketOffers(params) {
384
389
  const searchOffersResult = yield searchScreeningEventTicketOffers({
385
390
  ids: params.ids,
386
391
  event,
392
+ store: params.store,
387
393
  sort: params.sort
388
394
  })(repos);
389
395
  offers = searchOffersResult.ticketOffers;
@@ -393,6 +399,7 @@ function searchEventTicketOffers(params) {
393
399
  const searchOffersResult = yield searchTransportationEventTicketOffers({
394
400
  ids: params.ids,
395
401
  event,
402
+ store: params.store,
396
403
  sort: params.sort
397
404
  })(repos);
398
405
  offers = searchOffersResult.ticketOffers;
@@ -401,14 +408,15 @@ function searchEventTicketOffers(params) {
401
408
  else {
402
409
  throw new factory.errors.NotImplemented(`'${event.typeOf}' not implemented`);
403
410
  }
404
- const specifiedStoreId = (_a = params.store) === null || _a === void 0 ? void 0 : _a.id;
405
- if (typeof specifiedStoreId === 'string') {
406
- // アプリケーションが利用可能なオファーに絞る
407
- offers = offers.filter((o) => {
408
- return Array.isArray(o.availableAtOrFrom)
409
- && o.availableAtOrFrom.some((availableApplication) => availableApplication.id === specifiedStoreId);
410
- });
411
- }
411
+ // store.idでのフィルターをmongoに移行(2023-01-27~)
412
+ // const specifiedStoreId = params.store?.id;
413
+ // if (typeof specifiedStoreId === 'string') {
414
+ // // アプリケーションが利用可能なオファーに絞る
415
+ // offers = offers.filter((o) => {
416
+ // return Array.isArray(o.availableAtOrFrom)
417
+ // && o.availableAtOrFrom.some((availableApplication) => availableApplication.id === specifiedStoreId);
418
+ // });
419
+ // }
412
420
  // 有効期間を適用
413
421
  if (params.onlyValid === true) {
414
422
  offers = offers.filter((o) => {
@@ -426,14 +434,17 @@ function searchEventTicketOffers(params) {
426
434
  }
427
435
  for (const offer of offers) {
428
436
  if (Array.isArray(offer.addOn)) {
437
+ // store.idでのフィルターをmongoに移行(2023-01-27~)
429
438
  // addOnsに対しても利用可能アプリケーション設定を適用
430
- if (typeof specifiedStoreId === 'string') {
431
- // アプリケーションが利用可能なオファーに絞る
432
- offer.addOn = offer.addOn.filter((offer4addOn) => {
433
- return Array.isArray(offer4addOn.availableAtOrFrom)
434
- && offer4addOn.availableAtOrFrom.some((availableApplication) => availableApplication.id === specifiedStoreId);
435
- });
436
- }
439
+ // if (typeof specifiedStoreId === 'string') {
440
+ // // アプリケーションが利用可能なオファーに絞る
441
+ // offer.addOn = offer.addOn.filter((offer4addOn) => {
442
+ // return Array.isArray(offer4addOn.availableAtOrFrom)
443
+ // && offer4addOn.availableAtOrFrom.some(
444
+ // (availableApplication) => availableApplication.id === specifiedStoreId
445
+ // );
446
+ // });
447
+ // }
437
448
  // addOnsに対しても有効期間を適用
438
449
  if (params.onlyValid === true) {
439
450
  offer.addOn = offer.addOn.filter((offer4addOn) => {
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.2.0-alpha.33"
123
+ "version": "20.2.0-alpha.35"
124
124
  }