@chevre/domain 21.2.0-alpha.129 → 21.2.0-alpha.130

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.
@@ -25,6 +25,7 @@ async function main() {
25
25
  project,
26
26
  eventId: 'sampleEventId',
27
27
  startDate: startDate.toDate(),
28
+ hasTicketedSeat: true,
28
29
  offers: [
29
30
  {
30
31
  seatSection: 'sampleSeatSection',
@@ -9,24 +9,22 @@ async function main() {
9
9
 
10
10
  const taskRepo = new chevre.repository.Task(mongoose.connection);
11
11
 
12
- const tasks = <chevre.factory.task.ITask<chevre.factory.taskName.ConfirmPayTransaction>[]>await taskRepo.search({
12
+ const tasks = <chevre.factory.task.ITask<chevre.factory.taskName.ConfirmReserveTransaction>[]>await taskRepo.search({
13
13
  // limit: 100,
14
14
  // page: 1,
15
15
  name: {
16
- $in: [chevre.factory.taskName.ConfirmPayTransaction]
16
+ $in: [chevre.factory.taskName.ConfirmReserveTransaction]
17
17
  // $nin: [
18
18
  // chevre.factory.taskName.ImportEventsFromCOA,
19
19
  // chevre.factory.taskName.ImportEventCapacitiesFromCOA
20
20
  // ]
21
21
  },
22
22
  statuses: [chevre.factory.taskStatus.Aborted],
23
- runsFrom: moment('2023-05-02T22:00:00Z')
23
+ runsFrom: moment('2023-06-02T22:00:00Z')
24
24
  .toDate(),
25
25
  sort: { runsAt: chevre.factory.sortType.Ascending }
26
26
  });
27
- console.log(tasks.map((task) => `${task.project.id},${task.id},${task.name},${moment(task.runsAt)
28
- .tz('Asia/Tokyo')
29
- .format('YYYY-MM-DDTHH:mm:ssZ')},"${task.data.object[0]?.transactionNumber}"`)
27
+ console.log(tasks.map((task) => `${task.data.object?.transactionNumber}`)
30
28
  .join('\n'));
31
29
  console.log(tasks.length);
32
30
  }
@@ -23,6 +23,7 @@ async function main() {
23
23
  project,
24
24
  eventId: 'alckc9mlx',
25
25
  startDate: new Date(),
26
+ hasTicketedSeat: true,
26
27
  offers: [
27
28
  {
28
29
  seatSection: 'Default',
@@ -0,0 +1,23 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const PROJECT_ID = String(process.env.PROJECT_ID);
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const placeRepo = new chevre.repository.Place(mongoose.connection);
12
+
13
+ const rooms = await placeRepo.searchScreeningRooms({
14
+ $projection: { sectionCount: 1 }
15
+ });
16
+ console.log('place found', rooms);
17
+ const filteredRooms = rooms.filter((room) => typeof room.sectionCount === 'number' && room.sectionCount > 1);
18
+ console.log(filteredRooms.length, 'filteredRooms found');
19
+ }
20
+
21
+ main()
22
+ .then(console.log)
23
+ .catch(console.error);
@@ -19,6 +19,7 @@ export interface ILockKey {
19
19
  };
20
20
  eventId: string;
21
21
  startDate: Date;
22
+ hasTicketedSeat: boolean;
22
23
  offers: IOffer[];
23
24
  expires: Date;
24
25
  holder: string;
@@ -29,6 +30,7 @@ export interface IUnlockKey {
29
30
  };
30
31
  eventId: string;
31
32
  startDate: Date;
33
+ hasTicketedSeat: boolean;
32
34
  offer: IOffer;
33
35
  holder: string;
34
36
  }
@@ -120,6 +122,7 @@ export declare class StockHolderRepository {
120
122
  event: {
121
123
  id: string;
122
124
  startDate: Date;
125
+ hasTicketedSeat: boolean;
123
126
  };
124
127
  }): Promise<number>;
125
128
  /**
@@ -136,6 +139,7 @@ export declare class StockHolderRepository {
136
139
  };
137
140
  eventId: string;
138
141
  startDate: Date;
142
+ hasTicketedSeat: boolean;
139
143
  offers: IOffer[];
140
144
  }): Promise<IGetHolderResult[]>;
141
145
  /**
@@ -24,39 +24,47 @@ class StockHolderRepository {
24
24
  this.redisClient = redisClient;
25
25
  this.holdReservationModel = connection.model(holdReservation_1.modelName, holdReservation_1.schema);
26
26
  }
27
- // public static GET_KEY(params: {
28
- // eventId: string;
29
- // startDate: Date;
30
- // }) {
31
- // return StockHolderRepository.createKey(params);
32
- // }
33
- static offer2field(params) {
27
+ static offer2field(params, hasTicketedSeat) {
34
28
  var _a, _b;
35
- // 予約IDをfieldにする場合
36
- const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
37
- if (typeof serviceOutputId === 'string') {
38
- return serviceOutputId;
29
+ if (hasTicketedSeat) {
30
+ return `${params.seatSection}:${params.seatNumber}`;
31
+ }
32
+ else {
33
+ // 予約IDをfieldにする場合
34
+ const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
35
+ if (typeof serviceOutputId === 'string') {
36
+ return serviceOutputId;
37
+ }
38
+ else {
39
+ throw new factory.errors.ServiceUnavailable('offer2field requires itemOffered.serviceOutput.id');
40
+ }
39
41
  }
40
- return `${params.seatSection}:${params.seatNumber}`;
41
42
  }
42
- static offer2subReservation(params) {
43
+ static offer2subReservation(params, hasTicketedSeat) {
43
44
  var _a, _b;
44
- const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
45
- if (typeof serviceOutputId === 'string') {
45
+ if (hasTicketedSeat) {
46
46
  return {
47
- id: serviceOutputId,
48
- identifier: serviceOutputId
47
+ identifier: `${params.seatSection}:${params.seatNumber}`,
48
+ reservedTicket: {
49
+ ticketedSeat: {
50
+ seatSection: params.seatSection,
51
+ seatNumber: params.seatNumber
52
+ }
53
+ }
49
54
  };
50
55
  }
51
- return {
52
- identifier: `${params.seatSection}:${params.seatNumber}`,
53
- reservedTicket: {
54
- ticketedSeat: {
55
- seatSection: params.seatSection,
56
- seatNumber: params.seatNumber
57
- }
56
+ else {
57
+ const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
58
+ if (typeof serviceOutputId === 'string') {
59
+ return {
60
+ id: serviceOutputId,
61
+ identifier: serviceOutputId
62
+ };
63
+ }
64
+ else {
65
+ throw new factory.errors.ServiceUnavailable('offer2subReservation requires itemOffered.serviceOutput.id');
58
66
  }
59
- };
67
+ }
60
68
  }
61
69
  static createKey(params) {
62
70
  if (!(params.startDate instanceof Date)) {
@@ -81,12 +89,16 @@ class StockHolderRepository {
81
89
  if (params.useMongooseForcibly === true) {
82
90
  return true;
83
91
  }
92
+ // USE_NEW_STOCK_HOLDER_REPO_IDSに含まれれば強制的に使用
84
93
  if (settings_1.USE_NEW_STOCK_HOLDER_REPO_IDS.includes(params.eventId)) {
85
94
  return true;
86
95
  }
87
- if (moment(params.startDate)
88
- .isSameOrAfter(settings_1.USE_NEW_STOCK_HOLDER_REPO_FROM)) {
89
- return true;
96
+ // 座席有の場合のみ、USE_NEW_STOCK_HOLDER_REPO_FROMを検証
97
+ if (params.hasTicketedSeat) {
98
+ if (moment(params.startDate)
99
+ .isSameOrAfter(settings_1.USE_NEW_STOCK_HOLDER_REPO_FROM)) {
100
+ return true;
101
+ }
90
102
  }
91
103
  return false;
92
104
  }
@@ -95,7 +107,11 @@ class StockHolderRepository {
95
107
  */
96
108
  lockIfNotLimitExceeded(lockKey, maximum) {
97
109
  return __awaiter(this, void 0, void 0, function* () {
98
- const useMongoose = StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate });
110
+ const useMongoose = StockHolderRepository.useMongoose({
111
+ eventId: lockKey.eventId,
112
+ startDate: lockKey.startDate,
113
+ hasTicketedSeat: lockKey.hasTicketedSeat
114
+ });
99
115
  if (useMongoose) {
100
116
  if (!(lockKey.expires instanceof Date)) {
101
117
  throw new factory.errors.Argument('expires', 'must be Date');
@@ -105,7 +121,7 @@ class StockHolderRepository {
105
121
  yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
106
122
  const addedReservationCount = lockKey.offers.length;
107
123
  const reservationCountLte = maximum - addedReservationCount;
108
- const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
124
+ const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
109
125
  const reservationPackage = {
110
126
  typeOf: factory.reservationType.ReservationPackage,
111
127
  reservationNumber: lockKey.holder,
@@ -155,14 +171,15 @@ class StockHolderRepository {
155
171
  const useMongoose = StockHolderRepository.useMongoose({
156
172
  eventId: lockKey.eventId,
157
173
  startDate: lockKey.startDate,
158
- useMongooseForcibly: lockKey.useMongooseForcibly
174
+ useMongooseForcibly: lockKey.useMongooseForcibly,
175
+ hasTicketedSeat: lockKey.hasTicketedSeat
159
176
  });
160
177
  const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
161
178
  yield this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
162
179
  if (useMongoose) {
163
180
  yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
164
181
  const addedReservationCount = lockKey.offers.length;
165
- const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
182
+ const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
166
183
  const reservationPackage = {
167
184
  typeOf: factory.reservationType.ReservationPackage,
168
185
  reservationNumber: lockKey.holder,
@@ -189,7 +206,7 @@ class StockHolderRepository {
189
206
  else {
190
207
  const value = lockKey.holder;
191
208
  const multi = this.redisClient.multi();
192
- const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer));
209
+ const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer, lockKey.hasTicketedSeat));
193
210
  fields.forEach((field) => {
194
211
  multi.hSetNX(key, field, value);
195
212
  });
@@ -233,13 +250,17 @@ class StockHolderRepository {
233
250
  */
234
251
  unlock(params) {
235
252
  return __awaiter(this, void 0, void 0, function* () {
236
- const useMongoose = StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate });
253
+ const useMongoose = StockHolderRepository.useMongoose({
254
+ eventId: params.eventId,
255
+ startDate: params.startDate,
256
+ hasTicketedSeat: params.hasTicketedSeat
257
+ });
237
258
  const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
238
259
  yield this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
239
260
  if (useMongoose) {
240
261
  // [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
241
262
  yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
242
- const subReservation = StockHolderRepository.offer2subReservation(params.offer);
263
+ const subReservation = StockHolderRepository.offer2subReservation(params.offer, params.hasTicketedSeat);
243
264
  const reservationNumber = params.holder;
244
265
  const updateResult = yield this.holdReservationModel.findOneAndUpdate({
245
266
  'reservationFor.id': { $eq: params.eventId },
@@ -260,7 +281,7 @@ class StockHolderRepository {
260
281
  // docが存在しなくてもよい
261
282
  }
262
283
  else {
263
- const field = StockHolderRepository.offer2field(params.offer);
284
+ const field = StockHolderRepository.offer2field(params.offer, params.hasTicketedSeat);
264
285
  yield this.redisClient.multi()
265
286
  .hDel(key, field)
266
287
  .exec();
@@ -289,7 +310,11 @@ class StockHolderRepository {
289
310
  */
290
311
  countUnavailableOffers(params) {
291
312
  return __awaiter(this, void 0, void 0, function* () {
292
- if (StockHolderRepository.useMongoose({ eventId: params.event.id, startDate: params.event.startDate })) {
313
+ if (StockHolderRepository.useMongoose({
314
+ eventId: params.event.id,
315
+ startDate: params.event.startDate,
316
+ hasTicketedSeat: params.event.hasTicketedSeat
317
+ })) {
293
318
  // reservationCountを返す
294
319
  return this.holdReservationModel.findOne({
295
320
  'reservationFor.id': { $eq: params.event.id }
@@ -322,10 +347,13 @@ class StockHolderRepository {
322
347
  getHolder(params) {
323
348
  var _a;
324
349
  return __awaiter(this, void 0, void 0, function* () {
325
- if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
350
+ if (StockHolderRepository.useMongoose({
351
+ eventId: params.eventId,
352
+ startDate: params.startDate,
353
+ hasTicketedSeat: params.hasTicketedSeat
354
+ })) {
326
355
  // [id]あるいは[seatNumber+seatSection]でreservationNumberを返す
327
- // await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
328
- const subReservation = StockHolderRepository.offer2subReservation(params.offer);
356
+ const subReservation = StockHolderRepository.offer2subReservation(params.offer, params.hasTicketedSeat);
329
357
  const matchStages = [
330
358
  {
331
359
  $match: { 'reservationFor.id': { $eq: params.eventId } }
@@ -357,7 +385,7 @@ class StockHolderRepository {
357
385
  }
358
386
  else {
359
387
  const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
360
- const field = StockHolderRepository.offer2field(params.offer);
388
+ const field = StockHolderRepository.offer2field(params.offer, params.hasTicketedSeat);
361
389
  return this.redisClient.hGet(key, field);
362
390
  }
363
391
  });
@@ -396,10 +424,13 @@ class StockHolderRepository {
396
424
  // }
397
425
  searchHolders(params) {
398
426
  return __awaiter(this, void 0, void 0, function* () {
399
- if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
427
+ if (StockHolderRepository.useMongoose({
428
+ eventId: params.eventId,
429
+ startDate: params.startDate,
430
+ hasTicketedSeat: params.hasTicketedSeat
431
+ })) {
400
432
  // [id]あるいは[seatNumber+seatSection]のリストでreservationNumberのリストを返す
401
- // await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
402
- const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
433
+ const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, params.hasTicketedSeat));
403
434
  const matchStages = [
404
435
  {
405
436
  $match: { 'reservationFor.id': { $eq: params.eventId } }
@@ -432,7 +463,7 @@ class StockHolderRepository {
432
463
  else {
433
464
  const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
434
465
  const fields = params.offers.map((o) => {
435
- return StockHolderRepository.offer2field(o);
466
+ return StockHolderRepository.offer2field(o, params.hasTicketedSeat);
436
467
  });
437
468
  // Array reply: list of values associated with the given fields, in the same order as they are requested.
438
469
  const result = yield this.redisClient.hmGet(key, fields);
@@ -392,6 +392,7 @@ function filterByEligibleSeatingType(params) {
392
392
  eventId: params.event.id,
393
393
  startDate: moment(params.event.startDate)
394
394
  .toDate(),
395
+ hasTicketedSeat: true,
395
396
  offers: eligibleSeatOffers
396
397
  });
397
398
  // remainingAttendeeCapacity = availabilities.filter((a) => a.availability === factory.itemAvailability.InStock).length;
@@ -426,7 +427,8 @@ function aggregateReservationByEvent(params) {
426
427
  if (typeof eventLocationMaximumAttendeeCapacity === 'number') {
427
428
  maximumAttendeeCapacity = eventLocationMaximumAttendeeCapacity;
428
429
  }
429
- if (reservedSeatsAvailable({ event: params.event })) {
430
+ const hasTicketedSeat = reservedSeatsAvailable({ event: params.event });
431
+ if (hasTicketedSeat) {
430
432
  const screeningRoomSeatCount = (Array.isArray(params.screeningRoom.containsPlace))
431
433
  // b.containsPlaceがundefinedの場合があるので注意(座席未登録)
432
434
  ? params.screeningRoom.containsPlace.reduce((a, b) => a + ((Array.isArray(b.containsPlace)) ? b.containsPlace.length : 0), 0)
@@ -444,7 +446,8 @@ function aggregateReservationByEvent(params) {
444
446
  event: {
445
447
  id: params.event.id,
446
448
  startDate: moment(params.event.startDate)
447
- .toDate()
449
+ .toDate(),
450
+ hasTicketedSeat
448
451
  }
449
452
  });
450
453
  remainingAttendeeCapacity = maximumAttendeeCapacity - unavailableOfferCount;
@@ -243,6 +243,7 @@ function searchEventSeatOffers(params) {
243
243
  eventId: params.event.id,
244
244
  startDate: moment(params.event.startDate)
245
245
  .toDate(),
246
+ hasTicketedSeat: true,
246
247
  offers: seats.map((s) => {
247
248
  var _a;
248
249
  return {
@@ -626,7 +627,7 @@ function processLockOfferRateLimit(params) {
626
627
  */
627
628
  function processLockSeats(params) {
628
629
  return (repos) => __awaiter(this, void 0, void 0, function* () {
629
- var _a, _b;
630
+ var _a, _b, _c, _d, _e;
630
631
  const offers = [];
631
632
  params.reservations.forEach((r) => {
632
633
  var _a, _b;
@@ -675,13 +676,15 @@ function processLockSeats(params) {
675
676
  if (((_a = params.transaction.object) === null || _a === void 0 ? void 0 : _a.useHoldStockByTransactionNumber) === true) {
676
677
  holder = params.transaction.transactionNumber;
677
678
  }
678
- const maximumAttendeeCapacity4event = (_b = params.event.location) === null || _b === void 0 ? void 0 : _b.maximumAttendeeCapacity;
679
+ const hasTicketedSeat = ((_d = (_c = (_b = params.event.offers.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservedTicket) === null || _c === void 0 ? void 0 : _c.ticketedSeat) === null || _d === void 0 ? void 0 : _d.typeOf) === factory.placeType.Seat;
680
+ const maximumAttendeeCapacity4event = (_e = params.event.location) === null || _e === void 0 ? void 0 : _e.maximumAttendeeCapacity;
679
681
  if (typeof maximumAttendeeCapacity4event === 'number') {
680
682
  yield repos.stockHolder.lockIfNotLimitExceeded({
681
683
  project: { id: params.event.project.id },
682
684
  eventId: params.event.id,
683
685
  startDate: moment(params.event.startDate)
684
686
  .toDate(),
687
+ hasTicketedSeat,
685
688
  offers,
686
689
  expires,
687
690
  holder
@@ -693,6 +696,7 @@ function processLockSeats(params) {
693
696
  eventId: params.event.id,
694
697
  startDate: moment(params.event.startDate)
695
698
  .toDate(),
699
+ hasTicketedSeat,
696
700
  offers,
697
701
  expires,
698
702
  holder
@@ -448,7 +448,15 @@ function createScreeningEventFromCOA(params) {
448
448
  typeOf: 'WebAPI',
449
449
  identifier: factory.service.webAPI.Identifier.COA
450
450
  },
451
- priceCurrency: factory.priceCurrency.JPY
451
+ priceCurrency: factory.priceCurrency.JPY,
452
+ itemOffered: {
453
+ serviceOutput: {
454
+ reservedTicket: {
455
+ typeOf: 'Ticket',
456
+ ticketedSeat: { typeOf: factory.placeType.Seat }
457
+ }
458
+ }
459
+ }
452
460
  };
453
461
  const { additionalProperty, coaInfo } = createScreeningEventAdditionalPropertyFromCOA(params);
454
462
  return {
@@ -95,6 +95,7 @@ function searchEventSeatOffersWithPaging(params) {
95
95
  eventId: params.event.id,
96
96
  startDate: moment(event.startDate)
97
97
  .toDate(),
98
+ hasTicketedSeat: true,
98
99
  offers: seats.map((s) => {
99
100
  var _a;
100
101
  return {
@@ -350,6 +350,7 @@ function processUnlockSeat(params) {
350
350
  project: reservation.project,
351
351
  eventId: reservation.reservationFor.id,
352
352
  startDate: eventStartDate,
353
+ hasTicketedSeat: false,
353
354
  offer: {
354
355
  itemOffered: { serviceOutput: { id: reservation.id } },
355
356
  seatNumber: '',
@@ -368,6 +369,7 @@ function processUnlockSeat(params) {
368
369
  project: reservation.project,
369
370
  eventId: reservation.reservationFor.id,
370
371
  startDate: eventStartDate,
372
+ hasTicketedSeat: true,
371
373
  offer: {
372
374
  seatNumber: ticketedSeat.seatNumber,
373
375
  seatSection: ticketedSeat.seatSection
@@ -391,6 +393,7 @@ function processUnlockSeat(params) {
391
393
  project: reservation.project,
392
394
  eventId: reservation.reservationFor.id,
393
395
  startDate: eventStartDate,
396
+ hasTicketedSeat: true,
394
397
  offer: {
395
398
  seatNumber: seatNumber4sub,
396
399
  seatSection: seatSection4sub
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.38",
13
- "@cinerino/sdk": "3.157.0-alpha.13",
12
+ "@chevre/factory": "4.313.0-alpha.39",
13
+ "@cinerino/sdk": "3.157.0-alpha.16",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
16
16
  "@sendgrid/mail": "6.4.0",
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.129"
120
+ "version": "21.2.0-alpha.130"
121
121
  }