@chevre/domain 21.2.0-alpha.95 → 21.2.0-alpha.97

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.
@@ -69,7 +69,9 @@ async function main() {
69
69
  validateEvent: false,
70
70
  validateEventOfferPeriod: false,
71
71
  validateAppliesToMovieTicket: true,
72
- disablePendingReservations: true
72
+ disablePendingReservations: true,
73
+ stockHoldUntilDaysAfterEventEnd: 31,
74
+ useHoldStockByTransactionNumber: true
73
75
  })({
74
76
  stockHolder: itemAvailabilityRepo,
75
77
  event: eventRepo,
@@ -0,0 +1,30 @@
1
+ // tslint:disable:no-implicit-dependencies no-console
2
+ import { chevre } from '../../../lib/index';
3
+
4
+ import * as mongoose from 'mongoose';
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: true });
10
+
11
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
12
+ const assetTransactions = await assetTransactionRepo.search(
13
+ {
14
+ typeOf: chevre.factory.assetTransactionType.Reserve,
15
+ project: { id: { $eq: project.id } },
16
+ object: {
17
+ reservations: { reservedTicket: { ticketedSeat: { seatNumber: { $eq: 'A-03' } } } }
18
+ }
19
+ },
20
+ ['_id', 'transactionNumber'],
21
+ []
22
+ );
23
+ console.log('assetTransactions:', assetTransactions);
24
+ }
25
+
26
+ main()
27
+ .then(() => {
28
+ console.log('success!');
29
+ })
30
+ .catch(console.error);
@@ -67,7 +67,7 @@ export declare class MongoRepository {
67
67
  addReservations(params: {
68
68
  typeOf: factory.assetTransactionType.Reserve;
69
69
  id: string;
70
- object: Pick<factory.assetTransaction.reserve.IObject, 'acceptedOffer' | 'reservationFor' | 'subReservation'>;
70
+ object: Pick<factory.assetTransaction.reserve.IObject, 'acceptedOffer' | 'issuedThrough' | 'reservationFor' | 'subReservation'>;
71
71
  }): Promise<factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>>;
72
72
  /**
73
73
  * 取引を確定する
@@ -23,7 +23,7 @@ class MongoRepository {
23
23
  }
24
24
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
25
25
  static CREATE_MONGO_CONDITIONS(params) {
26
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;
26
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21;
27
27
  const andConditions = [
28
28
  {
29
29
  typeOf: params.typeOf
@@ -246,9 +246,18 @@ class MongoRepository {
246
246
  }
247
247
  });
248
248
  }
249
+ const objectSubReservationSeatNumberEq = (_13 = (_12 = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.reservations) === null || _10 === void 0 ? void 0 : _10.reservedTicket) === null || _11 === void 0 ? void 0 : _11.ticketedSeat) === null || _12 === void 0 ? void 0 : _12.seatNumber) === null || _13 === void 0 ? void 0 : _13.$eq;
250
+ if (typeof objectSubReservationSeatNumberEq === 'string') {
251
+ andConditions.push({
252
+ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': {
253
+ $exists: true,
254
+ $eq: objectSubReservationSeatNumberEq
255
+ }
256
+ });
257
+ }
249
258
  break;
250
259
  case factory.assetTransactionType.RegisterService:
251
- const objectItemOfferedServiceOutputIdentifierEq = (_12 = (_11 = (_10 = (_9 = params.object) === null || _9 === void 0 ? void 0 : _9.itemOffered) === null || _10 === void 0 ? void 0 : _10.serviceOutput) === null || _11 === void 0 ? void 0 : _11.identifier) === null || _12 === void 0 ? void 0 : _12.$eq;
260
+ const objectItemOfferedServiceOutputIdentifierEq = (_17 = (_16 = (_15 = (_14 = params.object) === null || _14 === void 0 ? void 0 : _14.itemOffered) === null || _15 === void 0 ? void 0 : _15.serviceOutput) === null || _16 === void 0 ? void 0 : _16.identifier) === null || _17 === void 0 ? void 0 : _17.$eq;
252
261
  if (typeof objectItemOfferedServiceOutputIdentifierEq === 'string') {
253
262
  andConditions.push({
254
263
  'object.itemOffered.serviceOutput.identifier': {
@@ -257,7 +266,7 @@ class MongoRepository {
257
266
  }
258
267
  });
259
268
  }
260
- const objectItemOfferedServiceOutputIdentifierIn = (_16 = (_15 = (_14 = (_13 = params.object) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.serviceOutput) === null || _15 === void 0 ? void 0 : _15.identifier) === null || _16 === void 0 ? void 0 : _16.$in;
269
+ const objectItemOfferedServiceOutputIdentifierIn = (_21 = (_20 = (_19 = (_18 = params.object) === null || _18 === void 0 ? void 0 : _18.itemOffered) === null || _19 === void 0 ? void 0 : _19.serviceOutput) === null || _20 === void 0 ? void 0 : _20.identifier) === null || _21 === void 0 ? void 0 : _21.$in;
261
270
  if (Array.isArray(objectItemOfferedServiceOutputIdentifierIn)) {
262
271
  andConditions.push({
263
272
  'object.itemOffered.serviceOutput.identifier': {
@@ -309,22 +318,23 @@ class MongoRepository {
309
318
  });
310
319
  }
311
320
  addReservations(params) {
321
+ var _a;
312
322
  return __awaiter(this, void 0, void 0, function* () {
313
323
  const doc = yield this.transactionModel.findOneAndUpdate({
314
324
  _id: { $eq: params.id },
315
325
  typeOf: { $eq: params.typeOf },
316
326
  status: { $eq: factory.transactionStatusType.InProgress }
317
- }, {
318
- 'object.acceptedOffer': params.object.acceptedOffer,
327
+ }, Object.assign({ 'object.acceptedOffer': params.object.acceptedOffer,
319
328
  // 念のため残す(2021/10/14)が、そのうち削除
320
329
  // 冗長なので削除(2021/10/19~)
321
330
  // 'object.event': params.object.reservationFor,
322
- 'object.reservationFor': params.object.reservationFor,
331
+ 'object.reservationFor': params.object.reservationFor,
323
332
  // 念のため残す(2021/10/14)が、そのうち削除
324
333
  // 冗長なので削除(2021/10/19~)
325
334
  // 'object.reservations': params.object.subReservation,
326
- 'object.subReservation': params.object.subReservation
327
- }, { new: true })
335
+ 'object.subReservation': params.object.subReservation }, (typeof ((_a = params.object.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string')
336
+ ? { 'object.issuedThrough': params.object.issuedThrough }
337
+ : undefined), { new: true })
328
338
  .exec();
329
339
  if (doc === null) {
330
340
  throw new factory.errors.NotFound(this.transactionModel.modelName);
@@ -117,6 +117,12 @@ schema.index({ 'object.subReservation.reservationFor.id': 1, startDate: -1 }, {
117
117
  'object.subReservation.reservationFor.id': { $exists: true }
118
118
  }
119
119
  });
120
+ schema.index({ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': 1, startDate: -1 }, {
121
+ name: 'searchByObjectSubReservationTicketedSeatSeatNumber',
122
+ partialFilterExpression: {
123
+ 'object.subReservation.reservedTicket.ticketedSeat.seatNumber': { $exists: true }
124
+ }
125
+ });
120
126
  schema.index({ 'object.reservationFor.id': 1, startDate: -1 }, {
121
127
  name: 'searchByObjectReservationForId',
122
128
  partialFilterExpression: {
@@ -61,12 +61,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
61
61
  project?: any;
62
62
  additionalProperty?: any;
63
63
  reservationFor?: any;
64
+ underName?: any;
65
+ issuedThrough?: any;
64
66
  subReservation?: any;
65
67
  broker?: any;
66
- underName?: any;
67
68
  price?: any;
68
69
  priceCurrency?: string | undefined;
69
- issuedThrough?: any;
70
70
  reservedTicket?: any;
71
71
  additionalTicketText?: string | undefined;
72
72
  bookingTime?: Date | undefined;
@@ -89,12 +89,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
89
89
  project?: any;
90
90
  additionalProperty?: any;
91
91
  reservationFor?: any;
92
+ underName?: any;
93
+ issuedThrough?: any;
92
94
  subReservation?: any;
93
95
  broker?: any;
94
- underName?: any;
95
96
  price?: any;
96
97
  priceCurrency?: string | undefined;
97
- issuedThrough?: any;
98
98
  reservedTicket?: any;
99
99
  additionalTicketText?: string | undefined;
100
100
  bookingTime?: Date | undefined;
@@ -117,12 +117,12 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
117
117
  project?: any;
118
118
  additionalProperty?: any;
119
119
  reservationFor?: any;
120
+ underName?: any;
121
+ issuedThrough?: any;
120
122
  subReservation?: any;
121
123
  broker?: any;
122
- underName?: any;
123
124
  price?: any;
124
125
  priceCurrency?: string | undefined;
125
- issuedThrough?: any;
126
126
  reservedTicket?: any;
127
127
  additionalTicketText?: string | undefined;
128
128
  bookingTime?: Date | undefined;
@@ -35,11 +35,15 @@ export declare class MongoRepository {
35
35
  reservationNumber: string;
36
36
  previousReservationStatus: factory.reservationStatusType;
37
37
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
38
+ broker?: factory.reservation.IBroker<factory.reservationType>;
39
+ issuedThrough?: factory.assetTransaction.reserve.IIssuedThrough;
38
40
  }): Promise<void>;
39
41
  confirmByIdIfNotExist(params: {
40
42
  reservation: factory.assetTransaction.reserve.IObjectSubReservation;
41
43
  reservationFor: factory.assetTransaction.reserve.IReservationFor;
42
44
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
45
+ broker?: factory.reservation.IBroker<factory.reservationType>;
46
+ issuedThrough?: factory.assetTransaction.reserve.IIssuedThrough;
43
47
  }): Promise<void>;
44
48
  /**
45
49
  * 予約取消
@@ -913,22 +913,24 @@ class MongoRepository {
913
913
  });
914
914
  }
915
915
  confirmByReservationNumber(params) {
916
+ var _a, _b;
916
917
  return __awaiter(this, void 0, void 0, function* () {
917
918
  const conditions = {
918
919
  reservationNumber: { $eq: String(params.reservationNumber) },
919
920
  reservationStatus: { $eq: params.previousReservationStatus }
920
921
  };
921
- const update = Object.assign({
922
+ const update = Object.assign(Object.assign(Object.assign({
922
923
  // previousReservationStatusを保管(2023-01-19~)
923
- previousReservationStatus: params.previousReservationStatus, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined);
924
+ previousReservationStatus: params.previousReservationStatus, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }, (params.underName !== undefined) ? { underName: params.underName } : undefined), (typeof ((_a = params.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.broker } : undefined), (typeof ((_b = params.issuedThrough) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { issuedThrough: params.issuedThrough } : undefined);
924
925
  yield this.reservationModel.updateMany(conditions, update)
925
926
  .exec();
926
927
  });
927
928
  }
928
929
  confirmByIdIfNotExist(params) {
930
+ var _a, _b;
929
931
  return __awaiter(this, void 0, void 0, function* () {
930
932
  const confirmedReservation = yield this.reservationModel.findOneAndUpdate({ _id: { $eq: params.reservation.id } }, {
931
- $setOnInsert: Object.assign(Object.assign(Object.assign({}, params.reservation), { _id: params.reservation.id, reservationFor: params.reservationFor, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }), (params.underName !== undefined) ? { underName: params.underName } : undefined)
933
+ $setOnInsert: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, params.reservation), { _id: params.reservation.id, reservationFor: params.reservationFor, reservationStatus: factory.reservationStatusType.ReservationConfirmed, modifiedTime: new Date() }), (params.underName !== undefined) ? { underName: params.underName } : undefined), (typeof ((_a = params.broker) === null || _a === void 0 ? void 0 : _a.typeOf) === 'string') ? { broker: params.broker } : undefined), (typeof ((_b = params.issuedThrough) === null || _b === void 0 ? void 0 : _b.typeOf) === 'string') ? { issuedThrough: params.issuedThrough } : undefined)
932
934
  }, { upsert: true, new: true })
933
935
  .select({ _id: 1 })
934
936
  .exec();
@@ -47,6 +47,11 @@ export declare function createAdditionalTicketText(params: {
47
47
  }): string | undefined;
48
48
  export type IUnitPriceSpecification = factory.priceSpecification.IPriceSpecification<factory.priceSpecificationType.UnitPriceSpecification>;
49
49
  export declare function createReservationFor(params: factory.event.screeningEvent.IEvent | factory.event.event.IEvent): factory.assetTransaction.reserve.IReservationFor;
50
+ export declare function createIssuedThrough(params: {
51
+ reservationFor: factory.event.screeningEvent.IEvent | factory.event.event.IEvent;
52
+ }): {
53
+ issuedThrough: factory.reservation.busReservation.IIssuedThrough | factory.reservation.eventReservation.IIssuedThrough;
54
+ };
50
55
  export declare function createReservation(params: {
51
56
  project: {
52
57
  id: string;
@@ -78,6 +83,6 @@ export declare function createPotentialActions(params: factory.assetTransaction.
78
83
  reservationPackage?: factory.action.reserve.IReservationPackageAsObject;
79
84
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
80
85
  };
81
- export declare function createPendingReservationAction(params: {
86
+ export declare function createCancelPendingReservationAction(params: {
82
87
  transaction: factory.assetTransaction.ITransaction<factory.assetTransactionType.Reserve>;
83
- }): factory.action.cancel.reservation.IAttributes[];
88
+ }): factory.action.cancel.reservation.IAttributes | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createPendingReservationAction = exports.createPotentialActions = exports.createReservation = exports.createReservationFor = exports.createAdditionalTicketText = exports.createAdditionalProperty = exports.validateAppliesToMovieTicket = exports.createReservedTicket = exports.createPointAward = exports.createStartParams = void 0;
3
+ exports.createCancelPendingReservationAction = exports.createPotentialActions = exports.createReservation = exports.createIssuedThrough = exports.createReservationFor = exports.createAdditionalTicketText = exports.createAdditionalProperty = exports.validateAppliesToMovieTicket = exports.createReservedTicket = exports.createPointAward = exports.createStartParams = void 0;
4
4
  /**
5
5
  * 予約取引ファクトリー
6
6
  */
@@ -356,6 +356,42 @@ function optimizeReservationSuperEvent(params) {
356
356
  ? { headline: superEvent.headline }
357
357
  : undefined);
358
358
  }
