@chevre/domain 21.2.0-alpha.133 → 21.2.0-alpha.134

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.
@@ -6,7 +6,7 @@ import * as redis from 'redis';
6
6
  import { chevre } from '../../../lib/index';
7
7
 
8
8
  async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
10
10
  const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
11
11
  socket: {
12
12
  host: process.env.REDIS_HOST,
@@ -60,6 +60,7 @@ 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({ reservationCount: 1, 'reservationFor.startDate': -1 }, { name: 'searchByReservationCount' });
63
64
  schema.index({ 'reservations.reservationNumber': 1, 'reservationFor.startDate': -1 }, {
64
65
  name: 'searchByReservationNumber',
65
66
  partialFilterExpression: {
@@ -118,7 +118,7 @@ class StockHolderRepository {
118
118
  }
119
119
  yield this.checkIfConflicted({ key: '', eventId: lockKey.eventId, useMongoose });
120
120
  // reservationCount<=nであれば$push+$incする
121
- yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
121
+ const { id } = yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
122
122
  const addedReservationCount = lockKey.offers.length;
123
123
  const reservationCountLte = maximum - addedReservationCount;
124
124
  const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
@@ -128,8 +128,9 @@ class StockHolderRepository {
128
128
  subReservation: subReservations
129
129
  };
130
130
  yield this.holdReservationModel.findOneAndUpdate({
131
+ _id: { $eq: id },
131
132
  reservationCount: { $lte: reservationCountLte },
132
- 'reservationFor.id': { $eq: lockKey.eventId },
133
+ // 'reservationFor.id': { $eq: lockKey.eventId },
133
134
  // 座席有無に関わらずsubReservation.identifierはuniqueであるはず
134
135
  'reservations.subReservation.identifier': {
135
136
  $nin: subReservations.map((r) => r.identifier)
@@ -177,7 +178,7 @@ class StockHolderRepository {
177
178
  const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
178
179
  yield this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
179
180
  if (useMongoose) {
180
- yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
181
+ const { id } = yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
181
182
  const addedReservationCount = lockKey.offers.length;
182
183
  const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer, lockKey.hasTicketedSeat));
183
184
  const reservationPackage = {
@@ -186,7 +187,8 @@ class StockHolderRepository {
186
187
  subReservation: subReservations
187
188
  };
188
189
  yield this.holdReservationModel.findOneAndUpdate({
189
- 'reservationFor.id': { $eq: lockKey.eventId },
190
+ _id: { $eq: id },
191
+ // 'reservationFor.id': { $eq: lockKey.eventId },
190
192
  // 座席有無に関わらずsubReservation.identifierはuniqueであるはず
191
193
  'reservations.subReservation.identifier': {
192
194
  $nin: subReservations.map((r) => r.identifier)
@@ -727,11 +729,13 @@ class StockHolderRepository {
727
729
  },
728
730
  reservations: []
729
731
  };
730
- const initializedResult = yield this.holdReservationModel.updateOne({ 'reservationFor.id': { $eq: params.eventId } }, {
732
+ const initializedResult = yield this.holdReservationModel.findOneAndUpdate({ 'reservationFor.id': { $eq: params.eventId } }, {
731
733
  $setOnInsert: aggregateReservation
732
- }, { upsert: true })
734
+ }, { new: true, upsert: true })
735
+ .select({ _id: 1 })
733
736
  .exec();
734
737
  debug('holdReservation initialized', initializedResult, params.eventId);
738
+ return { id: initializedResult.id };
735
739
  });
736
740
  }
737
741
  }
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.133"
120
+ "version": "21.2.0-alpha.134"
121
121
  }