@chevre/domain 21.2.0-alpha.142 → 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
@@ -268,24 +268,26 @@ class MongoRepository {
268
268
  });
269
269
  yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
270
270
  const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
271
- yield this.placeModel.findOneAndUpdate({
272
- typeOf: { $eq: factory.placeType.ScreeningRoom },
273
- 'project.id': { $eq: createScreeningRoom.project.id },
274
- 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
275
- branchCode: { $eq: createScreeningRoom.branchCode }
276
- }, {
277
- $setOnInsert: {
278
- typeOf: createScreeningRoom.typeOf,
279
- project: createScreeningRoom.project,
280
- branchCode: createScreeningRoom.branchCode
281
- },
282
- $set: setFields
283
- }, {
284
- upsert: true,
285
- new: true,
286
- projection: { _id: 1 }
287
- })
288
- .exec();
271
+ if (typeof branchCode === 'string' && branchCode.length > 0) {
272
+ yield this.placeModel.findOneAndUpdate({
273
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
274
+ 'project.id': { $eq: createScreeningRoom.project.id },
275
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
276
+ branchCode: { $eq: createScreeningRoom.branchCode }
277
+ }, {
278
+ $setOnInsert: {
279
+ typeOf: createScreeningRoom.typeOf,
280
+ project: createScreeningRoom.project,
281
+ branchCode: createScreeningRoom.branchCode
282
+ },
283
+ $set: setFields
284
+ }, {
285
+ upsert: true,
286
+ new: true,
287
+ projection: { _id: 1 }
288
+ })
289
+ .exec();
290
+ }
289
291
  })));
290
292
  });
291
293
  }
@@ -517,6 +519,16 @@ class MongoRepository {
517
519
  return doc.toObject();
518
520
  });
519
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
+ }
520
532
  createScreeningRoomSection(screeningRoomSection) {
521
533
  return __awaiter(this, void 0, void 0, function* () {
522
534
  const screeningRoom = screeningRoomSection.containedInPlace;
@@ -842,7 +854,8 @@ class MongoRepository {
842
854
  branchCode: '$containsPlace.branchCode',
843
855
  name: '$containsPlace.name',
844
856
  containedInPlace: {
845
- id: '$_id',
857
+ id: { $toString: '$_id' },
858
+ // id: '$_id',
846
859
  typeOf: '$typeOf',
847
860
  branchCode: '$branchCode',
848
861
  name: '$name'
@@ -1011,6 +1024,7 @@ class MongoRepository {
1011
1024
  });
1012
1025
  }
1013
1026
  const aggregate = this.placeModel.aggregate([
1027
+ { $sort: { branchCode: factory.sortType.Ascending } },
1014
1028
  // { $unwind: '$containsPlace' },
1015
1029
  ...matchStages,
1016
1030
  {
@@ -1165,7 +1179,8 @@ class MongoRepository {
1165
1179
  ...matchStages,
1166
1180
  {
1167
1181
  $project: Object.assign(Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', address: '$containsPlace.address', containedInPlace: {
1168
- id: '$_id',
1182
+ id: { $toString: '$_id' },
1183
+ // id: '$_id',
1169
1184
  typeOf: '$typeOf',
1170
1185
  branchCode: '$branchCode',
1171
1186
  name: '$name'
@@ -1230,16 +1245,21 @@ class MongoRepository {
1230
1245
  typeOf: '$containsPlace.typeOf',
1231
1246
  branchCode: '$containsPlace.branchCode',
1232
1247
  name: '$containsPlace.name',
1233
- // address: '$containsPlace.address',
1234
- // containedInPlace: {
1235
- // id: '$_id',
1236
- // typeOf: '$typeOf',
1237
- // branchCode: '$branchCode',
1238
- // name: '$name'
1239
- // },
1240
- // openSeatingAllowed: '$containsPlace.openSeatingAllowed',
1241
- // additionalProperty: '$containsPlace.additionalProperty',
1242
- 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
+ }
1243
1263
  }
1244
1264
  }
1245
1265
  ]);
@@ -1715,7 +1735,8 @@ class MongoRepository {
1715
1735
  branchCode: '$containsPlace.branchCode',
1716
1736
  name: '$containsPlace.name',
1717
1737
  containedInPlace: {
1718
- id: '$_id',
1738
+ id: { $toString: '$_id' },
1739
+ // id: '$_id',
1719
1740
  typeOf: '$typeOf',
1720
1741
  branchCode: '$branchCode',
1721
1742
  name: '$name'
@@ -1800,25 +1821,27 @@ class MongoRepository {
1800
1821
  debug('sync processing', creatingScreeningRooms.length, 'screeningRooms...', creatingScreeningRooms);
1801
1822
  yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
1802
1823
  const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
1803
- const upsertScreeningRoomResult = yield this.placeModel.findOneAndUpdate({
1804
- typeOf: { $eq: factory.placeType.ScreeningRoom },
1805
- 'project.id': { $eq: createScreeningRoom.project.id },
1806
- 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
1807
- branchCode: { $eq: createScreeningRoom.branchCode }
1808
- }, {
1809
- $setOnInsert: {
1810
- typeOf: createScreeningRoom.typeOf,
1811
- project: createScreeningRoom.project,
1812
- branchCode: createScreeningRoom.branchCode
1813
- },
1814
- $set: setFields
1815
- }, {
1816
- upsert: true,
1817
- new: true,
1818
- projection: { _id: 1 }
1819
- })
1820
- .exec();
1821
- debug('screeningRoom upserted. upsertScreeningRoomResult:', upsertScreeningRoomResult);
1824
+ if (typeof branchCode === 'string' && branchCode.length > 0) {
1825
+ const upsertScreeningRoomResult = yield this.placeModel.findOneAndUpdate({
1826
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
1827
+ 'project.id': { $eq: createScreeningRoom.project.id },
1828
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
1829
+ branchCode: { $eq: createScreeningRoom.branchCode }
1830
+ }, {
1831
+ $setOnInsert: {
1832
+ typeOf: createScreeningRoom.typeOf,
1833
+ project: createScreeningRoom.project,
1834
+ branchCode: createScreeningRoom.branchCode
1835
+ },
1836
+ $set: setFields
1837
+ }, {
1838
+ upsert: true,
1839
+ new: true,
1840
+ projection: { _id: 1 }
1841
+ })
1842
+ .exec();
1843
+ debug('screeningRoom upserted. upsertScreeningRoomResult:', upsertScreeningRoomResult);
1844
+ }
1822
1845
  })));
1823
1846
  });
1824
1847
  }
@@ -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.142"
120
+ "version": "21.2.0-alpha.144"
121
121
  }