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

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.
@@ -19,18 +19,18 @@ async function main() {
19
19
  const stockHolderRepo = new chevre.repository.StockHolder(client, mongoose.connection);
20
20
 
21
21
  const holdReservations = await stockHolderRepo.search({
22
- limit: 100,
23
- page: 1
22
+ limit: 2,
23
+ page: 2,
24
+ sort: { 'reservationFor.startDate': chevre.factory.sortType.Ascending }
24
25
  });
25
- console.log(holdReservations[0]?.reservationFor.aggregateReservation, holdReservations[0]?.objectSize);
26
+ console.log(holdReservations);
26
27
  console.log(holdReservations.length);
27
28
 
28
- const aggregations = await stockHolderRepo.aggregateByReservationFor({
29
- // reservationFor: { id: { $eq: 'xxx' } },
30
- limit: 100,
31
- page: 1
32
- });
33
- console.log(aggregations);
29
+ // const aggregations = await stockHolderRepo.aggregateByReservationFor({
30
+ // limit: 100,
31
+ // page: 1
32
+ // });
33
+ // console.log(aggregations);
34
34
  }
35
35
 
36
36
  main()
@@ -60,3 +60,33 @@ schema.index({ 'reservationFor.startDate': -1 }, { name: 'searchByReservationFor
60
60
  schema.index({ 'reservationFor.id': 1 }, { name: 'uniqueReservationForId', unique: true });
61
61
  schema.index({ 'reservationFor.id': 1, 'reservationFor.startDate': -1 }, { name: 'searchByReservationForId' });
62
62
  schema.index({ 'project.id': 1, 'reservationFor.startDate': -1 }, { name: 'searchByProjectId' });
63
+ schema.index({ 'reservations.reservationNumber': 1, 'reservationFor.startDate': -1 }, {
64
+ name: 'searchByReservationNumber',
65
+ partialFilterExpression: {
66
+ 'reservations.reservationNumber': { $exists: true }
67
+ }
68
+ });
69
+ schema.index({ 'reservations.subReservation.id': 1, 'reservationFor.startDate': -1 }, {
70
+ name: 'searchBySubReservationId',
71
+ partialFilterExpression: {
72
+ 'reservations.subReservation.id': { $exists: true }
73
+ }
74
+ });
75
+ schema.index({ 'reservations.subReservation.identifier': 1, 'reservationFor.startDate': -1 }, {
76
+ name: 'searchBySubReservationIdentifier',
77
+ partialFilterExpression: {
78
+ 'reservations.subReservation.identifier': { $exists: true }
79
+ }
80
+ });
81
+ schema.index({ 'reservations.subReservation.reservedTicket.ticketedSeat.seatNumber': 1, 'reservationFor.startDate': -1 }, {
82
+ name: 'searchBySubReservationSeatNumber',
83
+ partialFilterExpression: {
84
+ 'reservations.subReservation.reservedTicket.ticketedSeat.seatNumber': { $exists: true }
85
+ }
86
+ });
87
+ schema.index({ 'reservations.subReservation.reservedTicket.ticketedSeat.seatSection': 1, 'reservationFor.startDate': -1 }, {
88
+ name: 'searchBySubReservationSeatSection',
89
+ partialFilterExpression: {
90
+ 'reservations.subReservation.reservedTicket.ticketedSeat.seatSection': { $exists: true }
91
+ }
92
+ });
@@ -43,7 +43,6 @@ export interface ISubReservation {
43
43
  };
44
44
  }
45
45
  export interface IReservationPackage {
46
- typeOf: factory.reservationType.ReservationPackage;
47
46
  reservationNumber: string;
48
47
  subReservation: ISubReservation[];
49
48
  }
@@ -148,6 +147,9 @@ export declare class StockHolderRepository {
148
147
  search(params: {
149
148
  limit?: number;
150
149
  page?: number;
150
+ sort?: {
151
+ 'reservationFor.startDate': factory.sortType;
152
+ };
151
153
  project?: {
152
154
  id?: {
153
155
  $eq?: string;
@@ -123,7 +123,7 @@ class StockHolderRepository {
123
123
  const reservationCountLte = maximum - addedReservationCount;
124
124
  const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
125
125
  const reservationPackage = {
126
- typeOf: factory.reservationType.ReservationPackage,
126
+ // typeOf: factory.reservationType.ReservationPackage,
127
127
  reservationNumber: lockKey.holder,
128
128
  subReservation: subReservations
129
129
  };
@@ -181,7 +181,7 @@ class StockHolderRepository {
181
181
  const addedReservationCount = lockKey.offers.length;
182
182
  const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
183
183
  const reservationPackage = {
184
- typeOf: factory.reservationType.ReservationPackage,
184
+ // typeOf: factory.reservationType.ReservationPackage,
185
185
  reservationNumber: lockKey.holder,
186
186
  subReservation: subReservations
187
187
  };
@@ -264,8 +264,14 @@ class StockHolderRepository {
264
264
  const reservationNumber = params.holder;
265
265
  const updateResult = yield this.holdReservationModel.findOneAndUpdate({
266
266
  'reservationFor.id': { $eq: params.eventId },
267
- 'reservations.reservationNumber': { $eq: reservationNumber },
268
- 'reservations.subReservation.identifier': { $eq: subReservation.identifier }
267
+ 'reservations.reservationNumber': {
268
+ $exists: true,
269
+ $eq: reservationNumber
270
+ },
271
+ 'reservations.subReservation.identifier': {
272
+ $exists: true,
273
+ $eq: subReservation.identifier
274
+ }
269
275
  }, {
270
276
  $inc: { reservationCount: -1 },
271
277
  $pull: { 'reservations.$[reservationPackage].subReservation': { identifier: { $eq: subReservation.identifier } } }
@@ -277,8 +283,23 @@ class StockHolderRepository {
277
283
  })
278
284
  .select({ _id: 1 })
279
285
  .exec();
280
- debug('unlock processed. updateResult:', updateResult, 'reservationNumber:', reservationNumber, 'identifier:', subReservation.identifier);
281
286
  // docが存在しなくてもよい
287
+ debug('unlock processed. updateResult:', updateResult, 'reservationNumber:', reservationNumber, 'identifier:', subReservation.identifier);
288
+ // subReservationがemptyのreservationsをpull
289
+ const pullReservationPackageResult = yield this.holdReservationModel.findOneAndUpdate({
290
+ 'reservationFor.id': { $eq: params.eventId },
291
+ 'reservations.reservationNumber': { $exists: true, $eq: reservationNumber }
292
+ }, {
293
+ $pull: {
294
+ reservations: {
295
+ reservationNumber: { $eq: reservationNumber },
296
+ subReservation: { $size: 0 }
297
+ }
298
+ }
299
+ }, { new: true })
300
+ .select({ _id: 1 })
301
+ .exec();
302
+ debug('unlock processed. pullReservationPackageResult:', pullReservationPackageResult, 'reservationNumber:', reservationNumber, 'identifier:', subReservation.identifier);
282
303
  }
283
304
  else {
284
305
  const field = StockHolderRepository.offer2field(params.offer, params.hasTicketedSeat);
@@ -359,7 +380,12 @@ class StockHolderRepository {
359
380
  $match: { 'reservationFor.id': { $eq: params.eventId } }
360
381
  },
361
382
  {
362
- $match: { 'reservations.subReservation.identifier': { $eq: subReservation.identifier } }
383
+ $match: {
384
+ 'reservations.subReservation.identifier': {
385
+ $exists: true,
386
+ $eq: subReservation.identifier
387
+ }
388
+ }
363
389
  }
364
390
  ];
365
391
  const aggregate = this.holdReservationModel.aggregate([
@@ -436,7 +462,12 @@ class StockHolderRepository {
436
462
  $match: { 'reservationFor.id': { $eq: params.eventId } }
437
463
  },
438
464
  {
439
- $match: { 'reservations.subReservation.identifier': { $in: subReservations.map((r) => r.identifier) } }
465
+ $match: {
466
+ 'reservations.subReservation.identifier': {
467
+ $exists: true,
468
+ $in: subReservations.map((r) => r.identifier)
469
+ }
470
+ }
440
471
  }
441
472
  ];
442
473
  const aggregate = this.holdReservationModel.aggregate([
@@ -502,8 +533,9 @@ class StockHolderRepository {
502
533
  /**
503
534
  * 汎用的な検索(mongooseのみ対応)
504
535
  */
536
+ // tslint:disable-next-line:max-func-body-length
505
537
  search(params) {
506
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
538
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
507
539
  return __awaiter(this, void 0, void 0, function* () {
508
540
  const matchStages = [];
509
541
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -516,21 +548,16 @@ class StockHolderRepository {
516
548
  }
517
549
  const reservationNumberEq = (_e = params.reservationNumber) === null || _e === void 0 ? void 0 : _e.$eq;
518
550
  if (typeof reservationNumberEq === 'string') {
519
- matchStages.push({ $match: { 'reservations.reservationNumber': { $eq: reservationNumberEq } } });
551
+ matchStages.push({ $match: { 'reservations.reservationNumber': { $exists: true, $eq: reservationNumberEq } } });
520
552
  }
521
553
  const identifierEq = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$eq;
522
554
  if (typeof identifierEq === 'string') {
523
- matchStages.push({ $match: { 'reservations.subReservation.identifier': { $eq: identifierEq } } });
555
+ matchStages.push({ $match: { 'reservations.subReservation.identifier': { $exists: true, $eq: identifierEq } } });
524
556
  }
525
557
  const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
526
558
  if (typeof idEq === 'string') {
527
559
  matchStages.push({
528
- $match: {
529
- 'reservations.subReservation.id': {
530
- $exists: true,
531
- $eq: idEq
532
- }
533
- }
560
+ $match: { 'reservations.subReservation.id': { $exists: true, $eq: idEq } }
534
561
  });
535
562
  }
536
563
  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;
@@ -556,8 +583,21 @@ class StockHolderRepository {
556
583
  });
557
584
  }
558
585
  const aggregate = this.holdReservationModel.aggregate([
559
- { $unwind: '$reservations' },
560
- { $unwind: '$reservations.subReservation' },
586
+ ...(typeof ((_p = params.sort) === null || _p === void 0 ? void 0 : _p['reservationFor.startDate']) === 'number')
587
+ ? [{ $sort: { 'reservationFor.startDate': params.sort['reservationFor.startDate'] } }]
588
+ : [],
589
+ {
590
+ $unwind: {
591
+ path: '$reservations',
592
+ includeArrayIndex: 'reservationPackageIndex'
593
+ }
594
+ },
595
+ {
596
+ $unwind: {
597
+ path: '$reservations.subReservation',
598
+ includeArrayIndex: 'subReservationIndex'
599
+ }
600
+ },
561
601
  ...matchStages,
562
602
  {
563
603
  $project: {
@@ -573,7 +613,9 @@ class StockHolderRepository {
573
613
  },
574
614
  reservationNumber: '$reservations.reservationNumber',
575
615
  reservedTicket: '$reservations.subReservation.reservedTicket',
576
- objectSize: { $bsonSize: '$$ROOT' }
616
+ objectSize: { $bsonSize: '$$ROOT' },
617
+ reservationPackageIndex: '$reservationPackageIndex',
618
+ subReservationIndex: '$subReservationIndex'
577
619
  }
578
620
  }
579
621
  ]);
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.130"
120
+ "version": "21.2.0-alpha.131"
121
121
  }