@chevre/domain 21.2.0-alpha.123 → 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
|
*/
|
|
@@ -140,6 +145,9 @@ export declare class StockHolderRepository {
|
|
|
140
145
|
id?: {
|
|
141
146
|
$eq?: string;
|
|
142
147
|
};
|
|
148
|
+
identifier?: {
|
|
149
|
+
$eq?: string;
|
|
150
|
+
};
|
|
143
151
|
reservedTicket?: {
|
|
144
152
|
ticketedSeat?: {
|
|
145
153
|
seatNumber?: {
|
|
@@ -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,7 +88,12 @@ class StockHolderRepository {
|
|
|
85
88
|
*/
|
|
86
89
|
lockIfNotLimitExceeded(lockKey, maximum) {
|
|
87
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
|
|
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 });
|
|
89
97
|
// reservationCount<=nであれば$push+$incする
|
|
90
98
|
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
91
99
|
const addedReservationCount = lockKey.offers.length;
|
|
@@ -134,7 +142,17 @@ class StockHolderRepository {
|
|
|
134
142
|
*/
|
|
135
143
|
lock(lockKey) {
|
|
136
144
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
if (
|
|
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) {
|
|
138
156
|
yield this.initializeHoldReservation({ project: lockKey.project, eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
139
157
|
const addedReservationCount = lockKey.offers.length;
|
|
140
158
|
const subReservations = lockKey.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
@@ -162,11 +180,6 @@ class StockHolderRepository {
|
|
|
162
180
|
});
|
|
163
181
|
}
|
|
164
182
|
else {
|
|
165
|
-
if (!(lockKey.expires instanceof Date)) {
|
|
166
|
-
throw new factory.errors.Argument('expires', 'must be Date');
|
|
167
|
-
}
|
|
168
|
-
const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
169
|
-
yield this.checkIfConflicted({ key, eventId: lockKey.eventId });
|
|
170
183
|
const value = lockKey.holder;
|
|
171
184
|
const multi = this.redisClient.multi();
|
|
172
185
|
const fields = lockKey.offers.map((offer) => StockHolderRepository.offer2field(offer));
|
|
@@ -213,7 +226,10 @@ class StockHolderRepository {
|
|
|
213
226
|
*/
|
|
214
227
|
unlock(params) {
|
|
215
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
216
|
-
|
|
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) {
|
|
217
233
|
// [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
|
|
218
234
|
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
219
235
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
@@ -237,8 +253,6 @@ class StockHolderRepository {
|
|
|
237
253
|
// docが存在しなくてもよい
|
|
238
254
|
}
|
|
239
255
|
else {
|
|
240
|
-
const key = StockHolderRepository.createKey({ eventId: params.eventId, startDate: params.startDate });
|
|
241
|
-
yield this.checkIfConflicted({ key, eventId: params.eventId });
|
|
242
256
|
const field = StockHolderRepository.offer2field(params.offer);
|
|
243
257
|
yield this.redisClient.multi()
|
|
244
258
|
.hDel(key, field)
|
|
@@ -303,7 +317,7 @@ class StockHolderRepository {
|
|
|
303
317
|
return __awaiter(this, void 0, void 0, function* () {
|
|
304
318
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
305
319
|
// [id]あるいは[seatNumber+seatSection]でreservationNumberを返す
|
|
306
|
-
|
|
320
|
+
// await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
307
321
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer);
|
|
308
322
|
const matchStages = [
|
|
309
323
|
{
|
|
@@ -377,7 +391,7 @@ class StockHolderRepository {
|
|
|
377
391
|
return __awaiter(this, void 0, void 0, function* () {
|
|
378
392
|
if (StockHolderRepository.useMongoose({ eventId: params.eventId, startDate: params.startDate })) {
|
|
379
393
|
// [id]あるいは[seatNumber+seatSection]のリストでreservationNumberのリストを返す
|
|
380
|
-
|
|
394
|
+
// await this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
381
395
|
const subReservations = params.offers.map((offer) => StockHolderRepository.offer2subReservation(offer));
|
|
382
396
|
const matchStages = [
|
|
383
397
|
{
|
|
@@ -451,13 +465,9 @@ class StockHolderRepository {
|
|
|
451
465
|
* 汎用的な検索(mongooseのみ対応)
|
|
452
466
|
*/
|
|
453
467
|
search(params) {
|
|
454
|
-
var _a, _b, _c, _d, _e;
|
|
468
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
455
469
|
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
|
-
];
|
|
470
|
+
const matchStages = [];
|
|
461
471
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
462
472
|
if (typeof projectIdEq === 'string') {
|
|
463
473
|
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
@@ -470,6 +480,43 @@ class StockHolderRepository {
|
|
|
470
480
|
if (typeof reservationNumberEq === 'string') {
|
|
471
481
|
matchStages.push({ $match: { 'reservations.reservationNumber': { $eq: reservationNumberEq } } });
|
|
472
482
|
}
|
|
483
|
+
const identifierEq = (_f = params.identifier) === null || _f === void 0 ? void 0 : _f.$eq;
|
|
484
|
+
if (typeof identifierEq === 'string') {
|
|
485
|
+
matchStages.push({ $match: { 'reservations.subReservation.identifier': { $eq: identifierEq } } });
|
|
486
|
+
}
|
|
487
|
+
const idEq = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
488
|
+
if (typeof idEq === 'string') {
|
|
489
|
+
matchStages.push({
|
|
490
|
+
$match: {
|
|
491
|
+
'reservations.subReservation.id': {
|
|
492
|
+
$exists: true,
|
|
493
|
+
$eq: idEq
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
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;
|
|
499
|
+
if (typeof seatNumberEq === 'string') {
|
|
500
|
+
matchStages.push({
|
|
501
|
+
$match: {
|
|
502
|
+
'reservations.subReservation.reservedTicket.ticketedSeat.seatNumber': {
|
|
503
|
+
$exists: true,
|
|
504
|
+
$eq: seatNumberEq
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
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;
|
|
510
|
+
if (typeof seatSectionEq === 'string') {
|
|
511
|
+
matchStages.push({
|
|
512
|
+
$match: {
|
|
513
|
+
'reservations.subReservation.reservedTicket.ticketedSeat.seatSection': {
|
|
514
|
+
$exists: true,
|
|
515
|
+
$eq: seatSectionEq
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
}
|
|
473
520
|
const aggregate = this.holdReservationModel.aggregate([
|
|
474
521
|
{ $unwind: '$reservations' },
|
|
475
522
|
{ $unwind: '$reservations.subReservation' },
|
|
@@ -490,7 +537,8 @@ class StockHolderRepository {
|
|
|
490
537
|
aggregate.limit(params.limit * page)
|
|
491
538
|
.skip(params.limit * (page - 1));
|
|
492
539
|
}
|
|
493
|
-
return aggregate.
|
|
540
|
+
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
541
|
+
.exec();
|
|
494
542
|
});
|
|
495
543
|
}
|
|
496
544
|
checkIfConflicted(params) {
|
|
@@ -498,20 +546,44 @@ class StockHolderRepository {
|
|
|
498
546
|
// 旧キーと新キーの両方存在検証(念のため)
|
|
499
547
|
const oldKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2020-01-01T00:00:00Z') });
|
|
500
548
|
const newKey = StockHolderRepository.createKey({ eventId: params.eventId, startDate: new Date('2030-01-01T00:00:00Z') });
|
|
501
|
-
if (params.
|
|
549
|
+
if (params.useMongoose) {
|
|
550
|
+
// newもoldも存在するはずがない
|
|
502
551
|
// newの場合oldが存在するはずがない
|
|
503
552
|
const existingOldKeyCount = yield this.redisClient.exists(oldKey);
|
|
504
553
|
debug('existingOldKeyCount:', existingOldKeyCount);
|
|
505
554
|
if (existingOldKeyCount > 0) {
|
|
506
|
-
throw new factory.errors.ServiceUnavailable(
|
|
555
|
+
throw new factory.errors.ServiceUnavailable(`stockHolder storage conflicted. eventId:${params.eventId}`);
|
|
507
556
|
}
|
|
508
|
-
}
|
|
509
|
-
if (params.key !== newKey) {
|
|
510
557
|
// oldの場合newが存在するはずがない
|
|
511
558
|
const existingNewKeyCount = yield this.redisClient.exists(newKey);
|
|
512
559
|
debug('existingNewKeyCount:', existingNewKeyCount);
|
|
513
560
|
if (existingNewKeyCount > 0) {
|
|
514
|
-
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
|
+
}
|
|
515
587
|
}
|
|
516
588
|
}
|
|
517
589
|
});
|
|
@@ -531,12 +603,11 @@ class StockHolderRepository {
|
|
|
531
603
|
},
|
|
532
604
|
reservations: []
|
|
533
605
|
};
|
|
534
|
-
const
|
|
606
|
+
const initializedResult = yield this.holdReservationModel.updateOne({ 'reservationFor.id': { $eq: params.eventId } }, {
|
|
535
607
|
$setOnInsert: aggregateReservation
|
|
536
|
-
}, {
|
|
537
|
-
.select({ _id: 1 })
|
|
608
|
+
}, { upsert: true })
|
|
538
609
|
.exec();
|
|
539
|
-
debug('holdReservation initialized',
|
|
610
|
+
debug('holdReservation initialized', initializedResult, params.eventId);
|
|
540
611
|
});
|
|
541
612
|
}
|
|
542
613
|
}
|
package/package.json
CHANGED