@chevre/domain 21.2.0-alpha.143 → 21.2.0-alpha.144

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.
@@ -6,16 +6,27 @@ import { chevre } from '../../../lib/index';
6
6
  // const PROJECT_ID = String(process.env.PROJECT_ID);
7
7
 
8
8
  async function main() {
9
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
10
 
11
11
  const placeRepo = new chevre.repository.Place(mongoose.connection);
12
12
 
13
- const rooms = await placeRepo.searchScreeningRooms({
14
- $projection: { sectionCount: 1 }
15
- });
13
+ const rooms = await placeRepo.searchScreeningRooms(
14
+ {
15
+ limit: 10,
16
+ page: 1,
17
+ $projection: { sectionCount: 1 }
18
+ },
19
+ true
20
+ );
16
21
  console.log('place found', rooms);
17
22
  const filteredRooms = rooms.filter((room) => typeof room.sectionCount === 'number' && room.sectionCount > 1);
18
23
  console.log(filteredRooms.length, 'filteredRooms found');
24
+
25
+ const screeningRoom = await placeRepo.findScreeningRoomsByBranchCode({
26
+ branchCode: { $eq: rooms[0].branchCode },
27
+ containedInPlace: { id: { $eq: String(rooms[0].containedInPlace?.id) } }
28
+ });
29
+ console.log('screeningRoom found', screeningRoom);
19
30
  }
20
31
 
21
32
  main()
@@ -25,7 +25,7 @@
25
25
  import { Connection } from 'mongoose';
26
26
  import * as factory from '../factory';
27
27
  type IScreeningRoomSectionWithoutContainsPlace = Omit<factory.place.screeningRoomSection.IPlace, 'containsPlace'>;
28
- export type IScreeningRoomFoundByBranchCode = Pick<factory.place.screeningRoom.IPlace, 'typeOf' | 'branchCode' | 'name' | 'containsPlace'>;
28
+ export type IScreeningRoomFoundByBranchCode = Pick<factory.place.screeningRoom.IPlace, 'typeOf' | 'branchCode' | 'name' | 'containsPlace' | 'seatCount'>;
29
29
  /**
30
30
  * 施設リポジトリ
31
31
  */
@@ -89,6 +89,17 @@ export declare class MongoRepository {
89
89
  id: string;
90
90
  typeOf: factory.placeType.MovieTheater;
91
91
  }>;
