@chevre/domain 21.2.0-alpha.122 → 21.2.0-alpha.124

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.
@@ -122,6 +122,8 @@ export declare class StockHolderRepository {
122
122
  * 汎用的な検索(mongooseのみ対応)
123
123
  */
124
124
  search(params: {
125
+ limit?: number;
126
+ page?: number;
125
127
  project?: {
126
128
  id?: {
127
129
  $eq?: string;
@@ -138,6 +140,9 @@ export declare class StockHolderRepository {
138
140
  id?: {
139
141
  $eq?: string;
140
142
  };
143
+ identifier?: {
144
+ $eq?: string;
145
+ };
141
146
  reservedTicket?: {
142
147
  ticketedSeat?: {
143
148
  seatNumber?: {
@@ -150,5 +155,6 @@ export declare class StockHolderRepository {
150
155
  };
151
156
  }): Promise<ISearchSubReservationResult[]>;
152
157
  private checkIfConflicted;
158
+ private checkIfConflictedBetweenRedisAndMongo;
153
159
  private initializeHoldReservation;
154
160
  }
@@ -86,6 +86,7 @@ class StockHolderRepository {
86
86
  lockIfNotLimitExceeded(lockKey, maximum) {
87
87
  return __awaiter(this, void 0, void 0, function* () {
88
88
  if (StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate })) {
89
+ yield this.checkIfConflictedBetweenRedisAndMongo({ key: '', eventId: lockKey.eventId });
89
90
  // reservationCount<=nであれば$push+$incする
90
91
  yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
91
92
  const addedReservationCount = lockKey.offers.length;
@@ -135,6 +136,7 @@ class StockHolderRepository {
135
136
  lock(lockKey) {
136
137
  return __awaiter(this, void 0, void 0, function* () {
137
138
  if (StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate })) {
139
+ yield this.checkIfConflictedBetweenRedisAndMongo({ key: '', eventId: lockKey.eventId });
138
140
  yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
139
141
  const addedReservationCount = lockKey.offers.length;
140
142
  const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
@@ -214,6 +216,7 @@ class StockHolderRepository {
214
216
  unlock(params) {
215
217
  return __awaiter(this, void 0, void 0, function* () {
216
218
  if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
219
+ yield this.checkIfConflictedBetweenRedisAndMongo({ key: '', eventId: params.eventId });
217
220
  // [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
218
221
  yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
219
222
  const subReservation = StockHolderRepository.offer2subReservation(params.offer);
@@ -451,13 +454,9 @@ class StockHolderRepository {
451
454
  * 汎用的な検索(mongooseのみ対応)
452
455
  */
453
456
  search(params) {
454
- var _a, _b, _c, _d, _e;
457
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
455
458
  return __awaiter(this, void 0, void 0, function* () {
456
- const matchStages = [
457
- // {
458
- // $match: { 'reservations.subReservation.identifier': { $in: subReservations.map((r) => r.identifier) } }
459
- // }
460
- ];
459
+ const matchStages = [];
461
460
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
462
461
  if (typeof projectIdEq === 'string') {
463
462
  matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
@@ -470,6 +469,43 @@ class StockHolderRepository {
470
469
  if (typeof reservationNumberEq === 'string') {
471
470
  matchStages.push({ $match: { 'reservations.reservationNumber': { $eq: reservationNumberEq } } });
472
471
  }
472
+ const identifierEq = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$eq;
473
+ if (typeof identifierEq === 'string') {
474
+ matchStages.push({ $match: { 'reservations.subReservation.identifier': { $eq: identifierEq } } });
475
+ }
476
+ const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
477
+ if (typeof idEq === 'string') {
478
+ matchStages.push({
479
+ $match: {
480
+ 'reservations.subReservation.id': {
481
+ $exists: true,
482
+ $eq: idEq
483
+ }
484
+ }
485
+ });
486
+ }
487
+ const seatNumberEq = (_k = (_j = (_h = params.reservedTicket) === null || _h === void 0 ? void 0 : _h.ticketedSeat) === null || _j === void 0 ? void 0 : _j.seatNumber) === null || _k === void 0 ? void 0 : _k.$eq;
488
+ if (typeof seatNumberEq === 'string') {
489
+ matchStages.push({
490
+ $match: {
491
+ 'reservations.subReservation.reservedTicket.ticketedSeat.seatNumber': {
492
+ $exists: true,
493
+ $eq: seatNumberEq
494
+ }
495
+ }
496
+ });
497
+ }
498
+ const seatSectionEq = (_o = (_m = (_l = params.reservedTicket) === null || _l === void 0 ? void 0 : _l.ticketedSeat) === null || _m === void 0 ? void 0 : _m.seatSection) === null || _o === void 0 ? void 0 : _o.$eq;
499
+ if (typeof seatSectionEq === 'string') {
500
+ matchStages.push({
501
+ $match: {
502
+ 'reservations.subReservation.reservedTicket.ticketedSeat.seatSection': {
503
+ $exists: true,
504
+ $eq: seatSectionEq
505
+ }
506
+ }
507
+ });
508
+ }
473
509
  const aggregate = this.holdReservationModel.aggregate([
474
510
  { $unwind: '$reservations' },
475
511
  { $unwind: '$reservations.subReservation' },
@@ -485,7 +521,13 @@ class StockHolderRepository {
485
521
  }
486
522
  }
487
523
  ]);
488
- return aggregate.exec();
524
+ if (typeof params.limit === 'number' && params.limit > 0) {
525
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
526
+ aggregate.limit(params.limit * page)
527
+ .skip(params.limit * (page - 1));
528
+ }
529
+ return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
530
+ .exec();
489
531
  });
490
532
  }
491
533
  checkIfConflicted(params) {
@@ -511,6 +553,13 @@ class StockHolderRepository {
511
553
  }
512
554
  });
513
555
  }
556
+ // tslint:disable-next-line:prefer-function-over-method
557
+ checkIfConflictedBetweenRedisAndMongo(__) {
558
+ return __awaiter(this, void 0, void 0, function* () {
559
+ // tslint:disable-next-line:no-suspicious-comment
560
+ // TODO implement
561
+ });
562
+ }
514
563
  initializeHoldReservation(params) {
515
564
  return __awaiter(this, void 0, void 0, function* () {
516
565
  if (!(params.startDate instanceof Date)) {
package/package.json CHANGED
@@ -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.122"
120
+ "version": "21.2.0-alpha.124"
121
121
  }