@chevre/domain 20.2.0-alpha.0 → 20.2.0-alpha.2

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.
@@ -0,0 +1,80 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ const POS_CLIENT_ID = process.env.POS_CLIENT_ID;
10
+ if (typeof POS_CLIENT_ID !== 'string') {
11
+ throw new Error('set POS_CLIENT_ID');
12
+ }
13
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
14
+
15
+ // tslint:disable-next-line:max-func-body-length
16
+ async function main() {
17
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
18
+
19
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
20
+
21
+ const cursor = eventRepo.getCursor(
22
+ {
23
+ // 'project.id': { $eq: project.id },
24
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
25
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
26
+ startDate: {
27
+ $gte: moment()
28
+ .add(-1, 'month')
29
+ .toDate()
30
+ }
31
+ // _id: { $eq: 'al6aff83w' }
32
+ },
33
+ {
34
+ // _id: 1,
35
+ }
36
+ );
37
+ console.log('events found');
38
+
39
+ let i = 0;
40
+ let updateCount = 0;
41
+ await cursor.eachAsync(async (doc) => {
42
+ i += 1;
43
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
44
+
45
+ // IAMメンバー検索
46
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
47
+ if (eventOffers === undefined) {
48
+ throw new Error('event.offers undefined');
49
+ }
50
+
51
+ const itemOfferedTypeOf = eventOffers.itemOffered.typeOf;
52
+
53
+ const alreadyMigrated = itemOfferedTypeOf === chevre.factory.product.ProductType.EventService;
54
+
55
+ if (alreadyMigrated) {
56
+ console.log(
57
+ 'already exist...', event.project.id, event.id, event.startDate, itemOfferedTypeOf, i);
58
+ } else {
59
+ console.log(
60
+ 'updating seller...', event.project.id, event.id, event.startDate, i);
61
+ await eventRepo.updatePartiallyById({
62
+ id: event.id,
63
+ attributes: <any>{
64
+ typeOf: event.typeOf,
65
+ 'offers.itemOffered.typeOf': chevre.factory.product.ProductType.EventService
66
+ }
67
+ });
68
+ updateCount += 1;
69
+ console.log(
70
+ 'updated...', event.project.id, event.id, event.startDate, i);
71
+ }
72
+ });
73
+
74
+ console.log(i, 'events checked');
75
+ console.log(updateCount, 'events updated');
76
+ }
77
+
78
+ main()
79
+ .then()
80
+ .catch(console.error);
@@ -130,6 +130,10 @@ class MongoRepository {
130
130
  }
131
131
  let params;
132
132
  switch (conditions.typeOf) {
133
+ case factory.eventType.Event:
134
+ // no op
135
+ // params = conditions;
136
+ break;
133
137
  case factory.eventType.ScreeningEvent:
134
138
  params = conditions;
135
139
  // tslint:disable-next-line:no-single-line-block-comment
@@ -232,6 +232,9 @@ class MongoRepository {
232
232
  });
233
233
  }
