@chevre/domain 21.2.0-alpha.124 → 21.2.0-alpha.125
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.
|
@@ -85,7 +85,12 @@ export declare class StockHolderRepository {
|
|
|
85
85
|
/**
|
|
86
86
|
* 座席をロックする
|
|
87
87
|
*/
|
|
88
|
-
lock(lockKey: ILockKey
|
|
88
|
+
lock(lockKey: ILockKey & {
|
|
89
|
+
/**
|
|
90
|
+
* テスト目的の強制オプション
|
|
91
|
+
*/
|
|
92
|
+
useMongooseForcibly?: boolean;
|
|
93
|
+
}): Promise<void>;
|
|
89
94
|
/**
|
|
90
95
|
* 座席ロックを解除する
|
|
91
96
|
*/
|
|
@@ -155,6 +160,5 @@ export declare class StockHolderRepository {
|
|
|
155
160
|
};
|
|
156
161
|
}): Promise<ISearchSubReservationResult[]>;
|
|
157
162
|
private checkIfConflicted;
|
|
158
|
-
private checkIfConflictedBetweenRedisAndMongo;
|
|
159
163
|
private initializeHoldReservation;
|
|
160
164
|
}
|
|
@@ -75,6 +75,9 @@ class StockHolderRepository {
|
|
|
75
75
|
* 新リポジトリを使用するかどうか
|
|
76
76
|
*/
|
|
77
77
|
static useMongoose(params) {
|
|
78
|
+
if (params.useMongooseForcibly === true) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
78
81
|
if (settings_1.USE_NEW_STOCK_HOLDER_REPO_IDS.includes(params.eventId)) {
|
|
79
82
|
return true;
|
|
80
83
|
}
|
|
@@ -85,8 +88,12 @@ class StockHolderRepository {
|
|
|
85
88
|
*/
|
|
86
89
|
lockIfNotLimitExceeded(lockKey, maximum) {
|
|
87
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
89
|
-
|
|
91
|
+
const useMongoose = StockHolderRepository.useMongoose({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
92
|
+
if (useMongoose) {
|
|
93
|
+
if (!(lockKey.expires instanceof Date)) {
|
|
94
|
+
throw new factory.errors.Argument('expires', 'must be Date');
|
|
95
|
+
}
|
|
96
|
+
yield this.checkIfConflicted({ key: '', eventId: lockKey.eventId, useMongoose });
|
|
90
97
|
// reservationCount<=nであれば$push+$incする
|
|
91
98
|
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
92
99
|
const addedReservationCount = lockKey.offers.length;
|
|
@@ -135,8 +142,17 @@ class StockHolderRepository {
|
|
|
135
142
|
*/
|
|
136
143
|
lock(lockKey) {
|
|
137
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
if (
|
|
139
|
-
|
|
145
|
+
if (!(lockKey.expires instanceof Date)) {
|
|
146
|
+
throw new factory.errors.Argument('expires', 'must be Date');
|
|
147
|
+
}
|
|
148
|
+
const useMongoose = StockHolderRepository.useMongoose({
|
|
149
|
+
eventId: lockKey.eventId,
|
|
150
|
+
startDate: lockKey.startDate,
|
|
151
|
+
useMongooseForcibly: lockKey.useMongooseForcibly
|
|
152
|
+
});
|
|
153
|
+
const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
154
|
+
yield this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
|
|
155
|
+
if (useMongoose) {
|
|
140
156
|
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
141
157
|
const addedReservationCount = lockKey.offers.length;
|
|
142
158
|
const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
@@ -164,11 +180,6 @@ class StockHolderRepository {
|
|
|
164
180
|
});
|
|
165
181
|
}
|
|
166
182
|
else {
|
|
167
|
-
if (!(lockKey.expires instanceof Date)) {
|
|
168
|
-
throw new factory.errors.Argument('expires', 'must be Date');
|
|
169
|
-
}
|
|
170
|
-
const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
171
|
-
yield this.checkIfConflicted({ key, eventId: lockKey.eventId });
|
|
172
183
|
const value = lockKey.holder;
|
|
173
184
|
const multi = this.redisClient.multi();
|
|
174
185
|
const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer));
|
|
@@ -215,8 +226,10 @@ class StockHolderRepository {
|
|
|
215
226
|
*/
|
|
216
227
|
unlock(params) {
|
|
217
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
-
|
|
219
|
-
|
|
229
|
+
const useMongoose = StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate });
|
|
230
|
+
const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
|
|
231
|
+
yield this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
|
|
232
|
+
if (useMongoose) {
|
|
220
233
|
// [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
|
|
221
234
|
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
222
235
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
@@ -240,8 +253,6 @@ class StockHolderRepository {
|
|
|
240
253
|
// docが存在しなくてもよい
|
|
241
254
|
}
|
|
242
255
|
else {
|
|
243
|
-
const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
|
|
244
|
-
yield this.checkIfConflicted({ key, eventId: params.eventId });
|
|
245
256
|
const field = StockHolderRepository.offer2field(params.offer);
|
|
246
257
|
yield this.redisClient.multi()
|
|
247
258
|
.hDel(key, field)
|
|
@@ -306,7 +317,7 @@ class StockHolderRepository {
|
|
|
306
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
307
318
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
308
319
|
// [id]あるいは[seatNumber+seatSection]でreservationNumberを返す
|
|
309
|
-
|
|
320
|
+
// await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
310
321
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
311
322
|
const matchStages = [
|
|
312
323
|
{
|
|
@@ -380,7 +391,7 @@ class StockHolderRepository {
|
|
|
380
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
381
392
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
382
393
|
// [id]あるいは[seatNumber+seatSection]のリストでreservationNumberのリストを返す
|
|
383
|
-
|
|
394
|
+
// await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
384
395
|
const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
385
396
|
const matchStages = [
|
|
386
397
|
{
|
|
@@ -535,29 +546,46 @@ class StockHolderRepository {
|
|
|
535
546
|
// 旧キーと新キーの両方存在検証(念のため)
|
|
536
547
|
const oldKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2020-01-01T00:00:00Z') });
|
|
537
548
|
const newKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2030-01-01T00:00:00Z') });
|
|
538
|
-
if (params.
|
|
549
|
+
if (params.useMongoose) {
|
|
550
|
+
// newもoldも存在するはずがない
|
|
539
551
|
// newの場合oldが存在するはずがない
|
|
540
552
|
const existingOldKeyCount = yield this.redisClient.exists(oldKey);
|
|
541
553
|
debug('existingOldKeyCount:', existingOldKeyCount);
|
|
542
554
|
if (existingOldKeyCount > 0) {
|
|
543
|
-
throw new factory.errors.ServiceUnavailable(
|
|
555
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder storage conflicted. eventId:${params.eventId}`);
|
|
544
556
|
}
|
|
545
|
-
}
|
|
546
|
-
if (params.key !== newKey) {
|
|
547
557
|
// oldの場合newが存在するはずがない
|
|
548
558
|
const existingNewKeyCount = yield this.redisClient.exists(newKey);
|
|
549
559
|
debug('existingNewKeyCount:', existingNewKeyCount);
|
|
550
560
|
if (existingNewKeyCount > 0) {
|
|
551
|
-
throw new factory.errors.ServiceUnavailable(
|
|
561
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder storage conflicted. eventId:${params.eventId}`);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
// collectionにdocumentが存在するはずがない
|
|
566
|
+
const existingHoldReservationCount = yield this.holdReservationModel.count({ 'reservationFor.id': { $eq: params.eventId } })
|
|
567
|
+
.exec();
|
|
568
|
+
debug('existingHoldReservationCount:', existingHoldReservationCount);
|
|
569
|
+
if (existingHoldReservationCount > 0) {
|
|
570
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder storage conflicted. eventId:${params.eventId}`);
|
|
571
|
+
}
|
|
572
|
+
if (params.key !== oldKey) {
|
|
573
|
+
// newの場合oldが存在するはずがない
|
|
574
|
+
const existingOldKeyCount = yield this.redisClient.exists(oldKey);
|
|
575
|
+
debug('existingOldKeyCount:', existingOldKeyCount);
|
|
576
|
+
if (existingOldKeyCount > 0) {
|
|
577
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder keys conflicted. eventId:${params.eventId}`);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (params.key !== newKey) {
|
|
581
|
+
// oldの場合newが存在するはずがない
|
|
582
|
+
const existingNewKeyCount = yield this.redisClient.exists(newKey);
|
|
583
|
+
debug('existingNewKeyCount:', existingNewKeyCount);
|
|
584
|
+
if (existingNewKeyCount > 0) {
|
|
585
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder keys conflicted. eventId:${params.eventId}`);
|
|
586
|
+
}
|
|
552
587
|
}
|
|
553
588
|
}
|
|
554
|
-
});
|
|
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
589
|
});
|
|
562
590
|
}
|
|
563
591
|
initializeHoldReservation(params) {
|
|
@@ -575,12 +603,11 @@ class StockHolderRepository {
|
|
|
575
603
|
},
|
|
576
604
|
reservations: []
|
|
577
605
|
};
|
|
578
|
-
const
|
|
606
|
+
const initializedResult = yield this.holdReservationModel.updateOne({ 'reservationFor.id': { $eq: params.eventId } }, {
|
|
579
607
|
$setOnInsert: aggregateReservation
|
|
580
|
-
}, {
|
|
581
|
-
.select({ _id: 1 })
|
|
608
|
+
}, { upsert: true })
|
|
582
609
|
.exec();
|
|
583
|
-
debug('holdReservation initialized',
|
|
610
|
+
debug('holdReservation initialized', initializedResult, params.eventId);
|
|
584
611
|
});
|
|
585
612
|
}
|
|
586
613
|
}
|
package/package.json
CHANGED