359
+ function createIssuedThrough(params) {
360
+ var _a;
361
+ const eventOffers = params.reservationFor.offers;
362
+ // offersは必ず存在するはず
363
+ if (eventOffers === undefined) {
364
+ throw new factory.errors.NotFound('reservationFor.offers');
365
+ }
366
+ const serviceTypeOfIssuedThrough = (typeof ((_a = eventOffers.itemOffered.serviceType) === null || _a === void 0 ? void 0 : _a.codeValue) === 'string')
367
+ ? {
368
+ codeValue: eventOffers.itemOffered.serviceType.codeValue,
369
+ inCodeSet: {
370
+ typeOf: 'CategoryCodeSet',
371
+ identifier: factory.categoryCode.CategorySetIdentifier.ServiceType
372
+ },
373
+ typeOf: 'CategoryCode'
374
+ }
375
+ : undefined;
376
+ const availableChannel = eventOffers.itemOffered.availableChannel;
377
+ if (params.reservationFor.typeOf === factory.eventType.ScreeningEvent) {
378
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.EventService,
379
+ // 興行IDを追加(2022-09-08~)
380
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
381
+ return {
382
+ issuedThrough
383
+ };
384
+ }
385
+ else {
386
+ const issuedThrough = Object.assign({ typeOf: factory.product.ProductType.Transportation,
387
+ // 興行IDを追加(2022-09-08~)
388
+ id: eventOffers.itemOffered.id, availableChannel }, (typeof (serviceTypeOfIssuedThrough === null || serviceTypeOfIssuedThrough === void 0 ? void 0 : serviceTypeOfIssuedThrough.typeOf) === 'string') ? { serviceType: serviceTypeOfIssuedThrough } : undefined);
389
+ return {
390
+ issuedThrough
391
+ };
392
+ }
393
+ }
394
+ exports.createIssuedThrough = createIssuedThrough;
359
395
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
360
396
  function createReservation(params) {
361
397
  var _a, _b, _c, _d, _e;
@@ -561,10 +597,10 @@ function createMoneyTransferActions(params) {
561
597
  }
562
598
  return moneyTransfer;
563
599
  }
