@chevre/domain 23.1.0-alpha.30 → 23.1.0-alpha.32

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.
@@ -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);
@@ -0,0 +1,27 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // tslint:disable-next-line:max-func-body-length
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const roomRepo = await chevre.repository.place.ScreeningRoom.createInstance(mongoose.connection);
11
+
12
+ const rooms = await roomRepo.searchScreeningRooms({
13
+ $projection: { sectionCount: 1 }
14
+ });
15
+ console.log('docs found');
16
+ console.log(rooms);
17
+
18
+ const mutipleSectionRooms = rooms.filter((room) => typeof room.sectionCount === 'number' && room.sectionCount > 1);
19
+ console.log(mutipleSectionRooms);
20
+
21
+ console.log(rooms.length, 'rooms');
22
+ console.log(mutipleSectionRooms.length, 'mutipleSectionRooms');
23
+ }
24
+
25
+ main()
26
+ .then()
27
+ .catch(console.error);
@@ -0,0 +1,50 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const PROJECT_ID = String(process.env.PROJECT_ID);
7
+ const SCREEN_CODE = '100';
8
+ const MOVIE_THEATER_CODE = '118';
9
+ const SELLER_ID = '59d20831e53ebc2b4e774466';
10
+
11
+ const formatter = new Intl.NumberFormat('ja-JP');
12
+
13
+ // tslint:disable-next-line:max-func-body-length
14
+ async function main() {
15
+ let startTime: [number, number] = process.hrtime();
16
+ let diff: [number, number] = process.hrtime(startTime);
17
+
18
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
19
+
20
+ const sectionRepo = await chevre.repository.place.Section.createInstance(mongoose.connection);
21
+
22
+ setInterval(
23
+ async () => {
24
+ startTime = process.hrtime();
25
+ const seats = await sectionRepo.findSectionsByRoom(
26
+ {
27
+ limit: 10,
28
+ page: 1,
29
+ projectId: PROJECT_ID,
30
+ sellerId: SELLER_ID,
31
+ movieTheaterCode: MOVIE_THEATER_CODE,
32
+ roomCode: SCREEN_CODE
33
+ }
34
+ );
35
+ diff = process.hrtime(startTime);
36
+ // tslint:disable-next-line:no-null-keyword
37
+ console.dir(seats, { depth: null });
38
+ console.log(seats.length, 'sections found');
39
+ console.log('diff:', [diff[0], formatter.format(diff[1])]);
40
+ },
41
+ // tslint:disable-next-line:no-magic-numbers
42
+ 1000
43
+ );
44
+ }
45
+
46
+ main()
47
+ .then(() => {
48
+ console.log('success!');
49
+ })
50
+ .catch(console.error);
@@ -13,8 +13,8 @@ async function main() {
13
13
  {
14
14
  _id: {
15
15
  $nin: [
16
- 'ttts-development', 'sskts-development',
17
- 'ttts-test', 'sskts-test',
16
+ 'ttts-development',
17
+ 'ttts-test',
18
18
  'ttts-production', 'sskts-production'
19
19
  ]
20
20
  }
@@ -286,34 +286,38 @@ class PendingReservationRepo {
286
286
  });
287
287
  });
288
288
  }
289
- // public async searchHolders2(params: {
289
+ // public async findSubReservationsByEvent(params: {
290
+ // limit: number;
291
+ // page: number;
290
292
  // project: { id: string };
291
293
  // eventId: string;
292
- // startDate: Date;
293
- // hasTicketedSeat: boolean;
294
- // offers: IOffer[];
295
- // }): Promise<IGetHolderResult[]> {
296
- // const { eventId, offers, hasTicketedSeat } = params;
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
- // $unwind: {
307
- // path: '$subReservation'
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
- // $match: {
312
- // 'reservationFor.id': { $eq: eventId },
313
- // 'subReservation.identifier': { $exists: true, $in: reservationIdentifiers }
310
+ // $unwind: {
311
+ // path: '$subReservation'
314
312
  // }
315
313
  // },