234
234
  switch (params.typeOf) {
235
+ case factory.reservationType.BusReservation:
236
+ // no op
237
+ break;
235
238
  case factory.reservationType.EventReservation:
236
239
  // tslint:disable-next-line:no-single-line-block-comment
237
240
  /* istanbul ignore else */
@@ -20,7 +20,7 @@ function createStartParams(params) {
20
20
  typeOf: params.transaction.typeOf,
21
21
  object: {
22
22
  reservationFor: {
23
- id: reservationFor.id,
23
+ id: String(reservationFor.id),
24
24
  typeOf: reservationFor.typeOf
25
25
  }
26
26
  }
@@ -60,7 +60,7 @@ function createPotentialActions(params) {
60
60
  const cancelObject = {
61
61
  reservationFor: {
62
62
  typeOf: reservationForByReserveTransaction.typeOf,
63
- id: reservationForByReserveTransaction.id
63
+ id: String(reservationForByReserveTransaction.id)
64
64
  },
65
65
  reservationNumber,
66
66
  // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
@@ -82,22 +82,44 @@ function createPotentialActions(params) {
82
82
  else if (Array.isArray(transaction.object.reservations)) {
83
83
  // 予約取消アクション属性作成
84
84
  cancelReservationActionAttributes = transaction.object.reservations.map((reservation) => {
85
- var _a;
85
+ var _a, _b;
86
86
  // 最適化(2022-06-06~)
87
- const cancelObject = {
88
- typeOf: reservation.typeOf,
89
- id: reservation.id,
90
- issuedThrough: {
91
- typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
92
- },
93
- reservationFor: {
94
- typeOf: reservation.reservationFor.typeOf,
95
- id: reservation.reservationFor.id
96
- },
97
- reservationNumber: reservation.reservationNumber,
98
- // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
99
- reservationStatus: factory.reservationStatusType.ReservationConfirmed
100
- };
87
+ let cancelObject;
88
+ if (reservation.typeOf === factory.reservationType.BusReservation) {
89
+ cancelObject = {
90
+ typeOf: reservation.typeOf,
91
+ id: reservation.id,
92
+ issuedThrough: {
93
+ typeOf: (_a = reservation.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf
94
+ },
95
+ reservationFor: {
96
+ typeOf: reservation.reservationFor.typeOf,
97
+ id: String(reservation.reservationFor.id)
98
+ },
99
+ reservationNumber: reservation.reservationNumber,
100
+ // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
101
+ reservationStatus: factory.reservationStatusType.ReservationConfirmed
102
+ };
103
+ }
104
+ else if (reservation.typeOf === factory.reservationType.EventReservation) {
105
+ cancelObject = {
106
+ typeOf: reservation.typeOf,
107
+ id: reservation.id,
108
+ issuedThrough: {
109
+ typeOf: (_b = reservation.issuedThrough) === null || _b === void 0 ? void 0 : _b.typeOf
110
+ },
111
+ reservationFor: {
112
+ typeOf: reservation.reservationFor.typeOf,
113
+ id: String(reservation.reservationFor.id)
114
+ },
115
+ reservationNumber: reservation.reservationNumber,
116
+ // ReservationConfirmed->ReservationCancelledのみ処理されるように保証する
117
+ reservationStatus: factory.reservationStatusType.ReservationConfirmed
118
+ };
119
+ }
120
+ else {
121
+ throw new factory.errors.NotImplemented(`reservation.typeOf ${reservation.typeOf} not imeplemented`);
122
+ }
101
123
  return {
102
124
  project: transaction.project,
103
125
  typeOf: factory.actionType.CancelAction,
@@ -18,7 +18,6 @@ export declare function createReservedTicket(params: {
18
18
  acceptedOffer: factory.assetTransaction.reserve.IAcceptedTicketOfferWithoutDetail;
19
19
  availableOffer: factory.unitPriceOffer.IUnitPriceOffer;
20
20
  dateIssued: Date;
21
- event: factory.event.screeningEvent.IEvent;
22
21
  reservedSeatsOnly: boolean;
23
22
  screeningRoomSections?: factory.place.screeningRoomSection.IPlace[];
24
23
  availableSeatOffers: factory.place.seat.IPlaceWithOffer[];
@@ -43,7 +42,7 @@ export declare function createAdditionalTicketText(params: {
43
42
  reservedTicket: factory.reservation.ITicket;
44
43
  }): string | undefined;
45
44
  export declare type IUnitPriceSpecification = factory.priceSpecification.IPriceSpecification<factory.priceSpecificationType.UnitPriceSpecification>;
46
- export declare function createReservationFor(params: factory.event.screeningEvent.IEvent): factory.assetTransaction.reserve.IReservationFor;
45
+ export declare function createReservationFor(params: factory.event.screeningEvent.IEvent | factory.event.event.IEvent): factory.assetTransaction.reserve.IReservationFor;
47
46
  export declare function createReservation(params: {
48
47
  project: {
49
48
  id: string;
@@ -54,7 +53,7 @@ export declare function createReservation(params: {
54
53
  agent: factory.assetTransaction.reserve.IAgent;
55
54
  broker?: factory.reservation.IBroker<factory.reservationType.EventReservation>;
56
55
  reservationNumber: string;
57
- reservationFor: factory.event.screeningEvent.IEvent;
56
+ reservationFor: factory.event.screeningEvent.IEvent | factory.event.event.IEvent;
58
57
  reservedTicket: factory.reservation.ITicket;
59
58
  additionalProperty?: factory.propertyValue.IPropertyValue<string>[];
60
59
  additionalTicketText?: string;
@@ -329,15 +329,19 @@ function createAdditionalTicketText(params) {
329
329
  }
330
330
  exports.createAdditionalTicketText = createAdditionalTicketText;
331
331
  function createReservationFor(params) {
332
- return Object.assign({ endDate: params.endDate,
333
- // 不要なので廃止(2022-12-19~)
334
- // eventStatus: params.eventStatus,
335
- id: params.id, location: params.location, name: params.name,
336
- // 不要なので廃止(2022-12-19~)
337
- // project: params.project,
338
- startDate: params.startDate, superEvent: optimizeReservationSuperEvent(params), typeOf: params.typeOf }, (params.doorTime instanceof Date)
339
- ? { doorTime: params.doorTime }
340
- : undefined);
332
+ var _a, _b;
333
+ if (params.typeOf === factory.eventType.ScreeningEvent) {
334
+ return Object.assign({ endDate: params.endDate, id: params.id, location: params.location, name: params.name, startDate: params.startDate, superEvent: optimizeReservationSuperEvent(params), typeOf: params.typeOf }, (params.doorTime instanceof Date)
335
+ ? { doorTime: params.doorTime }
336
+ : undefined);
337
+ }
338
+ else {
339
+ const tripByEvent = (_b = (_a = params.offers) === null || _a === void 0 ? void 0 : _a.itemOffered.serviceOutput) === null || _b === void 0 ? void 0 : _b.reservationFor;
340
+ if (typeof (tripByEvent === null || tripByEvent === void 0 ? void 0 : tripByEvent.typeOf) !== 'string') {
341
+ throw new factory.errors.NotFound('event.offers.itemOffered.serviceOutput?.reservationFor');
342
+ }
343
+ return Object.assign(Object.assign({}, tripByEvent), { arrivalTime: params.endDate, id: params.id, name: params.name, departureTime: params.startDate });
344
+ }
341
345
  }
342
346
  exports.createReservationFor = createReservationFor;
343
347
  function optimizeReservationSuperEvent(params) {
@@ -353,8 +357,9 @@ function optimizeReservationSuperEvent(params) {
353
357
  ? { headline: superEvent.headline }
354
358
  : undefined);
355
359
  }
360
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
356
361
  function createReservation(params) {
357
- var _a, _b, _c;
362
+ var _a, _b, _c, _d, _e;
358
363
  // 適用メンバーシップ確認
359
364
  validateEligibleMembershipType({
360
365
  availableOffer: params.availableOffer,
@@ -381,31 +386,56 @@ function createReservation(params) {
381
386
  typeOf: 'CategoryCodeSet',
382
387
  identifier: factory.categoryCode.CategorySetIdentifier.ServiceType
383
388
  },
384
- // project: params.project,
385
389
  typeOf: 'CategoryCode'
386
390
  }
387
391
  : undefined;
388
- const issuedThrough = Object.assign(Object.assign({ typeOf: factory.product.ProductType.EventService }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined), (typeof eventOffers.itemOffered.id === 'string') ? { id: eventOffers.itemOffered.id } : undefined);
389
- return Object.assign(Object.assign(Object.assign(Object.assign({ project: params.project, typeOf: factory.reservationType.EventReservation, id: params.id, issuedThrough, additionalProperty: params.additionalProperty, bookingTime: params.reserveDate, modifiedTime: params.reserveDate, numSeats: 1, price: price4reservation, priceCurrency: factory.priceCurrency.JPY, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, reservedTicket: params.reservedTicket,
390
- // 最適化(2022-12-19~)
391
- // underName: params.agent,
392
- underName: {
393
- typeOf: params.agent.typeOf,
394
- name: params.agent.name
395
- }, checkedIn: false, attended: false }, (typeof params.additionalTicketText === 'string') ? { additionalTicketText: params.additionalTicketText } : undefined), (Array.isArray(params.subReservation))
396
- ? {
397
- subReservation: params.subReservation.map((r) => {
398
- return {
399
- reservedTicket: {
400
- ticketedSeat: r.reservedTicket.ticketedSeat,
401
- typeOf: 'Ticket'
402
- }
403
- };
404
- })
405
- }
406
- : undefined), (typeof ((_b = params.broker) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { broker: params.broker } : undefined), (typeof ((_c = params.programMembershipUsed) === null || _c === void 0 ? void 0 : _c.identifier) === 'string')
407
- ? { programMembershipUsed: params.programMembershipUsed }
408
- : undefined);
392
+ const availableChannel = eventOffers.itemOffered.availableChannel;
393
+ if (params.reservationFor.typeOf === factory.eventType.ScreeningEvent) {
394
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.EventService,
395
+ // 興行IDを追加(2022-09-08~)
396
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
397
+ return Object.assign(Object.assign(Object.assign(Object.assign({ project: params.project, typeOf: factory.reservationType.EventReservation, id: params.id, issuedThrough, additionalProperty: params.additionalProperty, bookingTime: params.reserveDate, modifiedTime: params.reserveDate, numSeats: 1, price: price4reservation, priceCurrency: factory.priceCurrency.JPY, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, reservedTicket: params.reservedTicket,
398
+ // 最適化(2022-12-19~)
399
+ underName: {
400
+ typeOf: params.agent.typeOf,
401
+ name: params.agent.name
402
+ }, checkedIn: false, attended: false }, (typeof params.additionalTicketText === 'string') ? { additionalTicketText: params.additionalTicketText } : undefined), (Array.isArray(params.subReservation))
403
+ ? {
404
+ subReservation: params.subReservation.map((r) => {
405
+ return {
406
+ reservedTicket: {
407
+ ticketedSeat: r.reservedTicket.ticketedSeat,
408
+ typeOf: 'Ticket'
409
+ }
410
+ };
411
+ })
412
+ }
413
+ : undefined), (typeof ((_b = params.broker) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { broker: params.broker } : undefined), (typeof ((_c = params.programMembershipUsed) === null || _c === void 0 ? void 0 : _c.identifier) === 'string')
414
+ ? { programMembershipUsed: params.programMembershipUsed }
415
+ : undefined);
416
+ }
417
+ else {
418
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.Transportation,
419
+ // 興行IDを追加(2022-09-08~)
420
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
421
+ return Object.assign(Object.assign(Object.assign(Object.assign({ project: params.project, typeOf: factory.reservationType.BusReservation, id: params.id, issuedThrough, additionalProperty: params.additionalProperty, bookingTime: params.reserveDate, modifiedTime: params.reserveDate, numSeats: 1, price: price4reservation, priceCurrency: factory.priceCurrency.JPY, reservationNumber: params.reservationNumber, reservationStatus: factory.reservationStatusType.ReservationPending, reservedTicket: params.reservedTicket, underName: {
422
+ typeOf: params.agent.typeOf,
423
+ name: params.agent.name
424
+ }, checkedIn: false, attended: false }, (typeof params.additionalTicketText === 'string') ? { additionalTicketText: params.additionalTicketText } : undefined), (Array.isArray(params.subReservation))
425
+ ? {
426
+ subReservation: params.subReservation.map((r) => {
427
+ return {
428
+ reservedTicket: {
429
+ ticketedSeat: r.reservedTicket.ticketedSeat,
430
+ typeOf: 'Ticket'
431
+ }
432
+ };
433
+ })
434
+ }
435
+ : undefined), (typeof ((_d = params.broker) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string') ? { broker: params.broker } : undefined), (typeof ((_e = params.programMembershipUsed) === null || _e === void 0 ? void 0 : _e.identifier) === 'string')
436
+ ? { programMembershipUsed: params.programMembershipUsed }
437
+ : undefined);
438
+ }
409
439
  }
410
440
  exports.createReservation = createReservation;
411
441
  // tslint:disable-next-line:max-func-body-length
@@ -76,7 +76,12 @@ function addReservations(params) {
76
76
  aggregateReservation: 0, aggregateOffer: 0, attendeeCount: 0,
77
77
  checkInCount: 0, maximumAttendeeCapacity: 0, remainingAttendeeCapacity: 0
78
78
  });
79
- validateEvent({ now, event });
79
+ if (event.typeOf !== factory.eventType.ScreeningEvent && event.typeOf !== factory.eventType.Event) {
80
+ throw new factory.errors.Argument('object.reservationFor.id', `invalid event type ${event.typeOf}`);
81
+ }
82
+ if (event.typeOf === factory.eventType.ScreeningEvent || event.typeOf === factory.eventType.Event) {
83
+ validateEvent({ now, event });
84
+ }
80
85
  // イベントオファー検索
81
86
  const ticketOffers = yield OfferService.event.searchEventTicketOffers({ event: { id: event.id } })(repos);
82
87
  let availableOffers = [];
@@ -91,11 +96,7 @@ function addReservations(params) {
91
96
  }
92
97
  }
93
98
  else {
94
- // hasOfferCatalog参照廃止(2022-09-02~)
95
99
  throw new factory.errors.NotFound('event.offers.itemOffered.id');
96
- // if (typeof event.hasOfferCatalog?.id === 'string') {
97
- // availableOffers = await repos.offer.findOffersByOfferCatalogId({ offerCatalog: { id: event.hasOfferCatalog.id } });
98
- // }
99
100
  }
100
101
  const availableSeatOffers = yield searchAvailableSeatOffers({ acceptedOffers, event: { id: event.id } })(repos);
101
102
  // 仮予約作成
@@ -247,7 +248,7 @@ function createReservations4transactionObject(params) {
247
248
  acceptedOffer: acceptedOffer,
248
249
  availableOffer: ticketType,
249
250
  dateIssued: params.now,
250
- event: params.event,
251
+ // event: params.event,
251
252
  reservedSeatsOnly,
252
253
  availableSeatOffers: params.availableSeatOffers,
253
254
  ticketOffer: ticketOffer,
@@ -446,8 +447,11 @@ function processLockOfferRateLimit(params) {
446
447
  }
447
448
  },
448
449
  reservationFor: {
449
- startDate: moment(params.reservationFor.startDate)
450
- .toDate()
450
+ startDate: (params.reservationFor.typeOf === factory.eventType.ScreeningEvent)
451
+ ? moment(params.reservationFor.startDate)
452
+ .toDate()
453
+ : moment(params.reservationFor.departureTime)
454
+ .toDate()
451
455
  },
452
456
  reservationNumber: reservation.reservationNumber
453
457
  };
@@ -622,7 +626,7 @@ function cancel(params) {
622
626
  const reservationPackage = {
623
627
  typeOf: factory.reservationType.ReservationPackage,
624
628
  reservationNumber: transaction.transactionNumber,
625
- reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
629
+ reservationFor: { typeOf: reservationFor.typeOf, id: String(reservationFor.id) },
626
630
  reservationStatus: pendingReservations[0].reservationStatus
627
631
  };
628
632
  cancelActionAttributes = [{
@@ -712,7 +716,7 @@ function exportTasksById(params) {
712
716
  const reservationPackage = {
713
717
  typeOf: factory.reservationType.ReservationPackage,
714
718
  reservationNumber: transaction.transactionNumber,
715
- reservationFor: { typeOf: reservationFor.typeOf, id: reservationFor.id },
719
+ reservationFor: { typeOf: reservationFor.typeOf, id: String(reservationFor.id) },
716
720
  reservationStatus: pendingReservations[0].reservationStatus
717
721
  };
718
722
  cancelActionAttributes = [{
@@ -4,14 +4,24 @@ exports.createReservationOwnershipInfo = void 0;
4
4
  const moment = require("moment-timezone");
5
5
  const factory = require("../../../factory");
6
6
  function createReservationOwnershipInfo(params) {
7
- var _a;
7
+ var _a, _b;
8
8
  const itemOffered = params.acceptedOffer.itemOffered;
9
9
  let ownershipInfo;
10
10
  // イベント予約に対する所有権の有効期限はイベント終了日時までで十分だろう
11
11
  // 現時点では所有権対象がイベント予約のみなので、これで問題ないが、
12
12
  // 対象が他に広がれば、有効期間のコントロールは別でしっかり行う必要があるだろう
13
- const ownedThrough = moment(itemOffered.reservationFor.endDate)
14
- .toDate();
13
+ let ownedThrough;
14
+ if (itemOffered.typeOf === factory.reservationType.EventReservation) {
15
+ ownedThrough = moment(itemOffered.reservationFor.endDate)
16
+ .toDate();
17
+ }
18
+ else if (itemOffered.typeOf === factory.reservationType.BusReservation) {
19
+ ownedThrough = moment(itemOffered.reservationFor.arrivalTime)
20
+ .toDate();
21
+ }
22
+ else {
23
+ throw new factory.errors.NotImplemented(`itemOffered.typeOf '${itemOffered.typeOf}' not implemented`);
24
+ }
15
25
  let bookingService = params.acceptedOffer.offeredThrough;
16
26
  if (bookingService === undefined) {
17
27
  // デフォルトブッキングサービスはChevre
@@ -35,6 +45,16 @@ function createReservationOwnershipInfo(params) {
35
45
  };
36
46
  }
37
47
  else {
48
+ let typeOfGood;
49
+ if (itemOffered.typeOf === factory.reservationType.EventReservation) {
50
+ typeOfGood = Object.assign({ typeOf: itemOffered.typeOf, id: itemOffered.id, reservationNumber: itemOffered.reservationNumber, bookingService: bookingService }, (typeof ((_a = itemOffered.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { issuedThrough: itemOffered.issuedThrough } : undefined);
51
+ }
52
+ else if (itemOffered.typeOf === factory.reservationType.BusReservation) {
53
+ typeOfGood = Object.assign({ typeOf: itemOffered.typeOf, id: itemOffered.id, reservationNumber: itemOffered.reservationNumber, bookingService: bookingService }, (typeof ((_b = itemOffered.issuedThrough) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { issuedThrough: itemOffered.issuedThrough } : undefined);
54
+ }
55
+ else {
56
+ throw new factory.errors.NotImplemented(`itemOffered.typeOf '${itemOffered.typeOf}' not implemented`);
57
+ }
38
58
  ownershipInfo = {
39
59
  project: params.project,
40
60
  typeOf: 'OwnershipInfo',
@@ -44,9 +64,7 @@ function createReservationOwnershipInfo(params) {
44
64
  acquiredFrom: params.acquiredFrom,
45
65
  ownedFrom: params.ownedFrom,
46
66
  ownedThrough: ownedThrough,
47
- typeOfGood: Object.assign({ typeOf: itemOffered.typeOf, id: itemOffered.id, reservationNumber: itemOffered.reservationNumber, bookingService: bookingService }, (typeof ((_a = itemOffered.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
48
- ? { issuedThrough: itemOffered.issuedThrough }
49
- : undefined)
67
+ typeOfGood
50
68
  };
51
69
  }
52
70
  return ownershipInfo;
@@ -209,58 +209,55 @@ exports.responseBody2acceptedOffers4result = responseBody2acceptedOffers4result;
209
209
  /**
210
210
  * 注文データの予約を生成する
211
211
  */
212
+ // tslint:disable-next-line:max-func-body-length
212
213
  function createReservation(params) {
213
214
  var _a;
214
215
  const itemOffered = params.itemOffered;
215
216
  const event = params.event;
216
- const workPerformed = Object.assign({
217
- // 不要なので廃止(2022-12-19~)
218
- // project: event.superEvent.workPerformed.project,
219
- typeOf: event.superEvent.workPerformed.typeOf, id: event.superEvent.workPerformed.id, identifier: event.superEvent.workPerformed.identifier, name: event.superEvent.workPerformed.name }, (typeof event.superEvent.workPerformed.duration === 'string')
220
- ? { duration: event.superEvent.workPerformed.duration }
221
- : undefined);
222
- const reservationFor = {
223
- // 不要なので廃止(2022-12-19~)
224
- // project: event.project,
225
- typeOf: event.typeOf,
226
- // 予約のreservationForは最適化されているので、additionalPropertyは存在しない
227
- // additionalProperty: itemOffered.reservationFor.additionalProperty,
228
- // 不要なので廃止(2022-12-19~)
229
- // eventStatus: event.eventStatus,
230
- id: event.id,
231
- location: event.location,
232
- name: event.name,
233
- doorTime: moment(event.doorTime)
234
- .toDate(),
235
- endDate: moment(event.endDate)
236
- .toDate(),
237
- startDate: moment(event.startDate)
238
- .toDate(),
239
- // 最適化(2022-05-31~)
240
- superEvent: Object.assign(Object.assign({
241
- // 不要なので廃止(2022-12-19~)
242
- // project: event.superEvent.project,
243
- typeOf: event.superEvent.typeOf, id: event.superEvent.id, kanaName: event.superEvent.kanaName, location: event.superEvent.location, name: event.superEvent.name, soundFormat: event.superEvent.soundFormat, videoFormat: event.superEvent.videoFormat, workPerformed }, (typeof event.superEvent.duration === 'string') ? { duration: event.superEvent.duration } : undefined), (event.superEvent.headline !== undefined) ? { headline: event.superEvent.headline } : undefined)
244
- // 廃止(superEvent.workPerformedへ完全移行)
245
- // workPerformed: {},
246
- };
217
+ let reservationItem;
247
218
  const reservedTicket = Object.assign({ typeOf: itemOffered.reservedTicket.typeOf, ticketType: {
248
- // 不要なので廃止(2022-12-17~)
249
- // project: { typeOf: params.project.typeOf, id: params.project.id },
250
219
  typeOf: itemOffered.reservedTicket.ticketType.typeOf,
251
220
  id: itemOffered.reservedTicket.ticketType.id,
252
221
  identifier: itemOffered.reservedTicket.ticketType.identifier,
253
222
  name: itemOffered.reservedTicket.ticketType.name,
254
223
  description: itemOffered.reservedTicket.ticketType.description,
255
224
  additionalProperty: itemOffered.reservedTicket.ticketType.additionalProperty
256
- // 不要なので廃止(2022-12-17~)
257
- // priceCurrency: itemOffered.reservedTicket.ticketType.priceCurrency
258
225
  } }, (itemOffered.reservedTicket.ticketedSeat !== undefined)
259
226
  ? { ticketedSeat: itemOffered.reservedTicket.ticketedSeat }
260
227
  : undefined);
261
- return Object.assign({ project: itemOffered.project, typeOf: itemOffered.typeOf, additionalProperty: itemOffered.additionalProperty, additionalTicketText: itemOffered.additionalTicketText, id: itemOffered.id, issuedThrough: itemOffered.issuedThrough, reservationNumber: itemOffered.reservationNumber, reservationFor: reservationFor, reservedTicket: reservedTicket }, (typeof ((_a = itemOffered.programMembershipUsed) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
262
- ? { programMembershipUsed: itemOffered.programMembershipUsed }
263
- : undefined);
228
+ if (itemOffered.typeOf === factory.reservationType.EventReservation
229
+ && event.typeOf === factory.eventType.ScreeningEvent) {
230
+ const workPerformed = Object.assign({ typeOf: event.superEvent.workPerformed.typeOf, id: event.superEvent.workPerformed.id, identifier: event.superEvent.workPerformed.identifier, name: event.superEvent.workPerformed.name }, (typeof event.superEvent.workPerformed.duration === 'string')
231
+ ? { duration: event.superEvent.workPerformed.duration }
232
+ : undefined);
233
+ const reservationFor = {
234
+ typeOf: event.typeOf,
235
+ id: event.id,
236
+ location: event.location,
237
+ name: event.name,
238
+ doorTime: moment(event.doorTime)
239
+ .toDate(),
240
+ endDate: moment(event.endDate)
241
+ .toDate(),
242
+ startDate: moment(event.startDate)
243
+ .toDate(),
244
+ // 最適化(2022-05-31~)
245
+ superEvent: Object.assign(Object.assign({ typeOf: event.superEvent.typeOf, id: event.superEvent.id, kanaName: event.superEvent.kanaName, location: event.superEvent.location, name: event.superEvent.name, soundFormat: event.superEvent.soundFormat, videoFormat: event.superEvent.videoFormat, workPerformed }, (typeof event.superEvent.duration === 'string') ? { duration: event.superEvent.duration } : undefined), (event.superEvent.headline !== undefined) ? { headline: event.superEvent.headline } : undefined)
246
+ // 廃止(superEvent.workPerformedへ完全移行)
247
+ // workPerformed: {},
248
+ };
249
+ reservationItem = Object.assign({ project: itemOffered.project, typeOf: itemOffered.typeOf, additionalProperty: itemOffered.additionalProperty, additionalTicketText: itemOffered.additionalTicketText, id: itemOffered.id, issuedThrough: itemOffered.issuedThrough, reservationNumber: itemOffered.reservationNumber, reservationFor: reservationFor, reservedTicket: reservedTicket }, (typeof ((_a = itemOffered.programMembershipUsed) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
250
+ ? { programMembershipUsed: itemOffered.programMembershipUsed }
251
+ : undefined);
252
+ }
253
+ else if (itemOffered.typeOf === factory.reservationType.BusReservation
254
+ && event.typeOf === factory.eventType.Event) {
255
+ throw new factory.errors.NotImplemented(`${itemOffered.typeOf} not impelemented`);
256
+ }
257
+ else {
258
+ throw new factory.errors.Argument('itemOffered');
259
+ }
260
+ return reservationItem;
264
261
  }
265
262
  function coaTicket2offer(params) {
266
263
  var _a, _b;
@@ -172,7 +172,25 @@ function responseBody2acceptedOffers4result(params) {
172
172
  };
173
173
  const additionalProperty = (_c = (_b = requestedOffer.itemOffered) === null || _b === void 0 ? void 0 : _b.serviceOutput) === null || _c === void 0 ? void 0 : _c.additionalProperty;
174
174
  const additionalTicketText = (_e = (_d = requestedOffer.itemOffered) === null || _d === void 0 ? void 0 : _d.serviceOutput) === null || _e === void 0 ? void 0 : _e.additionalTicketText;
175
- const reservation = Object.assign(Object.assign(Object.assign({ project: { typeOf: event.project.typeOf, id: event.project.id }, typeOf: factory.reservationType.EventReservation, id: reservationId, issuedThrough: { typeOf: factory.product.ProductType.EventService }, bookingTime: params.bookingTime }, (Array.isArray(additionalProperty)) ? { additionalProperty } : undefined), (typeof additionalTicketText === 'string') ? { additionalTicketText } : undefined), {
175
+ const issuedThrough = {
176
+ typeOf: factory.product.ProductType.EventService,
177
+ id: '',
178
+ availableChannel: {
179
+ typeOf: 'ServiceChannel',
180
+ serviceLocation: {
181
+ typeOf: reservationFor.location.typeOf,
182
+ branchCode: reservationFor.location.branchCode,
183
+ name: reservationFor.location.name,
184
+ containedInPlace: {
185
+ typeOf: reservationFor.superEvent.location.typeOf,
186
+ id: reservationFor.superEvent.location.id,
187
+ branchCode: reservationFor.superEvent.location.branchCode,
188
+ name: reservationFor.superEvent.location.name
189
+ }
190
+ }
191
+ }
192
+ };
193
+ const reservation = Object.assign(Object.assign(Object.assign({ project: { typeOf: event.project.typeOf, id: event.project.id }, typeOf: factory.reservationType.EventReservation, id: reservationId, issuedThrough, bookingTime: params.bookingTime }, (Array.isArray(additionalProperty)) ? { additionalProperty } : undefined), (typeof additionalTicketText === 'string') ? { additionalTicketText } : undefined), {
176
194
  // numSeats: 1, // 廃止(2022-08-18~)
177
195
  reservationFor: reservationFor, reservationNumber: reservationNumber, reservedTicket: reservedTicket });
178
196
  if (requestedOffer.priceSpecification === undefined) {
@@ -62,7 +62,7 @@ function cancelPendingReservation(actionAttributesList) {
62
62
  id: cancelingSubReservation.id,
63
63
  reservedTicket: cancelingSubReservation.reservedTicket,
64
64
  subReservation: cancelingSubReservation.subReservation,
65
- reservationFor: { id: reservationFor.id }
65
+ reservationFor: { id: String(reservationFor.id) }
66
66
  },
67
67
  expectedHolder: reserveTransactionId
68
68
  })(repos);
@@ -197,7 +197,7 @@ function cancelReservation(actionAttributesList) {
197
197
  id: cancelingSubReservation.id,
198
198
  reservedTicket: cancelingSubReservation.reservedTicket,
199
199
  subReservation: cancelingSubReservation.subReservation,
200
- reservationFor: { id: reservationFor.id }
200
+ reservationFor: { id: String(reservationFor.id) }
201
201
  },
202
202
  expectedHolder: reserveTransaction.id
203
203
  })(repos);
@@ -384,8 +384,11 @@ function processUnlockOfferRateLimit(params) {
384
384
  }
385
385
  },
386
386
  reservationFor: {
387
- startDate: moment(params.reservationFor.startDate)
388
- .toDate()
387
+ startDate: (params.reservationFor.typeOf === factory.eventType.ScreeningEvent)
388
+ ? moment(params.reservationFor.startDate)
389
+ .toDate()
390
+ : moment(params.reservationFor.departureTime)
391
+ .toDate()
389
392
  },
390
393
  reservationNumber: reservation.reservationNumber
391
394
  };
@@ -20,8 +20,8 @@ function createReservationAcceptedOffers(params) {
20
20
  const reservationFor = resultAcceptedOffers[0].itemOffered.reservationFor;
21
21
  const issuedThrough = resultAcceptedOffers[0].itemOffered.issuedThrough;
22
22
  if (typeof (issuedThrough === null || issuedThrough === void 0 ? void 0 : issuedThrough.typeOf) === 'string') {
23
- if (!eventIds.includes(reservationFor.id)) {
24
- eventIds.push(reservationFor.id);
23
+ if (!eventIds.includes(String(reservationFor.id))) {
24
+ eventIds.push(String(reservationFor.id));
25
25
  const orderedItem = reservationOffers2orderedItem({ reservationFor, issuedThrough });
26
26
  orderedItems.push({
27
27
  typeOf: 'OrderItem',
@@ -38,6 +38,9 @@ function reservationOffers2orderedItem(params) {
38
38
  var _a, _b, _c, _d;
39
39
  const reservationFor = params.reservationFor;
40
40
  const issuedThrough = params.issuedThrough;
41
+ if (reservationFor.typeOf !== factory.eventType.ScreeningEvent) {
42
+ throw new factory.errors.NotImplemented(`reservationFor.typeOf '${reservationFor.typeOf}' not implemented`);
43
+ }
41
44
  const reservationFor4orderedItem = {
42
45
  location: {
43
46
  branchCode: (_a = reservationFor.location) === null || _a === void 0 ? void 0 : _a.branchCode,
@@ -54,10 +57,10 @@ function reservationOffers2orderedItem(params) {
54
57
  startDate: reservationFor.startDate,
55
58
  endDate: reservationFor.endDate
56
59
  };
57
- return Object.assign(Object.assign({
58
- // 不要なので廃止(2022-12-19~)
59
- // project: reservationFor.project,
60
- typeOf: issuedThrough.typeOf }, (typeof ((_d = issuedThrough.serviceType) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string')
60
+ if (issuedThrough.typeOf !== factory.product.ProductType.EventService) {
61
+ throw new factory.errors.NotImplemented(`issuedThrough.typeOf '${issuedThrough.typeOf}' not implemented`);
62
+ }
63
+ return Object.assign(Object.assign({ typeOf: issuedThrough.typeOf }, (typeof ((_d = issuedThrough.serviceType) === null || _d === void 0 ? void 0 : _d.typeOf) === 'string')
61
64
  ? { serviceType: issuedThrough.serviceType }
62
65
  : undefined), { serviceOutput: {
63
66
  typeOf: factory.reservationType.EventReservation,
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.281.0-alpha.0",
12
+ "@chevre/factory": "4.281.0-alpha.2",
13
13
  "@cinerino/sdk": "3.135.0-alpha.6",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -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.0"
123
+ "version": "20.2.0-alpha.2"
124
124
  }
@@ -1,139 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as moment from 'moment';
3
- import * as mongoose from 'mongoose';
4
-
5
- import { chevre } from '../../../lib/index';
6
-
7
- // const project = { id: String(process.env.PROJECT_ID) };
8
-
9
- const AVAILABLE_ROLE_NAMES = ['customer', 'pos'];
10
- const POS_CLIENT_ID = process.env.POS_CLIENT_ID;
11
- if (typeof POS_CLIENT_ID !== 'string') {
12
- throw new Error('set POS_CLIENT_ID');
13
- }
14
- const MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = 93;
15
- const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
16
-
17
- // tslint:disable-next-line:max-func-body-length
18
- async function main() {
19
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
20
-
21
- const eventRepo = new chevre.repository.Event(mongoose.connection);
22
- const memberRepo = new chevre.repository.Member(mongoose.connection);
23
-
24
- const cursor = eventRepo.getCursor(
25
- {
26
- // 'project.id': { $eq: project.id },
27
- 'project.id': { $ne: EXCLUDED_PROJECT_ID },
28
- typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
29
- startDate: {
30
- $gte: moment()
31
- .add(-1, 'month')
32
- .toDate()
33
- }
34
- // _id: { $eq: 'al6aff83w' }
35
- },
36
- {
37
- // _id: 1,
38
- }
39
- );
40
- console.log('events found');
41
-
42
- let i = 0;
43
- let updateCount = 0;
44
- await cursor.eachAsync(async (doc) => {
45
- i += 1;
46
- const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
47
-
48
- // IAMメンバー検索
49
- const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
50
- if (eventOffers === undefined) {
51
- throw new Error('event.offers undefined');
52
- }
53
-
54
- const makesOfferFromEvent = eventOffers.seller.makesOffer;
55
-
56
- const alreadyMigrated = Array.isArray(makesOfferFromEvent)
57
- && makesOfferFromEvent.length > 0
58
- && makesOfferFromEvent.every((offer) => {
59
- return offer.availabilityEnds instanceof Date
60
- && offer.availabilityStarts instanceof Date
61
- && offer.validFrom instanceof Date
62
- && offer.validThrough instanceof Date
63
- && Array.isArray(offer.availableAtOrFrom)
64
- && offer.availableAtOrFrom.length === 1;
65
- });
66
-
67
- if (alreadyMigrated) {
68
- console.log(
69
- 'already exist...', event.project.id, event.id, event.startDate, makesOfferFromEvent.length, i);
70
- } else {
71
- let existingApplicationMembers = await memberRepo.search({
72
- limit: 100,
73
- page: 1,
74
- project: { id: { $eq: event.project.id } },
75
- member: { typeOf: { $eq: chevre.factory.creativeWorkType.WebApplication } }
76
- });
77
- // ロールで絞る(customer or pos)
78
- existingApplicationMembers = existingApplicationMembers
79
- .filter((m) => {
80
- return Array.isArray(m.member.hasRole) && m.member.hasRole.some((r) => AVAILABLE_ROLE_NAMES.includes(r.roleName));
81
- });
82
- console.log(
83
- existingApplicationMembers.length,
84
- 'existingApplicationMembers found.',
85
- event.project.id,
86
- existingApplicationMembers.map((m) => m.member.name)
87
- .join(',')
88
- );
89
- const newMakesOffer: chevre.factory.event.screeningEvent.ISellerMakesOffer[] = existingApplicationMembers.map((a) => {
90
- // posについては有効期間調整
91
- if (a.member.id === POS_CLIENT_ID) {
92
- const validFrom4pos: Date = moment(event.startDate)
93
- .add(-MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS, 'days')
94
- .toDate();
95
- const validThrough4pos: Date = moment(event.endDate)
96
- .add(1, 'month')
97
- .toDate();
98
-
99
- return {
100
- typeOf: chevre.factory.offerType.Offer,
101
- availableAtOrFrom: [{ id: a.member.id }],
102
- availabilityEnds: validThrough4pos, // 1 month later from endDate
103
- availabilityStarts: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
104
- validFrom: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
105
- validThrough: validThrough4pos // 1 month later from endDate
106
- };
107
- } else {
108
- return {
109
- typeOf: chevre.factory.offerType.Offer,
110
- availableAtOrFrom: [{ id: a.member.id }],
111
- availabilityEnds: eventOffers.availabilityEnds,
112
- availabilityStarts: eventOffers.availabilityStarts,
113
- validFrom: eventOffers.validFrom,
114
- validThrough: eventOffers.validThrough
115
- };
116
- }
117
- });
118
- console.log(
119
- 'updating seller...', event.project.id, event.id, event.startDate, newMakesOffer.length, i);
120
- await eventRepo.updatePartiallyById({
121
- id: event.id,
122
- attributes: <any>{
123
- typeOf: event.typeOf,
124
- 'offers.seller.makesOffer': newMakesOffer
125
- }
126
- });
127
- updateCount += 1;
128
- console.log(
129
- 'updated...', event.project.id, event.id, event.startDate, newMakesOffer.length, i);
130
- }
131
- });
132
-
133
- console.log(i, 'events checked');
134
- console.log(updateCount, 'events updated');
135
- }
136
-
137
- main()
138
- .then()
139
- .catch(console.error);