564
- function createPendingReservationAction(params) {
600
+ function createCancelPendingReservationAction(params) {
565
601
  const transaction = params.transaction;
566
602
  const pendingReservations = (Array.isArray(transaction.object.subReservation)) ? transaction.object.subReservation : [];
567
- let cancelActionAttributes = [];
603
+ let cancelActionAttributes;
568
604
  if (pendingReservations.length > 0) {
569
605
  const reservationFor = transaction.object.reservationFor;
570
606
  if (reservationFor === undefined) {
@@ -579,15 +615,15 @@ function createPendingReservationAction(params) {
579
615
  ? params.transaction.object.reservationStatus
580
616
  : factory.reservationStatusType.ReservationPending
581
617
  };
582
- cancelActionAttributes = [{
583
- project: transaction.project,
584
- typeOf: factory.actionType.CancelAction,
585
- purpose: { typeOf: transaction.typeOf, id: transaction.id },
586
- agent: transaction.project,
587
- object: reservationPackage,
588
- potentialActions: {}
589
- }];
618
+ cancelActionAttributes = {
619
+ project: transaction.project,
620
+ typeOf: factory.actionType.CancelAction,
621
+ purpose: { typeOf: transaction.typeOf, id: transaction.id },
622
+ agent: transaction.project,
623
+ object: reservationPackage,
624
+ potentialActions: {}
625
+ };
590
626
  }
591
627
  return cancelActionAttributes;
592
628
  }
593
- exports.createPendingReservationAction = createPendingReservationAction;
629
+ exports.createCancelPendingReservationAction = createCancelPendingReservationAction;
@@ -136,6 +136,7 @@ function addReservations(params) {
136
136
  })(repos);
137
137
  // 予約イベント最適化
138
138
  const reservationFor = (0, factory_1.createReservationFor)(event);
139
+ const { issuedThrough } = (0, factory_1.createIssuedThrough)({ reservationFor: event });
139
140
  // const minimizedObjectSubReservations: factory.assetTransaction.reserve.IMinimizedObjectSubReservation[] =
140
141
  // objectSubReservations.map((r) => {
141
142
  // return {
@@ -159,6 +160,8 @@ function addReservations(params) {
159
160
  id: transaction.id,
160
161
  object: {
161
162
  acceptedOffer: acceptedOffers4transactionObject,
163
+ // issuedThroughを追加(2023-06-05~)
164
+ issuedThrough,
162
165
  reservationFor,
163
166
  // subReservationにreservationForを保管しない(2021-10-19~)
164
167
  subReservation: objectSubReservations
@@ -786,8 +789,8 @@ function cancel(params) {
786
789
  });
787
790
  // 本来非同期でタスクが実行されるが、同期的に仮予約取消が実行されていないと、サービス利用側が困る可能性があるので、
788
791
  // 同期的にもcancelPendingReservationを実行しておく
789
- const cancelActionAttributes = (0, factory_1.createPendingReservationAction)({ transaction });
790
- if (cancelActionAttributes.length > 0) {
792
+ const cancelActionAttributes = (0, factory_1.createCancelPendingReservationAction)({ transaction });
793
+ if (cancelActionAttributes !== undefined) {
791
794
  yield (0, cancelReservation_1.cancelPendingReservation)(cancelActionAttributes)(repos);
792
795
  }
793
796
  });
@@ -832,8 +835,8 @@ function exportTasksById(params) {
832
835
  case factory.transactionStatusType.Canceled:
833
836
  // sync対応(2023-01-13~)
834
837
  if (!settings_1.USE_ASSET_TRANSACTION_SYNC_PROCESSING) {
835
- const cancelActionAttributes4canceled = (0, factory_1.createPendingReservationAction)({ transaction });
836
- if (cancelActionAttributes4canceled.length > 0) {
838
+ const cancelActionAttributes4canceled = (0, factory_1.createCancelPendingReservationAction)({ transaction });
839
+ if (cancelActionAttributes4canceled !== undefined) {
837
840
  const cancelPendingReservationTask = {
838
841
  project: transaction.project,
839
842
  name: factory.taskName.CancelPendingReservation,
@@ -843,7 +846,7 @@ function exportTasksById(params) {
843
846
  numberOfTried: 0,
844
847
  executionResults: [],
845
848
  data: {
846
- actionAttributes: cancelActionAttributes4canceled
849
+ actionAttributes: [cancelActionAttributes4canceled]
847
850
  }
848
851
  };
849
852
  taskAttributes.push(cancelPendingReservationTask);
@@ -851,8 +854,8 @@ function exportTasksById(params) {
851
854
  }
852
855
  break;
853
856
  case factory.transactionStatusType.Expired:
854
- const cancelActionAttributes = (0, factory_1.createPendingReservationAction)({ transaction });
855
- if (cancelActionAttributes.length > 0) {
857
+ const cancelActionAttributes = (0, factory_1.createCancelPendingReservationAction)({ transaction });
858
+ if (cancelActionAttributes !== undefined) {
856
859
  const cancelPendingReservationTask = {
857
860
  project: transaction.project,
858
861
  name: factory.taskName.CancelPendingReservation,
@@ -862,7 +865,7 @@ function exportTasksById(params) {
862
865
  numberOfTried: 0,
863
866
  executionResults: [],
864
867
  data: {
865
- actionAttributes: cancelActionAttributes
868
+ actionAttributes: [cancelActionAttributes]
866
869
  }
867
870
  };
868
871
  taskAttributes.push(cancelPendingReservationTask);
@@ -8,7 +8,7 @@ import { MongoRepository as TaskRepo } from '../../repo/task';
8
8
  /**
9
9
  * 進行中の予約をキャンセルする
10
10
  */
11
- declare function cancelPendingReservation(actionAttributesList: factory.action.cancel.reservation.IAttributes[]): (repos: {
11
+ declare function cancelPendingReservation(actionAttributes: factory.action.cancel.reservation.IAttributes): (repos: {
12
12
  action: ActionRepo;
13
13
  assetTransaction: AssetTransactionRepo;
14
14
  stockHolder: StockHolderRepo;
@@ -19,65 +19,112 @@ const onReservationCanceled_1 = require("./potentialActions/onReservationCancele
19
19
  /**
20
20
  * 進行中の予約をキャンセルする
21
21
  */
22
- // tslint:disable-next-line:max-func-body-length
23
- function cancelPendingReservation(actionAttributesList) {
24
- // tslint:disable-next-line:max-func-body-length
22
+ function cancelPendingReservation(actionAttributes) {
25
23
  return (repos) => __awaiter(this, void 0, void 0, function* () {
24
+ var _a;
26
25
  const now = new Date();
27
26
  let canceledReservations = [];
28
- if (actionAttributesList.length > 0) {
29
- // tslint:disable-next-line:max-func-body-length
30
- yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
31
- const reserveTransactionId = actionAttributes.purpose.id;
32
- // アクション開始
33
- const action = yield repos.action.start(actionAttributes);
34
- const actionObject = actionAttributes.object;
35
- let cancelResult;
36
- try {
37
- // 予約取引を検索
38
- const reserveTransactions = yield repos.assetTransaction.search({
39
- limit: 1,
40
- page: 1,
41
- typeOf: factory.assetTransactionType.Reserve,
42
- ids: [reserveTransactionId]
43
- });
44
- const reserveTransaction = reserveTransactions.shift();
45
- if (reserveTransaction !== undefined) {
46
- const reservationFor = reserveTransaction.object.reservationFor;
47
- if (reservationFor === undefined) {
48
- throw new factory.errors.NotFound('transaction.object.reservationFor');
27
+ const { reserveTransaction } = yield cancelPengindIfNotYet(actionAttributes, now)(repos);
28
+ if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
29
+ if (reserveTransaction.object.disablePendingReservations === true) {
30
+ // Pendingが存在しない場合は検索しても無駄(2023-06-05~)
31
+ }
32
+ else {
33
+ canceledReservations = yield repos.reservation.search({
34
+ reservationNumber: { $eq: actionAttributes.object.reservationNumber },
35
+ typeOf: factory.reservationType.EventReservation
36
+ });
37
+ canceledReservations = canceledReservations.map((r) => {
38
+ // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
39
+ delete r._id;
40
+ return r;
41
+ });
42
+ }
43
+ }
44
+ yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, false, {
45
+ project: { id: reserveTransaction.project.id },
46
+ id: String((_a = reserveTransaction.object.reservationFor) === null || _a === void 0 ? void 0 : _a.id)
47
+ })({ task: repos.task });
48
+ });
49
+ }
50
+ exports.cancelPendingReservation = cancelPendingReservation;
51
+ function cancelPengindIfNotYet(params, now) {
52
+ // tslint:disable-next-line:max-func-body-length
53
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
54
+ const actionAttributes = params;
55
+ const reserveTransactionId = actionAttributes.purpose.id;
56
+ // 予約取引を検索
57
+ const reserveTransactions = yield repos.assetTransaction.search({
58
+ limit: 1,
59
+ page: 1,
60
+ typeOf: factory.assetTransactionType.Reserve,
61
+ ids: [reserveTransactionId]
62
+ });
63
+ const reserveTransaction = reserveTransactions.shift();
64
+ if (reserveTransaction === undefined) {
65
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
66
+ }
67
+ // 冪等性を担保(2023-06-05~)
68
+ const completedActions = yield repos.action.search({
69
+ limit: 1,
70
+ page: 1,
71
+ actionStatus: { $in: [factory.actionStatusType.CompletedActionStatus] },
72
+ typeOf: { $eq: params.typeOf },
73
+ object: {
74
+ typeOf: { $eq: params.object.typeOf },
75
+ reservationNumber: { $eq: params.object.reservationNumber }
76
+ },
77
+ purpose: {
78
+ id: { $in: [params.purpose.id] },
79
+ typeOf: { $in: [params.purpose.typeOf] }
80
+ }
81
+ }, ['_id'], []);
82
+ if (completedActions.length === 0) {
83
+ // アクション開始
84
+ const action = yield repos.action.start(actionAttributes);
85
+ const actionObject = actionAttributes.object;
86
+ let cancelResult;
87
+ try {
88
+ if (reserveTransaction !== undefined) {
89
+ const reservationFor = reserveTransaction.object.reservationFor;
90
+ if (reservationFor === undefined) {
91
+ throw new factory.errors.NotFound('transaction.object.reservationFor');
92
+ }
93
+ // ReservationPackageに対応(2022-12-23~)
94
+ if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
95
+ const subReservation = reserveTransaction.object.subReservation;
96
+ if (Array.isArray(subReservation) && subReservation.length > 0) {
97
+ yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
98
+ yield processUnlockSeat({
99
+ reservation: {
100
+ id: cancelingSubReservation.id,
101
+ reservedTicket: cancelingSubReservation.reservedTicket,
102
+ subReservation: cancelingSubReservation.subReservation,
103
+ reservationFor: {
104
+ id: String(reservationFor.id),
105
+ startDate: (reservationFor.typeOf === factory.eventType.ScreeningEvent)
106
+ ? reservationFor.startDate
107
+ : reservationFor.departureTime
108
+ }
109
+ },
110
+ // holder:取引番号に対応(2023-06-05~)
111
+ expectedHolder: (reserveTransaction.object.useHoldStockByTransactionNumber === true)
112
+ ? reserveTransaction.transactionNumber
113
+ : reserveTransactionId
114
+ })(repos);
115
+ yield processUnlockOfferRateLimit({
116
+ reservation: {
117
+ reservationNumber: reserveTransaction.object.reservationNumber,
118
+ reservedTicket: cancelingSubReservation.reservedTicket
119
+ },
120
+ reservationFor
121
+ })(repos);
122
+ })));
123
+ }
124
+ if (reserveTransaction.object.disablePendingReservations === true) {
125
+ // disablePendingReservationsの場合は処理不要(2023-06-05~)
49
126
  }
50
- // ReservationPackageに対応(2022-12-23~)
51
- if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
52
- const subReservation = reserveTransaction.object.subReservation;
53
- if (Array.isArray(subReservation) && subReservation.length > 0) {
54
- yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
55
- yield processUnlockSeat({
56
- reservation: {
57
- id: cancelingSubReservation.id,
58
- reservedTicket: cancelingSubReservation.reservedTicket,
59
- subReservation: cancelingSubReservation.subReservation,
60
- reservationFor: {
61
- id: String(reservationFor.id),
62
- startDate: (reservationFor.typeOf === factory.eventType.ScreeningEvent)
63
- ? reservationFor.startDate
64
- : reservationFor.departureTime
65
- }
66
- },
67
- // holder:取引番号に対応(2023-06-05~)
68
- expectedHolder: (reserveTransaction.object.useHoldStockByTransactionNumber === true)
69
- ? reserveTransaction.transactionNumber
70
- : reserveTransactionId
71
- })(repos);
72
- yield processUnlockOfferRateLimit({
73
- reservation: {
74
- reservationNumber: reserveTransaction.object.reservationNumber,
75
- reservedTicket: cancelingSubReservation.reservedTicket
76
- },
77
- reservationFor
78
- })(repos);
79
- })));
80
- }
127
+ else {
81
128
  // 予約番号単位でキャンセル状態に変更する
82
129
  cancelResult = yield repos.reservation.cancelByReservationNumber({
83
130
  reservationNumber: actionObject.reservationNumber,
@@ -85,54 +132,41 @@ function cancelPendingReservation(actionAttributesList) {
85
132
  modifiedTime: now
86
133
  });
87
134
  }
88
- else {
89
- // 廃止(2022-12-27~)
90
- throw new factory.errors.NotImplemented(`object.typeOf '${actionObject.typeOf}' not implemented`);
91
- }
92
135
  }
93
- }
94
- catch (error) {
95
- // actionにエラー結果を追加
96
- try {
97
- const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
98
- yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
99
- }
100
- catch (__) {
101
- // 失敗したら仕方ない
136
+ else {
137
+ // 廃止(2022-12-27~)
138
+ throw new factory.errors.NotImplemented(`object.typeOf '${actionObject.typeOf}' not implemented`);
102
139
  }
103
- throw error;
104
140
  }
105
- // アクション完了
106
- const actionResult = Object.assign({}, (cancelResult !== undefined) ? {
107
- cancelResult: {
108
- // n: cancelResult.n,
109
- // nModified: cancelResult.nModified,
110
- // ok: cancelResult.ok,
111
- matchedCount: cancelResult.matchedCount,
112
- modifiedCount: cancelResult.modifiedCount
113
- }
114
- } : undefined
115
- // canceledReservationId: canceledReservation?.id
116
- );
117
- yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
118
- if (actionObject.typeOf === factory.reservationType.ReservationPackage) {
119
- // 最新のconfirmedReservationsを検索
120
- canceledReservations = yield repos.reservation.search({
121
- reservationNumber: { $eq: actionObject.reservationNumber },
122
- typeOf: factory.reservationType.EventReservation
123
- });
124
- canceledReservations = canceledReservations.map((r) => {
125
- // _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
126
- delete r._id;
127
- return r;
128
- });
141
+ }
142
+ catch (error) {
143
+ // actionにエラー結果を追加
144
+ try {
145
+ const actionError = Object.assign(Object.assign({}, error), { message: error.message, name: error.name });
146
+ yield repos.action.giveUp({ typeOf: action.typeOf, id: action.id, error: actionError });
129
147
  }
130
- yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, false)({ task: repos.task });
131
- })));
148
+ catch (__) {
149
+ // 失敗したら仕方ない
150
+ }
151
+ throw error;
152
+ }
153
+ // アクション完了
154
+ const actionResult = Object.assign({}, (cancelResult !== undefined) ? {
155
+ cancelResult: {
156
+ // n: cancelResult.n,
157
+ // nModified: cancelResult.nModified,
158
+ // ok: cancelResult.ok,
159
+ matchedCount: cancelResult.matchedCount,
160
+ modifiedCount: cancelResult.modifiedCount
161
+ }
162
+ } : undefined
163
+ // canceledReservationId: canceledReservation?.id
164
+ );
165
+ yield repos.action.complete({ typeOf: action.typeOf, id: action.id, result: actionResult });
132
166
  }
167
+ return { reserveTransaction };
133
168
  });
134
169
  }
135
- exports.cancelPendingReservation = cancelPendingReservation;
136
170
  /**
137
171
  * 予約をキャンセルする
138
172
  */
@@ -145,6 +179,7 @@ function cancelReservation(actionAttributesList) {
145
179
  yield Promise.all(actionAttributesList.map((actionAttributes) => __awaiter(this, void 0, void 0, function* () {
146
180
  const action = yield repos.action.start(actionAttributes);
147
181
  let cancelResult;
182
+ let canceledReservationForId;
148
183
  try {
149
184
  if (actionAttributes.object.typeOf === factory.reservationType.ReservationPackage) {
150
185
  // 予約取引を検索
@@ -156,12 +191,13 @@ function cancelReservation(actionAttributesList) {
156
191
  });
157
192
  const reserveTransaction = reserveTransactions.shift();
158
193
  if (reserveTransaction === undefined) {
159
- throw new factory.errors.NotFound('ReserveTransaction');
194
+ throw new factory.errors.NotFound(factory.assetTransactionType.Reserve);
160
195
  }
161
196
  const reservationFor = reserveTransaction.object.reservationFor;
162
197
  if (reservationFor === undefined) {
163
198
  throw new factory.errors.NotFound('transaction.object.reservationFor');
164
199
  }
200
+ canceledReservationForId = String(reservationFor.id);
165
201
  const subReservation = reserveTransaction.object.subReservation;
166
202
  if (Array.isArray(subReservation) && subReservation.length > 0) {
167
203
  yield Promise.all(subReservation.map((cancelingSubReservation) => __awaiter(this, void 0, void 0, function* () {
@@ -210,6 +246,7 @@ function cancelReservation(actionAttributesList) {
210
246
  object: { reservations: { id: { $in: [reservation.id] } } }
211
247
  });
212
248
  const reserveTransaction = reserveTransactions.shift();
249
+ canceledReservationForId = reservation.reservationFor.id;
213
250
  // holder:取引番号に対応(2023-06-05~)
214
251
  const expectedHolder = ((reserveTransaction === null || reserveTransaction === void 0 ? void 0 : reserveTransaction.object.useHoldStockByTransactionNumber) === true)
215
252
  ? reserveTransaction.transactionNumber
@@ -288,7 +325,10 @@ function cancelReservation(actionAttributesList) {
288
325
  });
289
326
  canceledReservations = [canceledReservation];
290
327
  }
291
- yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, true)({ task: repos.task });
328
+ yield (0, onReservationCanceled_1.onReservationCanceled)(canceledReservations, true, {
329
+ project: { id: actionAttributes.project.id },
330
+ id: canceledReservationForId
331
+ })({ task: repos.task });
292
332
  })));
293
333
  }
294
334
  });
@@ -103,7 +103,9 @@ function reserveIfNotYet(params, options) {
103
103
  yield repos.reservation.confirmByIdIfNotExist({
104
104
  reservation: subReservation,
105
105
  reservationFor,
106
- underName
106
+ underName,
107
+ broker: reserveTransaction.object.broker,
108
+ issuedThrough: reserveTransaction.object.issuedThrough
107
109
  });
108
110
  })));
109
111
  }