316
- // { $limit: reservationIdentifiers.length },
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
- // const docs = await aggregate
326
- // .option({ maxTimeMS: MONGO_MAX_TIME_MS })
327
- // .exec();
328
- // debug('searchHolders: aggregated.', docs, docs.length, 'docs');
329
- // // reservationNumberを正確に返す必要はなく、存在しているかどうかだけ分かればよい(stringを返せばよい)
330
- // return reservationIdentifiers.map((reservationIdentifier) => {
331
- // const doc = docs.find(({ identifier }) => identifier === reservationIdentifier);
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;
@@ -37,6 +37,26 @@ export declare class SectionRepo {
37
37
  };
38
38
  }, $unset: any): Promise<IUpdateSectionResult>;
39
39
  searchScreeningRoomSections(searchConditions: factory.place.screeningRoomSection.ISearchConditions): Promise<IScreeningRoomSectionWithoutContainsPlace[]>;
40
+ /**
41
+ * ルーム指定のセクション検索として再定義(2025-12-07~)
42
+ */
43
+ findSectionsByRoom(params: {
44
+ limit: number;
45
+ page: number;
46
+ projectId: string;
47
+ /**
48
+ * 販売者ID
49
+ */
50
+ sellerId: string;
51
+ /**
52
+ * 施設コード
53
+ */
54
+ movieTheaterCode: string;
55
+ /**
56
+ * ルームコード
57
+ */
58
+ roomCode: string;
59
+ }): Promise<Pick<IScreeningRoomSectionWithoutContainsPlace, 'additionalProperty' | 'branchCode' | 'name'>[]>;
40
60
  deleteScreeningRoomSection(screeningRoomSection: {
41
61
  project: {
42
62
  id: string;
@@ -248,6 +248,53 @@ class SectionRepo {
248
248
  .exec();
249
249
  });
250
250
  }
251
+ /**
252
+ * ルーム指定のセクション検索として再定義(2025-12-07~)
253
+ */
254
+ findSectionsByRoom(params
255
+ // options: Pick<
256
+ // factory.place.screeningRoomSection.ISearchConditions,
257
+ // 'branchCode'
258
+ // >
259
+ ) {
260
+ return __awaiter(this, void 0, void 0, function* () {
261
+ const { limit, page, projectId, sellerId, movieTheaterCode, roomCode } = params;
262
+ const matchStageBeforeUnwind = {
263
+ $match: {
264
+ 'project.id': { $eq: projectId },
265
+ 'parentOrganization.id': { $exists: true, $eq: sellerId },
266
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode }, // 施設コード
267
+ branchCode: { $eq: roomCode } // ルームコード
268
+ }
269
+ };
270
+ const aggregate = this.placeModel.aggregate([
271
+ // uniwind前はドキュメントの_id指定
272
+ matchStageBeforeUnwind,
273
+ { $unwind: '$containsPlace' },
274
+ // ...matchStages,
275
+ {
276
+ $project: {
277
+ _id: 0,
278
+ // typeOf: '$containsPlace.typeOf',
279
+ branchCode: '$containsPlace.branchCode',
280
+ name: '$containsPlace.name',
281
+ additionalProperty: '$containsPlace.additionalProperty'
282
+ }
283
+ }
284
+ ]);
285
+ if (typeof limit === 'number' && limit > 0) {
286
+ const pageMustBePositive = (typeof page === 'number' && page > 0) ? page : 1;
287
+ aggregate.skip(limit * (pageMustBePositive - 1))
288
+ .limit(limit);
289
+ }
290
+ else {
291
+ throw new factory.errors.Argument('limit', 'must be number > 0');
292
+ }
293
+ return aggregate
294
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
295
+ .exec();
296
+ });
297
+ }
251
298
  deleteScreeningRoomSection(screeningRoomSection) {
252
299
  return __awaiter(this, void 0, void 0, function* () {
253
300
  var _a;
@@ -25,6 +25,11 @@ type ISeatAsEventOffer = Pick<factory.place.seat.IPlaceWithOffer, 'branchCode' |
25
25
  };
26
26
  offers?: Pick<factory.place.seat.IOffer, 'availability'>[];
27
27
  };
28
+ type ISeatOfferBySection = Pick<factory.place.seat.IOffer, 'availability'> & {
29
+ itemOffered: {
30
+ branchCode: string;
31
+ };
32
+ };
28
33
  /**
29
34
  * イベントに対する座席オファーを検索する
30
35
  */
@@ -49,3 +54,20 @@ export declare function searchEventSeatOffersWithPaging(params: {
49
54
  stockHolder: StockHolderRepo;
50
55
  seat: SeatRepo;
51
56
  }) => Promise<ISeatAsEventOffer[]>;
57
+ /**
58
+ * セクション指定でイベントに対する座席オファーを検索する
59
+ */
60
+ export declare function findEventSeatOffersBySection(params: {
61
+ limit: number;
62
+ page: number;
63
+ projectId: string;
64
+ eventId: string;
65
+ /**
66
+ * セクションコード
67
+ */
68
+ sectionCode: string;
69
+ }): (repos: {
70
+ event: EventRepo;
71
+ stockHolder: StockHolderRepo;
72
+ seat: SeatRepo;
73
+ }) => 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");
@@ -137,3 +138,72 @@ function searchEventSeatOffersWithPaging(params) {
137
138
  return offers;
138
139
  });
