@chevre/domain 23.1.0-alpha.31 → 23.1.0-alpha.33
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/example/src/chevre/pendingReservation/findEventSeatOffersBySection.ts +45 -0
- package/example/src/chevre/project/unsetProjectSettings.ts +2 -2
- package/lib/chevre/repo/pendingReservation.js +28 -71
- package/lib/chevre/service/offer.d.ts +30 -1
- package/lib/chevre/service/offer.js +96 -34
- package/package.json +1 -1
|
@@ -0,0 +1,45 @@
|
|
|
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;
|
|
7
|
+
const formatter = new Intl.NumberFormat('ja-JP');
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
let startTime: [number, number] = process.hrtime();
|
|
12
|
+
let diff: [number, number] = process.hrtime(startTime);
|
|
13
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
+
|
|
15
|
+
setInterval(
|
|
16
|
+
async () => {
|
|
17
|
+
startTime = process.hrtime();
|
|
18
|
+
const result = await (await chevre.service.offer.createService()).findEventSeatOffersBySection({
|
|
19
|
+
limit: 100,
|
|
20
|
+
page: 10,
|
|
21
|
+
projectId: String(PROJECT_ID),
|
|
22
|
+
eventId: '693622f7876e9977c32ae270',
|
|
23
|
+
/**
|
|
24
|
+
* セクションコード
|
|
25
|
+
*/
|
|
26
|
+
sectionCode: 'Default'
|
|
27
|
+
})({
|
|
28
|
+
event: await chevre.repository.Event.createInstance(mongoose.connection),
|
|
29
|
+
seat: await chevre.repository.place.Seat.createInstance(mongoose.connection),
|
|
30
|
+
stockHolder: await chevre.repository.StockHolder.createInstance({ connection: mongoose.connection })
|
|
31
|
+
});
|
|
32
|
+
diff = process.hrtime(startTime);
|
|
33
|
+
// tslint:disable-next-line:no-null-keyword
|
|
34
|
+
console.dir(result, { depth: null });
|
|
35
|
+
console.log(result.length, 'results found');
|
|
36
|
+
console.log('diff:', [diff[0], formatter.format(diff[1])]);
|
|
37
|
+
},
|
|
38
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
39
|
+
1000
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
main()
|
|
44
|
+
.then()
|
|
45
|
+
.catch(console.error);
|
|
@@ -286,34 +286,38 @@ class PendingReservationRepo {
|
|
|
286
286
|
});
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
|
-
// public async
|
|
289
|
+
// public async findSubReservationsByEvent(params: {
|
|
290
|
+
// limit: number;
|
|
291
|
+
// page: number;
|
|
290
292
|
// project: { id: string };
|
|
291
293
|
// eventId: string;
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
// }
|
|
296
|
-
// const {
|
|
297
|
-
// const reservationIdentifiers = offers.map((offer) => PendingReservationRepo.offer2identifier(offer, hasTicketedSeat));
|
|
294
|
+
// }): Promise<{
|
|
295
|
+
// // reservationNumber: string;
|
|
296
|
+
// identifier: string;
|
|
297
|
+
// }[]> {
|
|
298
|
+
// const { limit, page, eventId } = params;
|
|
298
299
|
// const aggregate = this.pendingReservationModel.aggregate<{
|
|
299
|
-
// // reservationNumber: string;
|
|
300
300
|
// identifier: string;
|
|
301
301
|
// }>([
|
|
302
|
-
// // unwind,matchの順序
|
|
303
|
-
// // unwind->matchでは遅い?
|
|
304
|
-
// // match->limit->unwind->matchにする
|
|
305
302
|
// {
|
|
306
|
-
// $
|
|
307
|
-
//
|
|
303
|
+
// $match: {
|
|
304
|
+
// 'reservationFor.id': { $eq: eventId },
|
|
305
|
+
// 'subReservation.identifier': { $exists: true }
|
|
308
306
|
// }
|
|
309
307
|
// },
|
|
308
|
+
// // { $sort: { bookingTime: factory.sortType.Descending } },
|
|
310
309
|
// {
|
|
311
|
-
// $
|
|
312
|
-
//
|
|
313
|
-
// 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
|
|
310
|
+
// $unwind: {
|
|
311
|
+
// path: '$subReservation'
|
|
314
312
|
// }
|
|
315
313
|
// },
|
|
316
|
-
// { $
|
|
314
|
+
// { $sort: { 'subReservation.identifier': factory.sortType.Ascending } },
|
|
315
|
+
// // {
|
|
316
|
+
// // $match: {
|
|
317
|
+
// // // セクションで絞ってみる
|
|
318
|
+
// // 'subReservation.identifier': { $regex: new RegExp('^Default:') }
|
|
319
|
+
// // }
|
|
320
|
+
// // },
|
|
317
321
|
// {
|
|
318
322
|
// $project: {
|
|
319
323
|
// _id: 0,
|
|
@@ -322,64 +326,17 @@ class PendingReservationRepo {
|
|
|
322
326
|
// }
|
|
323
327
|
// }
|
|
324
328
|
// ]);
|
|
325
|
-
//
|
|
326
|
-
//
|
|
327
|
-
// .
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
// // tslint:disable-next-line:no-null-keyword
|
|
333
|
-
// // return (doc !== undefined) ? doc.reservationNumber : null;
|
|
334
|
-
// // tslint:disable-next-line:no-null-keyword
|
|
335
|
-
// return (doc !== undefined) ? doc.identifier : null;
|
|
336
|
-
// });
|
|
337
|
-
// }
|
|
338
|
-
// public async searchHoldersByDistinct(params: {
|
|
339
|
-
// project: { id: string };
|
|
340
|
-
// eventId: string;
|
|
341
|
-
// startDate: Date;
|
|
342
|
-
// hasTicketedSeat: boolean;
|
|
343
|
-
// offers: IOffer[];
|
|
344
|
-
// }) {
|
|
345
|
-
// const { eventId, offers, hasTicketedSeat } = params;
|
|
346
|
-
// const reservationIdentifiers = offers.map((offer) => PendingReservationRepo.offer2identifier(offer, hasTicketedSeat));
|
|
347
|
-
// const doc = await this.pendingReservationModel.distinct(
|
|
348
|
-
// 'subReservation.identifier',
|
|
349
|
-
// {
|
|
350
|
-
// 'reservationFor.id': { $eq: eventId },
|
|
351
|
-
// 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
|
|
352
|
-
// }
|
|
353
|
-
// )
|
|
354
|
-
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
355
|
-
// .exec();
|
|
356
|
-
// debug('searchHolders: distinct.', doc);
|
|
357
|
-
// return doc;
|
|
358
|
-
// }
|
|
359
|
-
// public async getSize(params: Omit<IUnlockKey, 'holder' | 'offer'>) {
|
|
360
|
-
// const { eventId } = params;
|
|
361
|
-
// const aggregate = this.aggregateReservationModel.aggregate([
|
|
362
|
-
// {
|
|
363
|
-
// $match: {
|
|
364
|
-
// 'reservationFor.id': { $eq: eventId }
|
|
365
|
-
// }
|
|
366
|
-
// },
|
|
367
|
-
// {
|
|
368
|
-
// $project: {
|
|
369
|
-
// typeOf: 1,
|
|
370
|
-
// objectSize: { $bsonSize: '$$ROOT' }
|
|
371
|
-
// }
|
|
372
|
-
// }
|
|
373
|
-
// ]);
|
|
329
|
+
// if (typeof limit === 'number' && limit > 0) {
|
|
330
|
+
// const pageMustBePositive: number = (typeof page === 'number' && page > 0) ? page : 1;
|
|
331
|
+
// aggregate.skip(limit * (pageMustBePositive - 1))
|
|
332
|
+
// .limit(limit);
|
|
333
|
+
// } else {
|
|
334
|
+
// throw new factory.errors.Argument('limit', 'must be number > 0');
|
|
335
|
+
// }
|
|
374
336
|
// return aggregate
|
|
375
337
|
// .option({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
376
338
|
// .exec();
|
|
377
339
|
// }
|
|
378
|
-
// public getCursor(conditions: FilterQuery<any>, projection: any) {
|
|
379
|
-
// return this.aggregateReservationModel.find(conditions, projection)
|
|
380
|
-
// .sort({ bookingTime: factory.sortType.Ascending })
|
|
381
|
-
// .cursor();
|
|
382
|
-
// }
|
|
383
340
|
docExists(params) {
|
|
384
341
|
return __awaiter(this, void 0, void 0, function* () {
|
|
385
342
|
const { eventId } = params;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EventRepo } from '../repo/event';
|
|
2
2
|
import type { SeatRepo } from '../repo/place/seat';
|
|
3
|
+
import type { SectionRepo } from '../repo/place/section';
|
|
3
4
|
import type { StockHolderRepo } from '../repo/stockHolder';
|
|
4
5
|
import * as factory from '../factory';
|
|
5
6
|
import * as EventOfferService from './offer/event';
|
|
@@ -25,6 +26,11 @@ type ISeatAsEventOffer = Pick<factory.place.seat.IPlaceWithOffer, 'branchCode' |
|
|
|
25
26
|
};
|
|
26
27
|
offers?: Pick<factory.place.seat.IOffer, 'availability'>[];
|
|
27
28
|
};
|
|
29
|
+
type ISeatOfferBySection = Pick<factory.place.seat.IOffer, 'availability'> & {
|
|
30
|
+
itemOffered: {
|
|
31
|
+
branchCode: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
28
34
|
/**
|
|
29
35
|
* イベントに対する座席オファーを検索する
|
|
30
36
|
*/
|
|
@@ -43,9 +49,32 @@ export declare function searchEventSeatOffersWithPaging(params: {
|
|
|
43
49
|
id: string;
|
|
44
50
|
};
|
|
45
51
|
$projection?: factory.place.seat.IProjection;
|
|
46
|
-
options: {
|
|
52
|
+
options: {
|
|
53
|
+
/**
|
|
54
|
+
* 自動的にひとつめのセクションに絞るかどうか
|
|
55
|
+
*/
|
|
56
|
+
useDefaultSection: boolean;
|
|
57
|
+
};
|
|
47
58
|
}): (repos: {
|
|
48
59
|
event: EventRepo;
|
|
49
60
|
stockHolder: StockHolderRepo;
|
|
50
61
|
seat: SeatRepo;
|
|
62
|
+
section: SectionRepo;
|
|
51
63
|
}) => Promise<ISeatAsEventOffer[]>;
|
|
64
|
+
/**
|
|
65
|
+
* セクション指定でイベントに対する座席オファーを検索する
|
|
66
|
+
*/
|
|
67
|
+
export declare function findEventSeatOffersBySection(params: {
|
|
68
|
+
limit: number;
|
|
69
|
+
page: number;
|
|
70
|
+
projectId: string;
|
|
71
|
+
eventId: string;
|
|
72
|
+
/**
|
|
73
|
+
* セクションコード
|
|
74
|
+
*/
|
|
75
|
+
sectionCode: string;
|
|
76
|
+
}): (repos: {
|
|
77
|
+
event: EventRepo;
|
|
78
|
+
stockHolder: StockHolderRepo;
|
|
79
|
+
seat: SeatRepo;
|
|
80
|
+
}) => Promise<ISeatOfferBySection[]>;
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.product = exports.moneyTransfer = exports.eventServiceByCOA = exports.event = void 0;
|
|
13
13
|
exports.addOffers2Seat = addOffers2Seat;
|
|
14
14
|
exports.searchEventSeatOffersWithPaging = searchEventSeatOffersWithPaging;
|
|
15
|
+
exports.findEventSeatOffersBySection = findEventSeatOffersBySection;
|
|
15
16
|
const moment = require("moment");
|
|
16
17
|
const factory = require("../factory");
|
|
17
18
|
const EventOfferService = require("./offer/event");
|
|
@@ -56,32 +57,49 @@ function addOffers2Seat(params) {
|
|
|
56
57
|
/**
|
|
57
58
|
* イベントに対する座席オファーを検索する
|
|
58
59
|
*/
|
|
59
|
-
// tslint:disable-next-line:max-func-body-length
|
|
60
60
|
function searchEventSeatOffersWithPaging(params) {
|
|
61
|
-
// tslint:disable-next-line:max-func-body-length
|
|
62
61
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
63
62
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
64
|
-
|
|
63
|
+
const { useDefaultSection } = params.options;
|
|
65
64
|
let offers = [];
|
|
66
65
|
// optimize(2024-07-18~)
|
|
67
|
-
const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'startDate', 'offers.itemOffered']);
|
|
66
|
+
const event = yield repos.event.projectEventFieldsById({ id: params.event.id }, ['project', 'startDate', 'offers.itemOffered', 'organizer']);
|
|
68
67
|
// 座席指定利用可能かどうか
|
|
69
68
|
const eventOffers = event.offers;
|
|
70
69
|
const reservedSeatsAvailable = ((_b = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) !== undefined;
|
|
71
70
|
if (reservedSeatsAvailable) {
|
|
72
71
|
const roomBranchCode = String((_d = (_c = eventOffers.itemOffered) === null || _c === void 0 ? void 0 : _c.availableChannel) === null || _d === void 0 ? void 0 : _d.serviceLocation.branchCode);
|
|
73
72
|
const movieTheaterBranchCode = String((_f = (_e = eventOffers.itemOffered) === null || _e === void 0 ? void 0 : _e.availableChannel) === null || _f === void 0 ? void 0 : _f.serviceLocation.containedInPlace.branchCode);
|
|
73
|
+
let defaultSectionCode;
|
|
74
|
+
if (useDefaultSection) {
|
|
75
|
+
const defaultSection = (yield repos.section.findSectionsByRoom({
|
|
76
|
+
limit: 1,
|
|
77
|
+
page: 1,
|
|
78
|
+
projectId: event.project.id,
|
|
79
|
+
sellerId: event.organizer.id,
|
|
80
|
+
movieTheaterCode: movieTheaterBranchCode,
|
|
81
|
+
roomCode: roomBranchCode
|
|
82
|
+
})).shift();
|
|
83
|
+
if (defaultSection === undefined) {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
defaultSectionCode = defaultSection.branchCode;
|
|
87
|
+
// tslint:disable-next-line:no-console
|
|
88
|
+
console.log('searchEventSeatOffersWithPaging:defaultSectionCode:', defaultSectionCode);
|
|
89
|
+
}
|
|
74
90
|
const seats = yield repos.seat.projectSeatsByScreeningRoom(Object.assign(Object.assign({}, params), { project: { id: { $eq: event.project.id } }, screeningRoom: {
|
|
75
91
|
branchCode: { $eq: roomBranchCode },
|
|
76
92
|
containedInPlace: {
|
|
77
93
|
branchCode: { $eq: movieTheaterBranchCode }
|
|
78
94
|
}
|
|
79
95
|
}, containedInPlace: {
|
|
80
|
-
branchCode: {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
:
|
|
84
|
-
|
|
96
|
+
branchCode: Object.assign({}, (typeof defaultSectionCode === 'string')
|
|
97
|
+
? { $eq: defaultSectionCode }
|
|
98
|
+
: {
|
|
99
|
+
$eq: (typeof ((_h = (_g = params.containedInPlace) === null || _g === void 0 ? void 0 : _g.branchCode) === null || _h === void 0 ? void 0 : _h.$eq) === 'string')
|
|
100
|
+
? (_k = (_j = params.containedInPlace) === null || _j === void 0 ? void 0 : _j.branchCode) === null || _k === void 0 ? void 0 : _k.$eq
|
|
101
|
+
: undefined
|
|
102
|
+
})
|
|
85
103
|
}, $projection: Object.assign({}, params.$projection) }));
|
|
86
104
|
if (seats.length > 0) {
|
|
87
105
|
const availabilities = yield repos.stockHolder.searchHolders({
|
|
@@ -98,31 +116,6 @@ function searchEventSeatOffersWithPaging(params) {
|
|
|
98
116
|
};
|
|
99
117
|
})
|
|
100
118
|
});
|
|
101
|
-
// ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
|
|
102
|
-
// const uniqueSeatingTypes = await repos.seat.aggregateSeatingTypes({
|
|
103
|
-
// project: { id: { $eq: event.project.id } },
|
|
104
|
-
// containedInPlace: {
|
|
105
|
-
// containedInPlace: {
|
|
106
|
-
// branchCode: { $eq: roomBranchCode },
|
|
107
|
-
// containedInPlace: { branchCode: { $eq: movieTheaterBranchCode } }
|
|
108
|
-
// }
|
|
109
|
-
// }
|
|
110
|
-
// });
|
|
111
|
-
// 座席タイプ価格仕様を検索
|
|
112
|
-
// let priceSpecs: ICategoryCodeChargeSpecification[] = [];
|
|
113
|
-
// if (!excludePriceSpecification) {
|
|
114
|
-
// if (Array.isArray(uniqueSeatingTypes) && uniqueSeatingTypes.length > 0) {
|
|
115
|
-
// priceSpecs =
|
|
116
|
-
// await repos.priceSpecification.search<factory.priceSpecificationType.CategoryCodeChargeSpecification>({
|
|
117
|
-
// project: { id: { $eq: event.project.id } },
|
|
118
|
-
// typeOf: factory.priceSpecificationType.CategoryCodeChargeSpecification,
|
|
119
|
-
// appliesToCategoryCode: {
|
|
120
|
-
// inCodeSet: { identifier: { $eq: factory.categoryCode.CategorySetIdentifier.SeatingType } },
|
|
121
|
-
// codeValue: { $in: uniqueSeatingTypes } // ルームに含まれる座席区分のみ加算料金を検索(2024-08-05~)
|
|
122
|
-
// }
|
|
123
|
-
// });
|
|
124
|
-
// }
|
|
125
|
-
// }
|
|
126
119
|
offers = seats.map((seat, index) => {
|
|
127
120
|
return addOffers2Seat({
|
|
128
121
|
seat,
|
|
@@ -137,3 +130,72 @@ function searchEventSeatOffersWithPaging(params) {
|
|
|
137
130
|
return offers;
|
|
138
131
|
});
|
|
139
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* セクション指定でイベントに対する座席オファーを検索する
|
|
135
|
+
*/
|
|
136
|
+
function findEventSeatOffersBySection(params) {
|
|
137
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a, _b, _c, _d, _e, _f;
|
|
139
|
+
const { limit, page, projectId, eventId, sectionCode } = params;
|
|
140
|
+
let offers = [];
|
|
141
|
+
// optimize(2024-07-18~)
|
|
142
|
+
const event = yield repos.event.projectEventFieldsById({ id: eventId }, ['startDate', 'offers.itemOffered']);
|
|
143
|
+
// 座席指定利用可能かどうか
|
|
144
|
+
const eventOffers = event.offers;
|
|
145
|
+
const reservedSeatsAvailable = ((_b = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.itemOffered.serviceOutput) === null || _a === void 0 ? void 0 : _a.reservedTicket) === null || _b === void 0 ? void 0 : _b.ticketedSeat) !== undefined;
|
|
146
|
+
if (reservedSeatsAvailable) {
|
|
147
|
+
const roomBranchCode = String((_d = (_c = eventOffers.itemOffered) === null || _c === void 0 ? void 0 : _c.availableChannel) === null || _d === void 0 ? void 0 : _d.serviceLocation.branchCode);
|
|
148
|
+
const movieTheaterBranchCode = String((_f = (_e = eventOffers.itemOffered) === null || _e === void 0 ? void 0 : _e.availableChannel) === null || _f === void 0 ? void 0 : _f.serviceLocation.containedInPlace.branchCode);
|
|
149
|
+
const seats = yield repos.seat.projectSeatsByScreeningRoom({
|
|
150
|
+
limit,
|
|
151
|
+
page,
|
|
152
|
+
project: { id: { $eq: projectId } },
|
|
153
|
+
screeningRoom: {
|
|
154
|
+
branchCode: { $eq: roomBranchCode },
|
|
155
|
+
containedInPlace: {
|
|
156
|
+
branchCode: { $eq: movieTheaterBranchCode }
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
containedInPlace: {
|
|
160
|
+
branchCode: { $eq: sectionCode } // セクション指定
|
|
161
|
+
},
|
|
162
|
+
$projection: {
|
|
163
|
+
'containedInPlace.branchCode': 0,
|
|
164
|
+
'containedInPlace.containedInPlace': 0,
|
|
165
|
+
'containedInPlace.typeOf': 0,
|
|
166
|
+
'containedInPlace.name': 0,
|
|
167
|
+
typeOf: 0,
|
|
168
|
+
additionalProperty: 0,
|
|
169
|
+
seatingType: 0,
|
|
170
|
+
name: 0
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
if (seats.length > 0) {
|
|
174
|
+
const availabilities = yield repos.stockHolder.searchHolders({
|
|
175
|
+
project: { id: projectId },
|
|
176
|
+
eventId,
|
|
177
|
+
startDate: moment(event.startDate)
|
|
178
|
+
.toDate(),
|
|
179
|
+
hasTicketedSeat: true,
|
|
180
|
+
offers: seats.map((s) => {
|
|
181
|
+
return {
|
|
182
|
+
seatNumber: s.branchCode,
|
|
183
|
+
seatSection: sectionCode
|
|
184
|
+
};
|
|
185
|
+
})
|
|
186
|
+
});
|
|
187
|
+
offers = seats.map((seat, index) => {
|
|
188
|
+
return {
|
|
189
|
+
availability: (typeof availabilities[index] === 'string')
|
|
190
|
+
? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
|
|
191
|
+
: factory.itemAvailability.InStock,
|
|
192
|
+
itemOffered: {
|
|
193
|
+
branchCode: seat.branchCode
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return offers;
|
|
200
|
+
});
|
|
201
|
+
}
|
package/package.json
CHANGED