@@ -113,7 +115,9 @@ function reserveIfNotYet(params, options) {
113
115
  yield repos.reservation.confirmByReservationNumber({
114
116
  reservationNumber: reservationPackage.reservationNumber,
115
117
  previousReservationStatus: reservationPackage.reservationStatus,
116
- underName
118
+ underName,
119
+ broker: reserveTransaction.object.broker,
120
+ issuedThrough: reserveTransaction.object.issuedThrough
117
121
  });
118
122
  }
119
123
  }
@@ -25,7 +25,7 @@ export interface IReservationPackage4informConfirmed {
25
25
  * 予約取消通知
26
26
  */
27
27
  export interface IReservation4informCanceled {
28
- typeOf: factory.reservationType.EventReservation;
28
+ typeOf: factory.reservationType.BusReservation | factory.reservationType.EventReservation;
29
29
  project: IProject;
30
30
  id: string;
31
31
  reservationStatus: factory.reservationStatusType.ReservationCancelled;
@@ -1,10 +1,25 @@
1
1
  import * as factory from '../../../factory';
2
2
  import { MongoRepository as TaskRepo } from '../../../repo/task';
3
3
  type IEventReservation = factory.reservation.IReservation<factory.reservationType.EventReservation>;
4
+ type IBusReservation = factory.reservation.IReservation<factory.reservationType.BusReservation>;
5
+ export declare function onReservationCanceled(
4
6
  /**
5
- * 予約取消後のアクション
7
+ * ステータス変更された予約リスト
6
8
  */
7
- export declare function onReservationCanceled(canceledReservations: IEventReservation[], useInformReservation: boolean): (repos: {
9
+ canceledReservations: IEventReservation[] | IBusReservation[],
10
+ /**
11
+ * 予約通知有無
12
+ */
13
+ useInformReservation: boolean,
14
+ /**
15
+ * 集計対象イベント
16
+ */
17
+ reservationFor: {
18
+ project: {
19
+ id: string;
20
+ };
21
+ id: string;
22
+ }): (repos: {
8
23
  task: TaskRepo;
9
24
  }) => Promise<void>;
10
25
  export {};
@@ -19,27 +19,19 @@ const settings_1 = require("../../../settings");
19
19
  const offer_1 = require("../../offer");
20
20
  const factory_1 = require("../factory");
21
21
  const informReservations = settings_1.settings.onReservationStatusChanged.informReservation;
22
+ function onReservationCanceled(
22
23
  /**
23
- * 予約取消後のアクション
24
+ * ステータス変更された予約リスト
24
25
  */
25
- // export function onReservationCanceledByAction(
26
- // actionAttributes: factory.action.cancel.reservation.IAttributes
27
- // ) {
28
- // return async (repos: {
29
- // task: TaskRepo;
30
- // }) => {
31
- // const potentialActions = actionAttributes.potentialActions;
32
- // const taskAttributes: factory.task.IAttributes<factory.taskName>[] = [];
33
- // if (potentialActions !== undefined) {
34
- // // no op
35
- // }
36
- // // タスク保管
37
- // if (taskAttributes.length > 0) {
38
- // await repos.task.saveMany(taskAttributes, { emitImmediately: true });
39
- // }
40
- // };
41
- // }
42
- function onReservationCanceled(canceledReservations, useInformReservation) {
26
+ canceledReservations,
27
+ /**
28
+ * 予約通知有無
29
+ */
30
+ useInformReservation,
31
+ /**
32
+ * 集計対象イベント
33
+ */
34
+ reservationFor) {
43
35
  return (repos) => __awaiter(this, void 0, void 0, function* () {
44
36
  if (Array.isArray(canceledReservations) && canceledReservations.length > 0) {
45
37
  const now = new Date();
@@ -93,10 +85,20 @@ function onReservationCanceled(canceledReservations, useInformReservation) {
93
85
  if (taskAttributes.length > 0) {
94
86
  yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
95
87
  }
88
+ // const reservationForId = canceledReservations[0].reservationFor.id;
89
+ // if (typeof reservationForId === 'string') {
90
+ // await createAggregateScreeningEventIfNotExist({
91
+ // project,
92
+ // reservationFor: [{ id: reservationForId }],
93
+ // force: false
94
+ // })({ task: repos.task });
95
+ // }
96
+ }
97
+ if (typeof (reservationFor === null || reservationFor === void 0 ? void 0 : reservationFor.id) === 'string') {
96
98
  // 冗長な作成を避ける
97
99
  yield (0, offer_1.createAggregateScreeningEventIfNotExist)({
98
- project,
99
- reservationFor: [{ id: canceledReservations[0].reservationFor.id }],
100
+ project: { id: reservationFor.project.id },
101
+ reservationFor: [{ id: reservationFor.id }],
100
102
  force: false
101
103
  })({ task: repos.task });
102
104
  }
@@ -32,7 +32,11 @@ function call(data) {
32
32
  const reservationRepo = new reservation_1.MongoRepository(settings.connection);
33
33
  const stockHolderRepo = new stockHolder_1.StockHolderRepository(settings.redisClient);
34
34
  const offerRateLimitRepo = new offer_1.RedisRepository(settings.redisClient);
35
- yield ReserveService.cancelPendingReservation(data.actionAttributes)({
35
+ // アクション数は予約番号単位で1しかありえないはず(2023-06-05~)
36
+ if (data.actionAttributes.length !== 1) {
37
+ throw new factory.errors.Argument('data.actionAttributes', 'data.actionAttributes.length must be 1');
38
+ }
39
+ yield ReserveService.cancelPendingReservation(data.actionAttributes[0])({
36
40
  action: actionRepo,
37
41
  assetTransaction: assetTransactionRepo,
38
42
  stockHolder: stockHolderRepo,
package/package.json CHANGED
@@ -9,8 +9,8 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.313.0-alpha.24",
13
- "@cinerino/sdk": "3.157.0-alpha.6",
12
+ "@chevre/factory": "4.313.0-alpha.26",
13
+ "@cinerino/sdk": "3.157.0-alpha.7",
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.95"
120
+ "version": "21.2.0-alpha.97"
121
121
  }
@@ -1,26 +0,0 @@
1
- // tslint:disable:no-implicit-dependencies no-console
2
- import { chevre } from '../../../lib/index';
3
-
4
- import * as mongoose from 'mongoose';
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 actionRepo = new chevre.repository.Action(mongoose.connection);
12
- const actions = await actionRepo.search(
13
- {
14
- object: { reservationNumber: { $eq: 'xxx' } }
15
- },
16
- ['_id'],
17
- []
18
- );
19
- console.log('actions:', actions);
20
- }
21
-
22
- main()
23
- .then(() => {
24
- console.log('success!');
25
- })
26
- .catch(console.error);