@chevre/domain 21.2.0-alpha.134 → 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.
- package/lib/chevre/repo/place.d.ts +2 -8
- package/lib/chevre/repo/place.js +58 -34
- package/lib/chevre/repo/stockHolder.d.ts +4 -0
- package/lib/chevre/repo/stockHolder.js +70 -20
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +9 -9
- package/lib/chevre/service/task/onResourceUpdated.js +9 -3
- package/package.json +1 -1
- package/example/src/chevre/findMovieTheaterById.ts +0 -40
|
@@ -48,17 +48,11 @@ export declare class MongoRepository {
|
|
|
48
48
|
/**
|
|
49
49
|
* 施設検索
|
|
50
50
|
*/
|
|
51
|
-
searchMovieTheaters(params: factory.place.movieTheater.ISearchConditions & {
|
|
52
|
-
$projection?: {
|
|
53
|
-
[key: string]: 0;
|
|
54
|
-
};
|
|
55
|
-
}): Promise<factory.place.movieTheater.IPlaceWithoutScreeningRoom[]>;
|
|
51
|
+
searchMovieTheaters(params: factory.place.movieTheater.ISearchConditions & {}, inclusion: string[], exclusion: string[]): Promise<factory.place.movieTheater.IPlaceWithoutScreeningRoom[]>;
|
|
56
52
|
/**
|
|
57
53
|
* 施設取得
|
|
54
|
+
* 廃止(2023-06-22~)
|
|
58
55
|
*/
|
|
59
|
-
findById(params: {
|
|
60
|
-
id: string;
|
|
61
|
-
}, inclusion: string[], exclusion: string[]): Promise<factory.place.movieTheater.IPlace>;
|
|
62
56
|
deleteMovieTheaterById(params: {
|
|
63
57
|
id: string;
|
|
64
58
|
}): Promise<void>;
|
package/lib/chevre/repo/place.js
CHANGED
|
@@ -277,34 +277,12 @@ class MongoRepository {
|
|
|
277
277
|
/**
|
|
278
278
|
* 施設検索
|
|
279
279
|
*/
|
|
280
|
-
searchMovieTheaters(params
|
|
280
|
+
searchMovieTheaters(params,
|
|
281
|
+
// projection明示指定化(2023-06-22~)
|
|
282
|
+
inclusion, exclusion) {
|
|
281
283
|
var _a;
|
|
282
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
283
285
|
const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
|
|
284
|
-
// containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
|
|
285
|
-
const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0, containsPlace: 0 }, params.$projection));
|
|
286
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
287
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
288
|
-
query.limit(params.limit)
|
|
289
|
-
.skip(params.limit * (page - 1));
|
|
290
|
-
}
|
|
291
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
292
|
-
/* istanbul ignore else */
|
|
293
|
-
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
|
|
294
|
-
query.sort({ branchCode: params.sort.branchCode });
|
|
295
|
-
}
|
|
296
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
297
|
-
.exec()
|
|
298
|
-
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* 施設取得
|
|
303
|
-
*/
|
|
304
|
-
findById(params,
|
|
305
|
-
// projection?: any
|
|
306
|
-
inclusion, exclusion) {
|
|
307
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
308
286
|
let projection = {};
|
|
309
287
|
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
310
288
|
inclusion.forEach((field) => {
|
|
@@ -315,7 +293,9 @@ class MongoRepository {
|
|
|
315
293
|
projection = {
|
|
316
294
|
__v: 0,
|
|
317
295
|
createdAt: 0,
|
|
318
|
-
updatedAt: 0
|
|
296
|
+
updatedAt: 0,
|
|
297
|
+
// containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
|
|
298
|
+
containsPlace: 0
|
|
319
299
|
};
|
|
320
300
|
if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
321
301
|
exclusion.forEach((field) => {
|
|
@@ -323,17 +303,61 @@ class MongoRepository {
|
|
|
323
303
|
});
|
|
324
304
|
}
|
|
325
305
|
}
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
if (doc === null) {
|
|
332
|
-
throw new factory.errors.NotFound(this.placeModel.modelName);
|
|
306
|
+
const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
307
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
308
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
309
|
+
query.limit(params.limit)
|
|
310
|
+
.skip(params.limit * (page - 1));
|
|
333
311
|
}
|
|
334
|
-
|
|
312
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
313
|
+
/* istanbul ignore else */
|
|
314
|
+
if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
|
|
315
|
+
query.sort({ branchCode: params.sort.branchCode });
|
|
316
|
+
}
|
|
317
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
318
|
+
.exec()
|
|
319
|
+
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
335
320
|
});
|
|
336
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* 施設取得
|
|
324
|
+
* 廃止(2023-06-22~)
|
|
325
|
+
*/
|
|
326
|
+
// public async findById(
|
|
327
|
+
// params: { id: string },
|
|
328
|
+
// inclusion: string[],
|
|
329
|
+
// exclusion: string[]
|
|
330
|
+
// ): Promise<factory.place.movieTheater.IPlace> {
|
|
331
|
+
// let projection: { [key: string]: number } = {};
|
|
332
|
+
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
333
|
+
// inclusion.forEach((field) => {
|
|
334
|
+
// projection[field] = 1;
|
|
335
|
+
// });
|
|
336
|
+
// } else {
|
|
337
|
+
// projection = {
|
|
338
|
+
// __v: 0,
|
|
339
|
+
// createdAt: 0,
|
|
340
|
+
// updatedAt: 0
|
|
341
|
+
// };
|
|
342
|
+
// if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
343
|
+
// exclusion.forEach((field) => {
|
|
344
|
+
// projection[field] = 0;
|
|
345
|
+
// });
|
|
346
|
+
// }
|
|
347
|
+
// }
|
|
348
|
+
// const doc = await this.placeModel.findOne(
|
|
349
|
+
// {
|
|
350
|
+
// typeOf: { $eq: factory.placeType.MovieTheater },
|
|
351
|
+
// _id: { $eq: params.id }
|
|
352
|
+
// },
|
|
353
|
+
// projection
|
|
354
|
+
// )
|
|
355
|
+
// .exec();
|
|
356
|
+
// if (doc === null) {
|
|
357
|
+
// throw new factory.errors.NotFound(this.placeModel.modelName);
|
|
358
|
+
// }
|
|
359
|
+
// return doc.toObject();
|
|
360
|
+
// }
|
|
337
361
|
deleteMovieTheaterById(params) {
|
|
338
362
|
return __awaiter(this, void 0, void 0, function* () {
|
|
339
363
|
yield this.placeModel.findOneAndDelete({
|
|
@@ -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';
|
|
@@ -59,15 +59,15 @@ function findEntranceGates(params) {
|
|
|
59
59
|
const searchMovieTheatersResult = yield repos.place.searchMovieTheaters({
|
|
60
60
|
limit: 1,
|
|
61
61
|
page: 1,
|
|
62
|
-
id: { $eq: params.event.superEvent.location.id }
|
|
63
|
-
$projection: {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
});
|
|
62
|
+
id: { $eq: params.event.superEvent.location.id }
|
|
63
|
+
// $projection: {
|
|
64
|
+
// containsPlace: 0,
|
|
65
|
+
// hasPOS: 0,
|
|
66
|
+
// offers: 0,
|
|
67
|
+
// parentOrganization: 0,
|
|
68
|
+
// name: 0
|
|
69
|
+
// }
|
|
70
|
+
}, ['hasEntranceGate'], []);
|
|
71
71
|
movieTheater = searchMovieTheatersResult.shift();
|
|
72
72
|
// movieTheater = await repos.place.findById(
|
|
73
73
|
// { id: params.event.superEvent.location.id },
|
|
@@ -231,7 +231,12 @@ function createInformMovieTheaterTasks(params) {
|
|
|
231
231
|
if (params.ids.length !== 1) {
|
|
232
232
|
throw new factory.errors.Argument('id', 'id.length must be 1');
|
|
233
233
|
}
|
|
234
|
-
const
|
|
234
|
+
const movieTheaters = yield repos.place.searchMovieTheaters({
|
|
235
|
+
limit: 1,
|
|
236
|
+
page: 1,
|
|
237
|
+
project: { id: { $eq: params.project.id } },
|
|
238
|
+
id: { $eq: params.ids[0] }
|
|
239
|
+
}, [
|
|
235
240
|
'additionalProperty',
|
|
236
241
|
'branchCode',
|
|
237
242
|
'hasEntranceGate',
|
|
@@ -249,8 +254,9 @@ function createInformMovieTheaterTasks(params) {
|
|
|
249
254
|
// 'containsPlace.additionalProperty',
|
|
250
255
|
// 'containsPlace.address'
|
|
251
256
|
], []);
|
|
252
|
-
|
|
253
|
-
|
|
257
|
+
const movieTheater = movieTheaters.shift();
|
|
258
|
+
if (movieTheater === undefined) {
|
|
259
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
254
260
|
}
|
|
255
261
|
// ルームを検索
|
|
256
262
|
const screeningRooms = yield repos.place.searchScreeningRooms({
|
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);
|