@chevre/domain 21.2.0-alpha.135 → 21.2.0-alpha.136
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.
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.StockHolderRepository = void 0;
|
|
13
13
|
const createDebug = require("debug");
|
|
14
14
|
const moment = require("moment");
|
|
15
|
+
const mongoose_1 = require("mongoose");
|
|
15
16
|
const factory = require("../factory");
|
|
16
17
|
const holdReservation_1 = require("./mongoose/schemas/holdReservation");
|
|
17
18
|
const settings_1 = require("../settings");
|
|
@@ -129,12 +130,12 @@ class StockHolderRepository {
|
|
|
129
130
|
};
|
|
130
131
|
yield this.holdReservationModel.findOneAndUpdate({
|
|
131
132
|
_id: { $eq: id },
|
|
132
|
-
reservationCount: { $lte: reservationCountLte }
|
|
133
|
+
reservationCount: { $lte: reservationCountLte }
|
|
133
134
|
// 'reservationFor.id': { $eq: lockKey.eventId },
|
|
134
135
|
// 座席有無に関わらずsubReservation.identifierはuniqueであるはず
|
|
135
|
-
'reservations.subReservation.identifier': {
|
|
136
|
-
|
|
137
|
-
}
|
|
136
|
+
// 'reservations.subReservation.identifier': {
|
|
137
|
+
// $nin: subReservations.map((r) => r.identifier)
|
|
138
|
+
// }
|
|
138
139
|
}, {
|
|
139
140
|
$inc: { reservationCount: addedReservationCount },
|
|
140
141
|
$push: { reservations: reservationPackage }
|
|
@@ -146,6 +147,8 @@ class StockHolderRepository {
|
|
|
146
147
|
throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
|
|
147
148
|
}
|
|
148
149
|
});
|
|
150
|
+
// 重複検証
|
|
151
|
+
yield this.checkIfAlreadyInUse({ reservationPackage, id });
|
|
149
152
|
}
|
|
150
153
|
else {
|
|
151
154
|
const key = StockHolderRepository.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
|
|
@@ -164,6 +167,7 @@ class StockHolderRepository {
|
|
|
164
167
|
/**
|
|
165
168
|
* 座席をロックする
|
|
166
169
|
*/
|
|
170
|
+
// tslint:disable-next-line:max-func-body-length
|
|
167
171
|
lock(lockKey) {
|
|
168
172
|
return __awaiter(this, void 0, void 0, function* () {
|
|
169
173
|
if (!(lockKey.expires instanceof Date)) {
|
|
@@ -186,24 +190,20 @@ class StockHolderRepository {
|
|
|
186
190
|
reservationNumber: lockKey.holder,
|
|
187
191
|
subReservation: subReservations
|
|
188
192
|
};
|
|
189
|
-
yield this.holdReservationModel.
|
|
190
|
-
_id: { $eq: id }
|
|
193
|
+
yield this.holdReservationModel.updateOne({
|
|
194
|
+
_id: { $eq: id }
|
|
191
195
|
// 'reservationFor.id': { $eq: lockKey.eventId },
|
|
192
196
|
// 座席有無に関わらずsubReservation.identifierはuniqueであるはず
|
|
193
|
-
'reservations.subReservation.identifier': {
|
|
194
|
-
|
|
195
|
-
}
|
|
197
|
+
// 'reservations.subReservation.identifier': {
|
|
198
|
+
// $nin: subReservations.map((r) => r.identifier)
|
|
199
|
+
// }
|
|
196
200
|
}, {
|
|
197
201
|
$inc: { reservationCount: addedReservationCount },
|
|
198
202
|
$push: { reservations: reservationPackage }
|
|
199
|
-
}
|
|
200
|
-
.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
if (doc === null) {
|
|
204
|
-
throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
|
|
205
|
-
}
|
|
206
|
-
});
|
|
203
|
+
})
|
|
204
|
+
.exec();
|
|
205
|
+
// 重複検証
|
|
206
|
+
yield this.checkIfAlreadyInUse({ reservationPackage, id });
|
|
207
207
|
}
|
|
208
208
|
else {
|
|
209
209
|
const value = lockKey.holder;
|
|
@@ -261,11 +261,12 @@ class StockHolderRepository {
|
|
|
261
261
|
yield this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
|
|
262
262
|
if (useMongoose) {
|
|
263
263
|
// [id]あるいは[seatNumber+seatSection]でreservations.subReservationsから$pull+$incする
|
|
264
|
-
yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
264
|
+
const { id } = yield this.initializeHoldReservation({ project: params.project, eventId: params.eventId, startDate: params.startDate });
|
|
265
265
|
const subReservation = StockHolderRepository.offer2subReservation(params.offer, params.hasTicketedSeat);
|
|
266
266
|
const reservationNumber = params.holder;
|
|
267
267
|
const updateResult = yield this.holdReservationModel.findOneAndUpdate({
|
|
268
|
-
|
|
268
|
+
_id: { $eq: id },
|
|
269
|
+
// 'reservationFor.id': { $eq: params.eventId },
|
|
269
270
|
'reservations.reservationNumber': {
|
|
270
271
|
$exists: true,
|
|
271
272
|
$eq: reservationNumber
|
|
@@ -289,7 +290,8 @@ class StockHolderRepository {
|
|
|
289
290
|
debug('unlock processed. updateResult:', updateResult, 'reservationNumber:', reservationNumber, 'identifier:', subReservation.identifier);
|
|
290
291
|
// subReservationがemptyのreservationsをpull
|
|
291
292
|
const pullReservationPackageResult = yield this.holdReservationModel.findOneAndUpdate({
|
|
292
|
-
|
|
293
|
+
_id: { $eq: id },
|
|
294
|
+
// 'reservationFor.id': { $eq: params.eventId },
|
|
293
295
|
'reservations.reservationNumber': { $exists: true, $eq: reservationNumber }
|
|
294
296
|
}, {
|
|
295
297
|
$pull: {
|
|
@@ -738,6 +740,54 @@ class StockHolderRepository {
|
|
|
738
740
|
return { id: initializedResult.id };
|
|
739
741
|
});
|
|
740
742
|
}
|
|
743
|
+
/**
|
|
744
|
+
* 仮で追加したholdReservationsが重複していないかどうか検証する
|
|
745
|
+
*/
|
|
746
|
+
checkIfAlreadyInUse(params) {
|
|
747
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
748
|
+
const objectId = new mongoose_1.Types.ObjectId(params.id);
|
|
749
|
+
const matchStages = [
|
|
750
|
+
{ $match: { _id: { $eq: objectId } } },
|
|
751
|
+
{
|
|
752
|
+
$match: {
|
|
753
|
+
'reservations.subReservation.identifier': {
|
|
754
|
+
$exists: true,
|
|
755
|
+
$in: params.reservationPackage.subReservation.map((r) => r.identifier)
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
];
|
|
760
|
+
const aggregate = this.holdReservationModel.aggregate([
|
|
761
|
+
{ $unwind: '$reservations' },
|
|
762
|
+
{ $unwind: '$reservations.subReservation' },
|
|
763
|
+
...matchStages,
|
|
764
|
+
{
|
|
765
|
+
$project: {
|
|
766
|
+
_id: 0,
|
|
767
|
+
reservationNumber: '$reservations.reservationNumber'
|
|
768
|
+
}
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
$group: {
|
|
772
|
+
_id: '$reservationNumber'
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
]);
|
|
776
|
+
const subReservationsByDoc = yield aggregate.exec();
|
|
777
|
+
debug('checkIfAlreadyInUse:subReservationsByDoc:', subReservationsByDoc);
|
|
778
|
+
if (subReservationsByDoc.length > 1) {
|
|
779
|
+
// 仮追加したsubReservationsを削除
|
|
780
|
+
debug('canceling hold reservationPackage...reservationNumber:', params.reservationPackage.reservationNumber);
|
|
781
|
+
const updateOneResult = yield this.holdReservationModel.updateOne({ _id: { $eq: objectId } }, {
|
|
782
|
+
$inc: { reservationCount: -params.reservationPackage.subReservation.length },
|
|
783
|
+
$pull: { reservations: { reservationNumber: { $eq: params.reservationPackage.reservationNumber } } }
|
|
784
|
+
})
|
|
785
|
+
.exec();
|
|
786
|
+
debug('hold reservationPackage canceled. reservationNumber:', params.reservationPackage.reservationNumber, updateOneResult);
|
|
787
|
+
throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
|
|
788
|
+
}
|
|
789
|
+
});
|
|
790
|
+
}
|
|
741
791
|
}
|
|
742
792
|
StockHolderRepository.KEY_PREFIX_NEW = 'stockHolder';
|
|
743
793
|
StockHolderRepository.KEY_PREFIX = 'chevre:itemAvailability:screeningEvent';
|
package/package.json
CHANGED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// const PROJECT_ID = process.env.PROJECT_ID;
|
|
7
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
-
|
|
11
|
-
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
12
|
-
|
|
13
|
-
const movieTheater = await placeRepo.findById(
|
|
14
|
-
{ id: '5d1da6853736344e714efbb8' },
|
|
15
|
-
[
|
|
16
|
-
'additionalProperty',
|
|
17
|
-
'branchCode',
|
|
18
|
-
'hasEntranceGate',
|
|
19
|
-
'hasPOS',
|
|
20
|
-
'kanaName',
|
|
21
|
-
'name',
|
|
22
|
-
'parentOrganization',
|
|
23
|
-
'project',
|
|
24
|
-
'telephone',
|
|
25
|
-
'url',
|
|
26
|
-
'typeOf',
|
|
27
|
-
'containsPlace.branchCode',
|
|
28
|
-
'containsPlace.name',
|
|
29
|
-
'containsPlace.typeOf',
|
|
30
|
-
'containsPlace.additionalProperty',
|
|
31
|
-
'containsPlace.address'
|
|
32
|
-
],
|
|
33
|
-
[]
|
|
34
|
-
);
|
|
35
|
-
console.log('place found', movieTheater);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
main()
|
|
39
|
-
.then(console.log)
|
|
40
|
-
.catch(console.error);
|