92
+ deleteScreeningRoomsByMovieTheaterId(params: {
93
+ project: {
94
+ id: string;
95
+ };
96
+ containedInPlace: {
97
+ /**
98
+ * 施設ID
99
+ */
100
+ id: string;
101
+ };
102
+ }): Promise<void>;
92
103
  createScreeningRoomSection(screeningRoomSection: IScreeningRoomSectionWithoutContainsPlace): Promise<{
93
104
  /**
94
105
  * 施設ID
@@ -519,6 +519,16 @@ class MongoRepository {
519
519
  return doc.toObject();
520
520
  });
521
521
  }
522
+ deleteScreeningRoomsByMovieTheaterId(params) {
523
+ return __awaiter(this, void 0, void 0, function* () {
524
+ yield this.placeModel.deleteMany({
525
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
526
+ 'project.id': { $eq: params.project.id },
527
+ 'containedInPlace.id': { $exists: true, $eq: params.containedInPlace.id }
528
+ })
529
+ .exec();
530
+ });
531
+ }
522
532
  createScreeningRoomSection(screeningRoomSection) {
523
533
  return __awaiter(this, void 0, void 0, function* () {
524
534
  const screeningRoom = screeningRoomSection.containedInPlace;
@@ -844,7 +854,8 @@ class MongoRepository {
844
854
  branchCode: '$containsPlace.branchCode',
845
855
  name: '$containsPlace.name',
846
856
  containedInPlace: {
847
- id: '$_id',
857
+ id: { $toString: '$_id' },
858
+ // id: '$_id',
848
859
  typeOf: '$typeOf',
849
860
  branchCode: '$branchCode',
850
861
  name: '$name'
@@ -1013,6 +1024,7 @@ class MongoRepository {
1013
1024
  });
1014
1025
  }
1015
1026
  const aggregate = this.placeModel.aggregate([
1027
+ { $sort: { branchCode: factory.sortType.Ascending } },
1016
1028
  // { $unwind: '$containsPlace' },
1017
1029
  ...matchStages,
1018
1030
  {
@@ -1167,7 +1179,8 @@ class MongoRepository {
1167
1179
  ...matchStages,
1168
1180
  {
1169
1181
  $project: Object.assign(Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', address: '$containsPlace.address', containedInPlace: {
1170
- id: '$_id',
1182
+ id: { $toString: '$_id' },
1183
+ // id: '$_id',
1171
1184
  typeOf: '$typeOf',
1172
1185
  branchCode: '$branchCode',
1173
1186
  name: '$name'
@@ -1232,16 +1245,21 @@ class MongoRepository {
1232
1245
  typeOf: '$containsPlace.typeOf',
1233
1246
  branchCode: '$containsPlace.branchCode',
1234
1247
  name: '$containsPlace.name',
1235
- // address: '$containsPlace.address',
1236
- // containedInPlace: {
1237
- // id: '$_id',
1238
- // typeOf: '$typeOf',
1239
- // branchCode: '$branchCode',
1240
- // name: '$name'
1241
- // },
1242
- // openSeatingAllowed: '$containsPlace.openSeatingAllowed',
1243
- // additionalProperty: '$containsPlace.additionalProperty',
1244
- containsPlace: '$containsPlace.containsPlace'
1248
+ containsPlace: '$containsPlace.containsPlace',
1249
+ seatCount: {
1250
+ $sum: {
1251
+ $map: {
1252
+ input: '$containsPlace.containsPlace',
1253
+ in: {
1254
+ $cond: {
1255
+ if: { $isArray: '$$this.containsPlace' },
1256
+ then: { $size: '$$this.containsPlace' },
1257
+ else: 0
1258
+ }
1259
+ }
1260
+ }
1261
+ }
1262
+ }
1245
1263
  }
1246
1264
  }
1247
1265
  ]);
@@ -1717,7 +1735,8 @@ class MongoRepository {
1717
1735
  branchCode: '$containsPlace.branchCode',
1718
1736
  name: '$containsPlace.name',
1719
1737
  containedInPlace: {
1720
- id: '$_id',
1738
+ id: { $toString: '$_id' },
1739
+ // id: '$_id',
1721
1740
  typeOf: '$typeOf',
1722
1741
  branchCode: '$branchCode',
1723
1742
  name: '$name'
@@ -87,7 +87,7 @@ function aggregateByEvent(params) {
87
87
  const { maximumAttendeeCapacity, remainingAttendeeCapacity, aggregateReservation } = yield aggregateReservationByEvent({
88
88
  aggregateDate: now,
89
89
  event: event,
90
- screeningRoom: screeningRoom
90
+ screeningRoom
91
91
  })(repos);
92
92
  // オファーごとの集計
93
93
  let aggregateOffer;
@@ -429,10 +429,15 @@ function aggregateReservationByEvent(params) {
429
429
  }
430
430
  const hasTicketedSeat = reservedSeatsAvailable({ event: params.event });
431
431
  if (hasTicketedSeat) {
432
- const screeningRoomSeatCount = (Array.isArray(params.screeningRoom.containsPlace))
433
- // b.containsPlaceがundefinedの場合があるので注意(座席未登録)
434
- ? params.screeningRoom.containsPlace.reduce((a, b) => a + ((Array.isArray(b.containsPlace)) ? b.containsPlace.length : 0), 0)
435
- : 0;
432
+ // seatCountを利用する(2023-06-24~)
433
+ const screeningRoomSeatCount = (typeof params.screeningRoom.seatCount === 'number') ? params.screeningRoom.seatCount : 0;
434
+ // const screeningRoomSeatCount = (Array.isArray(params.screeningRoom.containsPlace))
435
+ // // b.containsPlaceがundefinedの場合があるので注意(座席未登録)
436
+ // ? params.screeningRoom.containsPlace.reduce(
437
+ // (a, b) => a + ((Array.isArray(b.containsPlace)) ? b.containsPlace.length : 0),
438
+ // 0
439
+ // )
440
+ // : 0;
436
441
  maximumAttendeeCapacity = screeningRoomSeatCount;
437
442
  // イベントのキャパシティ設定がスクリーン座席数より小さければmaximumAttendeeCapacityを上書き
438
443
  if (typeof eventLocationMaximumAttendeeCapacity === 'number' && eventLocationMaximumAttendeeCapacity < screeningRoomSeatCount) {
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.143"
120
+ "version": "21.2.0-alpha.144"
121
121
  }