139
140
  }
141
+ /**
142
+ * セクション指定でイベントに対する座席オファーを検索する
143
+ */
144
+ function findEventSeatOffersBySection(params) {
145
+ return (repos) => __awaiter(this, void 0, void 0, function* () {
146
+ var _a, _b, _c, _d, _e, _f;
147
+ const { limit, page, projectId, eventId, sectionCode } = params;
148
+ let offers = [];
149
+ // optimize(2024-07-18~)
150
+ const event = yield repos.event.projectEventFieldsById({ id: eventId }, ['startDate', 'offers.itemOffered']);
151
+ // 座席指定利用可能かどうか
152
+ const eventOffers = event.offers;
153
+ 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;
154
+ if (reservedSeatsAvailable) {
155
+ const roomBranchCode = String((_d = (_c = eventOffers.itemOffered) === null || _c === void 0 ? void 0 : _c.availableChannel) === null || _d === void 0 ? void 0 : _d.serviceLocation.branchCode);
156
+ 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);
157
+ const seats = yield repos.seat.projectSeatsByScreeningRoom({
158
+ limit,
159
+ page,
160
+ project: { id: { $eq: projectId } },
161
+ screeningRoom: {
162
+ branchCode: { $eq: roomBranchCode },
163
+ containedInPlace: {
164
+ branchCode: { $eq: movieTheaterBranchCode }
165
+ }
166
+ },
167
+ containedInPlace: {
168
+ branchCode: { $eq: sectionCode } // セクション指定
169
+ },
170
+ $projection: {
171
+ 'containedInPlace.branchCode': 0,
172
+ 'containedInPlace.containedInPlace': 0,
173
+ 'containedInPlace.typeOf': 0,
174
+ 'containedInPlace.name': 0,
175
+ typeOf: 0,
176
+ additionalProperty: 0,
177
+ seatingType: 0,
178
+ name: 0
179
+ }
180
+ });
181
+ if (seats.length > 0) {
182
+ const availabilities = yield repos.stockHolder.searchHolders({
183
+ project: { id: projectId },
184
+ eventId,
185
+ startDate: moment(event.startDate)
186
+ .toDate(),
187
+ hasTicketedSeat: true,
188
+ offers: seats.map((s) => {
189
+ return {
190
+ seatNumber: s.branchCode,
191
+ seatSection: sectionCode
192
+ };
193
+ })
194
+ });
195
+ offers = seats.map((seat, index) => {
196
+ return {
197
+ availability: (typeof availabilities[index] === 'string')
198
+ ? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
199
+ : factory.itemAvailability.InStock,
200
+ itemOffered: {
201
+ branchCode: seat.branchCode
202
+ }
203
+ };
204
+ });
205
+ }
206
+ }
207
+ return offers;
208
+ });
209
+ }
package/package.json CHANGED
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "23.1.0-alpha.30"
118
+ "version": "23.1.0-alpha.32"
119
119
  }