@chevre/domain 21.2.0-alpha.99 → 21.2.0

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.
Files changed (162) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  2. package/example/src/chevre/aggregateSellerPaymentAccepted.ts +27 -0
  3. package/example/src/chevre/aggregation/aggregateSystem.ts +53 -22
  4. package/example/src/chevre/countDelayedTasks.ts +7 -2
  5. package/example/src/chevre/createManyEventsIfNotExist.ts +199 -46
  6. package/example/src/chevre/findScreeningRoomsByBranchCode.ts +4 -3
  7. package/example/src/chevre/giveUpStartDatePassedCertainPeriod.ts +56 -0
  8. package/example/src/chevre/lockStockHolder.ts +5 -2
  9. package/example/src/chevre/migrateCategoryCodeAdditionalProperties.ts +116 -0
  10. package/example/src/chevre/migrateScreeningEventSeriesVersion.ts +79 -0
  11. package/example/src/chevre/processRegisterMembership.ts +8 -4
  12. package/example/src/chevre/processRegisterPaymentCard.ts +8 -4
  13. package/example/src/chevre/processReserve.ts +1 -1
  14. package/example/src/chevre/searchAbortedTasks.ts +4 -6
  15. package/example/src/chevre/searchEventSeats.ts +5 -2
  16. package/example/src/chevre/searchHoldReservations.ts +38 -0
  17. package/example/src/chevre/searchPermissions.ts +54 -0
  18. package/example/src/chevre/searchScreeningRooms.ts +35 -0
  19. package/example/src/chevre/sendEmailMessage.ts +1 -2
  20. package/example/src/chevre/syncScreeningRooms.ts +22 -0
  21. package/example/src/chevre/syncScreeningRoomsAll.ts +44 -0
  22. package/example/src/chevre/unsetContainsInPlaceFromMovieTheater.ts +41 -0
  23. package/lib/chevre/factory/order.d.ts +4 -1
  24. package/lib/chevre/factory/order.js +19 -6
  25. package/lib/chevre/repo/account.js +3 -2
  26. package/lib/chevre/repo/accountTransaction.js +2 -1
  27. package/lib/chevre/repo/accountingReport.d.ts +1 -3
  28. package/lib/chevre/repo/action.d.ts +50 -1
  29. package/lib/chevre/repo/action.js +53 -2
  30. package/lib/chevre/repo/additionalProperty.js +2 -1
  31. package/lib/chevre/repo/aggregation.d.ts +3 -0
  32. package/lib/chevre/repo/aggregation.js +3 -0
  33. package/lib/chevre/repo/assetTransaction.js +6 -5
  34. package/lib/chevre/repo/categoryCode.d.ts +1 -1
  35. package/lib/chevre/repo/categoryCode.js +37 -25
  36. package/lib/chevre/repo/code.js +3 -2
  37. package/lib/chevre/repo/comment.js +2 -1
  38. package/lib/chevre/repo/creativeWork.d.ts +1 -1
  39. package/lib/chevre/repo/creativeWork.js +35 -12
  40. package/lib/chevre/repo/customer.js +2 -1
  41. package/lib/chevre/repo/emailMessage.js +2 -1
  42. package/lib/chevre/repo/event.d.ts +30 -2
  43. package/lib/chevre/repo/event.js +87 -36
  44. package/lib/chevre/repo/member.d.ts +14 -0
  45. package/lib/chevre/repo/member.js +31 -3
  46. package/lib/chevre/repo/merchantReturnPolicy.js +2 -1
  47. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +3 -3
  48. package/lib/chevre/repo/mongoose/schemas/holdReservation.d.ts +75 -0
  49. package/lib/chevre/repo/mongoose/schemas/holdReservation.js +93 -0
  50. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +3 -3
  51. package/lib/chevre/repo/mongoose/schemas/order.d.ts +21 -21
  52. package/lib/chevre/repo/mongoose/schemas/place.d.ts +6 -0
  53. package/lib/chevre/repo/mongoose/schemas/place.js +16 -1
  54. package/lib/chevre/repo/mongoose/schemas/product.js +6 -0
  55. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +9 -9
  56. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +3 -3
  57. package/lib/chevre/repo/offer.js +3 -2
  58. package/lib/chevre/repo/offerCatalog.js +0 -27
  59. package/lib/chevre/repo/offerItemCondition.js +2 -1
  60. package/lib/chevre/repo/order.js +8 -7
  61. package/lib/chevre/repo/ownershipInfo.js +2 -7
  62. package/lib/chevre/repo/paymentServiceProvider.d.ts +65 -0
  63. package/lib/chevre/repo/paymentServiceProvider.js +156 -0
  64. package/lib/chevre/repo/place.d.ts +203 -27
  65. package/lib/chevre/repo/place.js +1726 -694
  66. package/lib/chevre/repo/priceSpecification.js +3 -2
  67. package/lib/chevre/repo/product.d.ts +5 -3
  68. package/lib/chevre/repo/product.js +92 -5
  69. package/lib/chevre/repo/project.js +2 -1
  70. package/lib/chevre/repo/reservation.d.ts +9 -1
  71. package/lib/chevre/repo/reservation.js +29 -20
  72. package/lib/chevre/repo/role.d.ts +7 -0
  73. package/lib/chevre/repo/role.js +39 -2
  74. package/lib/chevre/repo/seller.d.ts +21 -1
  75. package/lib/chevre/repo/seller.js +59 -4
  76. package/lib/chevre/repo/serviceOutput.js +2 -1
  77. package/lib/chevre/repo/stockHolder.d.ts +143 -7
  78. package/lib/chevre/repo/stockHolder.js +622 -104
  79. package/lib/chevre/repo/task.d.ts +12 -1
  80. package/lib/chevre/repo/task.js +17 -7
  81. package/lib/chevre/repo/transaction.js +6 -5
  82. package/lib/chevre/repo/trip.js +2 -1
  83. package/lib/chevre/repository.d.ts +6 -0
  84. package/lib/chevre/repository.js +8 -1
  85. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +18 -8
  86. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +19 -8
  87. package/lib/chevre/service/aggregation/system.d.ts +43 -1
  88. package/lib/chevre/service/aggregation/system.js +112 -2
  89. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  90. package/lib/chevre/service/assetTransaction/pay/account/validation.js +1 -1
  91. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  92. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  93. package/lib/chevre/service/assetTransaction/reserve.js +10 -3
  94. package/lib/chevre/service/event.d.ts +3 -0
  95. package/lib/chevre/service/event.js +52 -21
  96. package/lib/chevre/service/iam.d.ts +6 -2
  97. package/lib/chevre/service/iam.js +23 -9
  98. package/lib/chevre/service/offer/event/factory.js +22 -13
  99. package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
  100. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +15 -8
  101. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -9
  102. package/lib/chevre/service/offer/product/factory.js +13 -6
  103. package/lib/chevre/service/offer/product.js +2 -2
  104. package/lib/chevre/service/offer.d.ts +16 -8
  105. package/lib/chevre/service/offer.js +71 -8
  106. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +31 -17
  107. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +1 -1
  108. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -2
  109. package/lib/chevre/service/order/placeOrder.js +4 -4
  110. package/lib/chevre/service/order/returnOrder.js +1 -1
  111. package/lib/chevre/service/order/sendOrder.js +3 -3
  112. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +4 -6
  113. package/lib/chevre/service/payment/any/onRefund.js +46 -42
  114. package/lib/chevre/service/payment/creditCard.js +2 -2
  115. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +1 -1
  116. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  117. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +1 -1
  118. package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -1
  119. package/lib/chevre/service/payment/movieTicket/validation.js +16 -9
  120. package/lib/chevre/service/payment/movieTicket.js +2 -2
  121. package/lib/chevre/service/reserve/cancelReservation.js +15 -3
  122. package/lib/chevre/service/reserve/confirmReservation.js +19 -11
  123. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  124. package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
  125. package/lib/chevre/service/task/cancelReservation.js +1 -1
  126. package/lib/chevre/service/task/deleteTransaction.js +2 -0
  127. package/lib/chevre/service/task/onEventChanged.d.ts +7 -0
  128. package/lib/chevre/service/task/onEventChanged.js +29 -0
  129. package/lib/chevre/service/task/onResourceUpdated.d.ts +7 -0
  130. package/lib/chevre/service/task/onResourceUpdated.js +396 -0
  131. package/lib/chevre/service/task/syncScreeningRooms.d.ts +7 -0
  132. package/lib/chevre/service/task/syncScreeningRooms.js +24 -0
  133. package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
  134. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  135. package/lib/chevre/service/transaction/deleteTransaction.js +129 -1
  136. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +1 -0
  137. package/lib/chevre/service/transaction/moneyTransfer/factory.d.ts +1 -1
  138. package/lib/chevre/service/transaction/moneyTransfer.js +1 -1
  139. package/lib/chevre/service/transaction/orderProgramMembership/findCreditCard.js +1 -1
  140. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +1 -1
  141. package/lib/chevre/service/transaction/orderProgramMembership.js +1 -1
  142. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +1 -0
  143. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/givePointAward.js +1 -1
  144. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  145. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  146. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.js +4 -4
  147. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +3 -4
  148. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +8 -12
  149. package/lib/chevre/service/transaction/placeOrderInProgress.js +6 -4
  150. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +1 -0
  151. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +2 -2
  152. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +5 -5
  153. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +2 -2
  154. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +3 -3
  155. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +1 -1
  156. package/lib/chevre/service/transaction/returnOrder.js +3 -1
  157. package/lib/chevre/settings.d.ts +11 -0
  158. package/lib/chevre/settings.js +44 -2
  159. package/package.json +3 -3
  160. package/example/src/chevre/eventCatalog2eventService.ts +0 -123
  161. package/example/src/chevre/migrateOrderAdditionalProperties.ts +0 -85
  162. package/example/src/chevre/migrateStockHolderKeys.ts +0 -89
@@ -21,9 +21,12 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
+ const createDebug = require("debug");
24
25
  const mongoose_1 = require("mongoose");
25
26
  const place_1 = require("./mongoose/schemas/place");
26
27
  const factory = require("../factory");
28
+ const settings_1 = require("../settings");
29
+ const debug = createDebug('chevre-domain:repo:place');
27
30
  /**
28
31
  * 施設リポジトリ
29
32
  */
@@ -220,7 +223,16 @@ class MongoRepository {
220
223
  else {
221
224
  // 上書き禁止属性を除外(2022-08-24~)
222
225
  const { id, branchCode, project, typeOf } = params, updateFields = __rest(params, ["id", "branchCode", "project", "typeOf"]);
223
- doc = yield this.placeModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
226
+ doc = yield this.placeModel.findOneAndUpdate({ _id: params.id }, updateFields, {
227
+ upsert: false,
228
+ new: true,
229
+ projection: {
230
+ __v: 0,
231
+ createdAt: 0,
232
+ updatedAt: 0,
233
+ containsPlace: 0
234
+ }
235
+ })
224
236
  .exec();
225
237
  }
226
238
  if (doc === null) {
@@ -229,50 +241,115 @@ class MongoRepository {
229
241
  return doc.toObject();
230
242
  });
231
243
  }
244
+ // void化(2023-06-23~)
232
245
  saveMovieTheaterByBranchCode4coa(params) {
233
246
  return __awaiter(this, void 0, void 0, function* () {
234
- return this.placeModel.findOneAndUpdate({
235
- 'project.id': { $eq: params.project.id },
236
- branchCode: { $eq: params.branchCode }
237
- }, params, { new: true })
238
- .exec()
239
- .then((doc) => {
240
- if (doc === null) {
241
- throw new factory.errors.NotFound(`${factory.placeType.MovieTheater} ${params.branchCode}`);
242
- }
243
- return doc.toObject();
244
- });
245
- });
246
- }
247
- findMovieTheaterByBranchCode(params) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- return this.placeModel.findOne({
247
+ const { containsPlace } = params, movieTheater4update = __rest(params, ["containsPlace"]);
248
+ const movieTheaterDoc = yield this.placeModel.findOneAndUpdate({
250
249
  typeOf: { $eq: factory.placeType.MovieTheater },
251
250
  'project.id': { $eq: params.project.id },
252
251
  branchCode: { $eq: params.branchCode }
253
- }, {
254
- __v: 0,
255
- createdAt: 0,
256
- updatedAt: 0
252
+ },
253
+ // containsPlaceの保管を廃止(2023-07-04~)
254
+ // params,
255
+ movieTheater4update, {
256
+ new: true,
257
+ projection: { _id: 1 }
257
258
  })
258
- .exec()
259
- .then((doc) => {
260
- if (doc === null) {
261
- throw new factory.errors.NotFound(`${factory.placeType.MovieTheater} ${params.branchCode}`);
262
- }
263
- return doc.toObject();
259
+ .exec();
260
+ if (movieTheaterDoc === null) {
261
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
262
+ }
263
+ const movieTheater = movieTheaterDoc.toObject();
264
+ // ScreeningRoomも保管する(2023-06-24~)
265
+ const creatingScreeningRooms = params.containsPlace.map((place) => {
266
+ return Object.assign(Object.assign({}, place), { containedInPlace: {
267
+ id: movieTheater.id,
268
+ typeOf: params.typeOf,
269
+ branchCode: params.branchCode,
270
+ name: params.name
271
+ }, containsPlace: (Array.isArray(place.containsPlace)) ? place.containsPlace : [], project: params.project });
264
272
  });
273
+ yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
274
+ const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
275
+ if (typeof branchCode === 'string' && branchCode.length > 0) {
276
+ yield this.placeModel.findOneAndUpdate({
277
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
278
+ 'project.id': { $eq: createScreeningRoom.project.id },
279
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
280
+ branchCode: { $eq: createScreeningRoom.branchCode }
281
+ }, {
282
+ $setOnInsert: {
283
+ typeOf: createScreeningRoom.typeOf,
284
+ project: createScreeningRoom.project,
285
+ branchCode: createScreeningRoom.branchCode
286
+ },
287
+ $set: setFields
288
+ }, {
289
+ upsert: true,
290
+ new: true,
291
+ projection: { _id: 1 }
292
+ })
293
+ .exec();
294
+ }
295
+ })));
265
296
  });
266
297
  }
298
+ // 廃止(2023-06-23~)
299
+ // public async findMovieTheaterByBranchCode(params: {
300
+ // project: { id: string };
301
+ // branchCode: string;
302
+ // }): Promise<factory.place.movieTheater.IPlace> {
303
+ // return this.placeModel.findOne(
304
+ // {
305
+ // typeOf: { $eq: factory.placeType.MovieTheater },
306
+ // 'project.id': { $eq: params.project.id },
307
+ // branchCode: { $eq: params.branchCode }
308
+ // },
309
+ // {
310
+ // __v: 0,
311
+ // createdAt: 0,
312
+ // updatedAt: 0
313
+ // }
314
+ // )
315
+ // .exec()
316
+ // .then((doc) => {
317
+ // if (doc === null) {
318
+ // throw new factory.errors.NotFound(`${factory.placeType.MovieTheater} ${params.branchCode}`);
319
+ // }
320
+ // return doc.toObject();
321
+ // });
322
+ // }
267
323
  /**
268
324
  * 施設検索
269
325
  */
270
- searchMovieTheaters(params) {
326
+ searchMovieTheaters(params,
327
+ // projection明示指定化(2023-06-22~)
328
+ inclusion, exclusion) {
271
329
  var _a;
272
330
  return __awaiter(this, void 0, void 0, function* () {
273
331
  const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
274
- // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
275
- const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0, containsPlace: 0 }, params.$projection));
332
+ let projection = {};
333
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
334
+ inclusion.forEach((field) => {
335
+ projection[field] = 1;
336
+ });
337
+ }
338
+ else {
339
+ projection = {
340
+ __v: 0,
341
+ createdAt: 0,
342
+ updatedAt: 0,
343
+ // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
344
+ containsPlace: 0
345
+ };
346
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
347
+ exclusion.forEach((field) => {
348
+ projection[field] = 0;
349
+ });
350
+ }
351
+ }
352
+ const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
276
353
  if (typeof params.limit === 'number' && params.limit > 0) {
277
354
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
278
355
  query.limit(params.limit)
@@ -283,33 +360,56 @@ class MongoRepository {
283
360
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
284
361
  query.sort({ branchCode: params.sort.branchCode });
285
362
  }
286
- return query.setOptions({ maxTimeMS: 10000 })
363
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
287
364
  .exec()
288
365
  .then((docs) => docs.map((doc) => doc.toObject()));
289
366
  });
290
367
  }
291
368
  /**
292
369
  * 施設取得
370
+ * 廃止(2023-06-22~)
293
371
  */
294
- findById(params, projection) {
295
- return __awaiter(this, void 0, void 0, function* () {
296
- const doc = yield this.placeModel.findOne({
297
- typeOf: { $eq: factory.placeType.MovieTheater },
298
- _id: { $eq: params.id }
299
- }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
300
- .exec();
301
- if (doc === null) {
302
- throw new factory.errors.NotFound(this.placeModel.modelName);
303
- }
304
- return doc.toObject();
305
- });
306
- }
372
+ // public async findById(
373
+ // params: { id: string },
374
+ // inclusion: string[],
375
+ // exclusion: string[]
376
+ // ): Promise<factory.place.movieTheater.IPlace> {
377
+ // let projection: { [key: string]: number } = {};
378
+ // if (Array.isArray(inclusion) && inclusion.length > 0) {
379
+ // inclusion.forEach((field) => {
380
+ // projection[field] = 1;
381
+ // });
382
+ // } else {
383
+ // projection = {
384
+ // __v: 0,
385
+ // createdAt: 0,
386
+ // updatedAt: 0
387
+ // };
388
+ // if (Array.isArray(exclusion) && exclusion.length > 0) {
389
+ // exclusion.forEach((field) => {
390
+ // projection[field] = 0;
391
+ // });
392
+ // }
393
+ // }
394
+ // const doc = await this.placeModel.findOne(
395
+ // {
396
+ // typeOf: { $eq: factory.placeType.MovieTheater },
397
+ // _id: { $eq: params.id }
398
+ // },
399
+ // projection
400
+ // )
401
+ // .exec();
402
+ // if (doc === null) {
403
+ // throw new factory.errors.NotFound(this.placeModel.modelName);
404
+ // }
405
+ // return doc.toObject();
406
+ // }
307
407
  deleteMovieTheaterById(params) {
308
408
  return __awaiter(this, void 0, void 0, function* () {
309
409
  yield this.placeModel.findOneAndDelete({
310
410
  typeOf: { $eq: factory.placeType.MovieTheater },
311
411
  _id: { $eq: params.id }
312
- })
412
+ }, { projection: { _id: 1 } })
313
413
  .exec()
314
414
  .then((doc) => {
315
415
  if (doc === null) {
@@ -318,98 +418,212 @@ class MongoRepository {
318
418
  });
319
419
  });
320
420
  }
321
- createScreeningRoom(screeningRoom) {
421
+ createScreeningRoom(screeningRoom, useScreeningRoomType) {
322
422
  return __awaiter(this, void 0, void 0, function* () {
323
423
  // 施設存在確認
324
424
  let doc = yield this.placeModel.findOne({
425
+ typeOf: { $eq: factory.placeType.MovieTheater },
325
426
  'project.id': { $eq: screeningRoom.project.id },
326
- branchCode: screeningRoom.containedInPlace.branchCode
327
- }, {
328
- _id: 1
329
- })
427
+ branchCode: { $eq: screeningRoom.containedInPlace.branchCode }
428
+ }, { _id: 1, typeOf: 1, branchCode: 1, name: 1 })
330
429
  .exec();
331
430
  if (doc === null) {
332
- throw new factory.errors.NotFound('containedInPlace');
431
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
333
432
  }
334
- // ルームコードが存在しなければ追加する
335
- doc = yield this.placeModel.findOneAndUpdate({
336
- 'project.id': { $eq: screeningRoom.project.id },
337
- branchCode: screeningRoom.containedInPlace.branchCode,
338
- 'containsPlace.branchCode': { $ne: screeningRoom.branchCode }
339
- }, {
340
- $push: {
341
- containsPlace: {
342
- typeOf: screeningRoom.typeOf,
343
- branchCode: screeningRoom.branchCode,
344
- name: screeningRoom.name,
345
- address: screeningRoom.address,
346
- additionalProperty: screeningRoom.additionalProperty
347
- }
433
+ if (useScreeningRoomType === true) {
434
+ const movieTheater = doc.toObject();
435
+ const creatingScreeningRoom = Object.assign({ typeOf: screeningRoom.typeOf, branchCode: screeningRoom.branchCode, name: screeningRoom.name, address: screeningRoom.address, additionalProperty: (Array.isArray(screeningRoom.additionalProperty)) ? screeningRoom.additionalProperty : [], containedInPlace: {
436
+ id: movieTheater.id,
437
+ typeOf: movieTheater.typeOf,
438
+ branchCode: movieTheater.branchCode,
439
+ name: movieTheater.name
440
+ }, containsPlace: [], project: screeningRoom.project }, (typeof screeningRoom.openSeatingAllowed === 'boolean')
441
+ ? { openSeatingAllowed: screeningRoom.openSeatingAllowed }
442
+ : undefined);
443
+ const upsertScreeningRoomResult = yield this.placeModel.updateOne({
444
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
445
+ 'project.id': { $eq: creatingScreeningRoom.project.id },
446
+ 'containedInPlace.id': { $exists: true, $eq: creatingScreeningRoom.containedInPlace.id },
447
+ branchCode: { $eq: creatingScreeningRoom.branchCode }
448
+ },
449
+ // 既存であれば何もしない
450
+ { $setOnInsert: creatingScreeningRoom }, { upsert: true })
451
+ .exec();
452
+ // 既存であればコード重複
453
+ if (upsertScreeningRoomResult.matchedCount > 0) {
454
+ throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoom, ['branchCode']);
348
455
  }
349
- }, {
350
- new: true,
351
- projection: {
352
- _id: 1,
353
- 'project.id': 1,
354
- branchCode: 1
456
+ return {
457
+ containedInPlace: { id: creatingScreeningRoom.containedInPlace.id },
458
+ typeOf: factory.placeType.ScreeningRoom
459
+ };
460
+ }
461
+ else {
462
+ // ルームコードが存在しなければ追加する
463
+ doc = yield this.placeModel.findOneAndUpdate({
464
+ typeOf: { $eq: factory.placeType.MovieTheater },
465
+ 'project.id': { $eq: screeningRoom.project.id },
466
+ branchCode: screeningRoom.containedInPlace.branchCode,
467
+ 'containsPlace.branchCode': { $ne: screeningRoom.branchCode }
468
+ }, {
469
+ $push: {
470
+ containsPlace: {
471
+ typeOf: screeningRoom.typeOf,
472
+ branchCode: screeningRoom.branchCode,
473
+ name: screeningRoom.name,
474
+ address: screeningRoom.address,
475
+ additionalProperty: screeningRoom.additionalProperty
476
+ }
477
+ }
478
+ }, {
479
+ new: true,
480
+ projection: {
481
+ _id: 1,
482
+ branchCode: 1,
483
+ typeOf: 1
484
+ }
485
+ })
486
+ .exec();
487
+ // 存在しなければコード重複
488
+ if (doc === null) {
489
+ throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoom, ['branchCode']);
355
490
  }
356
- })
357
- .exec();
358
- // 存在しなければコード重複
359
- if (doc === null) {
360
- throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoom, ['branchCode']);
491
+ return doc.toObject();
361
492
  }
362
493
  });
363
494
  }
364
- updateScreeningRoom(screeningRoom, $unset) {
495
+ updateScreeningRoom(screeningRoom, $unset, useScreeningRoomType) {
365
496
  return __awaiter(this, void 0, void 0, function* () {
366
- const doc = yield this.placeModel.findOneAndUpdate({
367
- 'project.id': { $eq: screeningRoom.project.id },
368
- branchCode: screeningRoom.containedInPlace.branchCode,
369
- 'containsPlace.branchCode': screeningRoom.branchCode
370
- }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].name': screeningRoom.name }, (screeningRoom.address !== undefined && screeningRoom.address !== null)
371
- ? { 'containsPlace.$[screeningRoom].address': screeningRoom.address }
372
- : undefined), (typeof screeningRoom.openSeatingAllowed === 'boolean')
373
- ? { 'containsPlace.$[screeningRoom].openSeatingAllowed': screeningRoom.openSeatingAllowed }
374
- : undefined), (Array.isArray(screeningRoom.additionalProperty))
375
- ? { 'containsPlace.$[screeningRoom].additionalProperty': screeningRoom.additionalProperty }
376
- : undefined), ($unset !== undefined && $unset !== null)
377
- ? { $unset }
378
- : undefined), {
379
- new: true,
380
- arrayFilters: [
381
- { 'screeningRoom.branchCode': screeningRoom.branchCode }
382
- ],
383
- projection: {
384
- _id: 1,
385
- 'project.id': 1,
386
- branchCode: 1
497
+ if (useScreeningRoomType === true) {
498
+ const doc = yield this.placeModel.findOneAndUpdate({
499
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
500
+ 'project.id': { $eq: screeningRoom.project.id },
501
+ 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode },
502
+ branchCode: screeningRoom.branchCode
503
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ name: screeningRoom.name }, (screeningRoom.address !== undefined && screeningRoom.address !== null)
504
+ ? { address: screeningRoom.address }
505
+ : undefined), (typeof screeningRoom.openSeatingAllowed === 'boolean')
506
+ ? { openSeatingAllowed: screeningRoom.openSeatingAllowed }
507
+ : undefined), (Array.isArray(screeningRoom.additionalProperty))
508
+ ? { additionalProperty: screeningRoom.additionalProperty }
509
+ : undefined), (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].openSeatingAllowed']) === 1
510
+ || $unset.openSeatingAllowed === 1)
511
+ ? {
512
+ $unset: {
513
+ openSeatingAllowed: 1
514
+ }
515
+ }
516
+ : undefined), {
517
+ new: true,
518
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
519
+ })
520
+ .exec();
521
+ if (doc === null) {
522
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
387
523
  }
388
- })
389
- .exec();
390
- if (doc === null) {
391
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
524
+ return doc.toObject();
525
+ }
526
+ else {
527
+ const doc = yield this.placeModel.findOneAndUpdate({
528
+ typeOf: { $eq: factory.placeType.MovieTheater },
529
+ 'project.id': { $eq: screeningRoom.project.id },
530
+ branchCode: screeningRoom.containedInPlace.branchCode,
531
+ 'containsPlace.branchCode': screeningRoom.branchCode
532
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].name': screeningRoom.name }, (screeningRoom.address !== undefined && screeningRoom.address !== null)
533
+ ? { 'containsPlace.$[screeningRoom].address': screeningRoom.address }
534
+ : undefined), (typeof screeningRoom.openSeatingAllowed === 'boolean')
535
+ ? { 'containsPlace.$[screeningRoom].openSeatingAllowed': screeningRoom.openSeatingAllowed }
536
+ : undefined), (Array.isArray(screeningRoom.additionalProperty))
537
+ ? { 'containsPlace.$[screeningRoom].additionalProperty': screeningRoom.additionalProperty }
538
+ : undefined), ($unset !== undefined && $unset !== null)
539
+ ? { $unset }
540
+ : undefined), {
541
+ new: true,
542
+ arrayFilters: [
543
+ { 'screeningRoom.branchCode': screeningRoom.branchCode }
544
+ ],
545
+ projection: {
546
+ _id: 1,
547
+ branchCode: 1,
548
+ typeOf: 1
549
+ }
550
+ })
551
+ .exec();
552
+ if (doc === null) {
553
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
554
+ }
555
+ return doc.toObject();
556
+ }
557
+ });
558
+ }
559
+ updateScreeningRoomsByContainedInPlaceId(screeningRoom) {
560
+ var _a;
561
+ return __awaiter(this, void 0, void 0, function* () {
562
+ if (typeof ((_a = screeningRoom.containedInPlace.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string') {
563
+ yield this.placeModel.updateMany({
564
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
565
+ 'project.id': { $eq: screeningRoom.project.id },
566
+ 'containedInPlace.id': { $exists: true, $eq: screeningRoom.containedInPlace.id }
567
+ }, {
568
+ 'containedInPlace.name': screeningRoom.containedInPlace.name
569
+ })
570
+ .exec();
392
571
  }
393
572
  });
394
573
  }
395
- deleteScreeningRoom(screeningRoom) {
574
+ deleteScreeningRoom(screeningRoom, useScreeningRoomType) {
396
575
  return __awaiter(this, void 0, void 0, function* () {
397
- const doc = yield this.placeModel.findOneAndUpdate({
398
- 'project.id': { $eq: screeningRoom.project.id },
399
- branchCode: screeningRoom.containedInPlace.branchCode,
400
- 'containsPlace.branchCode': screeningRoom.branchCode
401
- }, {
402
- $pull: {
403
- containsPlace: { branchCode: screeningRoom.branchCode }
576
+ if (useScreeningRoomType === true) {
577
+ const doc = yield this.placeModel.findOneAndDelete({
578
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
579
+ 'project.id': { $eq: screeningRoom.project.id },
580
+ 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode },
581
+ branchCode: screeningRoom.branchCode
582
+ }, {
583
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
584
+ })
585
+ .exec();
586
+ if (doc === null) {
587
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
588
+ }
589
+ return doc.toObject();
590
+ }
591
+ else {
592
+ const doc = yield this.placeModel.findOneAndUpdate({
593
+ typeOf: { $eq: factory.placeType.MovieTheater },
594
+ 'project.id': { $eq: screeningRoom.project.id },
595
+ branchCode: screeningRoom.containedInPlace.branchCode,
596
+ 'containsPlace.branchCode': screeningRoom.branchCode
597
+ }, {
598
+ $pull: {
599
+ containsPlace: { branchCode: screeningRoom.branchCode }
600
+ }
601
+ }, {
602
+ projection: {
603
+ _id: 1,
604
+ typeOf: 1
605
+ }
606
+ })
607
+ .exec();
608
+ if (doc === null) {
609
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
404
610
  }
611
+ return doc.toObject();
612
+ }
613
+ });
614
+ }
615
+ deleteScreeningRoomsByMovieTheaterId(params) {
616
+ return __awaiter(this, void 0, void 0, function* () {
617
+ yield this.placeModel.deleteMany({
618
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
619
+ 'project.id': { $eq: params.project.id },
620
+ 'containedInPlace.id': { $exists: true, $eq: params.containedInPlace.id }
405
621
  })
406
622
  .exec();
407
- if (doc === null) {
408
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
409
- }
410
623
  });
411
624
  }
412
- createScreeningRoomSection(screeningRoomSection) {
625
+ // tslint:disable-next-line:max-func-body-length
626
+ createScreeningRoomSection(screeningRoomSection, useScreeningRoomType) {
413
627
  return __awaiter(this, void 0, void 0, function* () {
414
628
  const screeningRoom = screeningRoomSection.containedInPlace;
415
629
  if (typeof (screeningRoom === null || screeningRoom === void 0 ? void 0 : screeningRoom.branchCode) !== 'string') {
@@ -421,45 +635,75 @@ class MongoRepository {
421
635
  }
422
636
  // 施設存在確認
423
637
  let doc = yield this.placeModel.findOne({
638
+ typeOf: { $eq: factory.placeType.MovieTheater },
424
639
  'project.id': { $eq: screeningRoomSection.project.id },
425
- branchCode: movieTheater.branchCode,
426
- 'containsPlace.branchCode': screeningRoom.branchCode
640
+ branchCode: { $eq: movieTheater.branchCode }
427
641
  }, { _id: 1 })
428
642
  .exec();
429
643
  if (doc === null) {
430
644
  throw new factory.errors.NotFound(factory.placeType.MovieTheater);
431
645
  }
432
- doc = yield this.placeModel.findOneAndUpdate({
433
- 'project.id': { $eq: screeningRoomSection.project.id },
434
- branchCode: movieTheater.branchCode,
435
- 'containsPlace.branchCode': screeningRoom.branchCode
436
- // 'containsPlace.containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
437
- }, {
438
- $push: {
439
- 'containsPlace.$[screeningRoom].containsPlace': Object.assign({ typeOf: screeningRoomSection.typeOf, branchCode: screeningRoomSection.branchCode, name: screeningRoomSection.name }, (Array.isArray(screeningRoomSection.additionalProperty))
440
- ? { additionalProperty: screeningRoomSection.additionalProperty }
441
- : undefined)
646
+ if (useScreeningRoomType === true) {
647
+ // セクションコードが存在しなければ追加する
648
+ doc = yield this.placeModel.findOneAndUpdate({
649
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
650
+ 'project.id': { $eq: screeningRoomSection.project.id },
651
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
652
+ branchCode: { $eq: screeningRoom.branchCode },
653
+ 'containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
654
+ }, {
655
+ $push: {
656
+ containsPlace: Object.assign({ typeOf: screeningRoomSection.typeOf, branchCode: screeningRoomSection.branchCode, name: screeningRoomSection.name }, (Array.isArray(screeningRoomSection.additionalProperty))
657
+ ? { additionalProperty: screeningRoomSection.additionalProperty }
658
+ : undefined)
659
+ }
660
+ }, {
661
+ new: true,
662
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
663
+ })
664
+ .exec();
665
+ // 存在しなければコード重複
666
+ if (doc === null) {
667
+ throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoomSection, ['branchCode']);
442
668
  }
443
- }, {
444
- new: true,
445
- arrayFilters: [
446
- {
447
- 'screeningRoom.branchCode': screeningRoom.branchCode,
448
- 'screeningRoom.containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
669
+ return doc.toObject();
670
+ }
671
+ else {
672
+ doc = yield this.placeModel.findOneAndUpdate({
673
+ typeOf: { $eq: factory.placeType.MovieTheater },
674
+ 'project.id': { $eq: screeningRoomSection.project.id },
675
+ branchCode: movieTheater.branchCode,
676
+ 'containsPlace.branchCode': screeningRoom.branchCode
677
+ }, {
678
+ $push: {
679
+ 'containsPlace.$[screeningRoom].containsPlace': Object.assign({ typeOf: screeningRoomSection.typeOf, branchCode: screeningRoomSection.branchCode, name: screeningRoomSection.name }, (Array.isArray(screeningRoomSection.additionalProperty))
680
+ ? { additionalProperty: screeningRoomSection.additionalProperty }
681
+ : undefined)
682
+ }
683
+ }, {
684
+ new: true,
685
+ arrayFilters: [
686
+ {
687
+ 'screeningRoom.branchCode': screeningRoom.branchCode,
688
+ 'screeningRoom.containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
689
+ }
690
+ ],
691
+ projection: {
692
+ _id: 1,
693
+ typeOf: 1
449
694
  }
450
- ],
451
- projection: {
452
- _id: 1
695
+ })
696
+ .exec();
697
+ // 存在しなければコード重複
698
+ if (doc === null) {
699
+ throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoomSection, ['branchCode']);
453
700
  }
454
- })
455
- .exec();
456
- // 存在しなければコード重複
457
- if (doc === null) {
458
- throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoomSection, ['branchCode']);
701
+ return doc.toObject();
459
702
  }
460
703
  });
461
704
  }
462
- updateScreeningRoomSection(screeningRoomSection, $unset) {
705
+ // tslint:disable-next-line:max-func-body-length
706
+ updateScreeningRoomSection(screeningRoomSection, $unset, useScreeningRoomType) {
463
707
  return __awaiter(this, void 0, void 0, function* () {
464
708
  const screeningRoom = screeningRoomSection.containedInPlace;
465
709
  if (typeof (screeningRoom === null || screeningRoom === void 0 ? void 0 : screeningRoom.branchCode) !== 'string') {
@@ -469,317 +713,768 @@ class MongoRepository {
469
713
  if (typeof (movieTheater === null || movieTheater === void 0 ? void 0 : movieTheater.branchCode) !== 'string') {
470
714
  throw new factory.errors.ArgumentNull('containedInPlace.containedInPlace.branchCode');
471
715
  }
472
- const doc = yield this.placeModel.findOneAndUpdate({
473
- 'project.id': { $eq: screeningRoomSection.project.id },
474
- branchCode: movieTheater.branchCode,
475
- 'containsPlace.branchCode': screeningRoom.branchCode,
476
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
477
- }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].branchCode': screeningRoomSection.branchCode }, (screeningRoomSection.name !== undefined && screeningRoomSection !== null)
478
- ? {
479
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].name': screeningRoomSection.name
480
- }
481
- : undefined), (Array.isArray(screeningRoomSection.additionalProperty))
482
- ? {
483
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].additionalProperty': screeningRoomSection.additionalProperty
484
- }
485
- : undefined), (Array.isArray(screeningRoomSection.containsPlace) && screeningRoomSection.containsPlace.length > 0)
486
- ? {
487
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': screeningRoomSection.containsPlace.map((p) => {
488
- return Object.assign(Object.assign(Object.assign({ typeOf: p.typeOf, branchCode: p.branchCode }, (p.name !== undefined && p.name !== null) ? { name: p.name } : undefined), (Array.isArray(p.seatingType)) ? { seatingType: p.seatingType } : undefined), (Array.isArray(p.additionalProperty)) ? { additionalProperty: p.additionalProperty } : undefined);
489
- })
490
- }
491
- : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
492
- new: true,
493
- arrayFilters: [
494
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
495
- { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
496
- ],
497
- projection: {
498
- _id: 1
499
- }
500
- })
501
- .exec();
502
- if (doc === null) {
503
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
504
- }
505
- });
506
- }
507
- // tslint:disable-next-line:max-func-body-length
508
- searchScreeningRoomSections(searchConditions) {
509
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
510
- return __awaiter(this, void 0, void 0, function* () {
511
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
512
- const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
513
- if (typeof projectIdEq === 'string') {
514
- matchStages.push({
515
- $match: { 'project.id': { $eq: projectIdEq } }
516
- });
517
- }
518
- // 施設コード
519
- const movieTheaterBranchCodeEq = (_e = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
520
- if (typeof movieTheaterBranchCodeEq === 'string') {
521
- matchStages.push({
522
- $match: {
523
- branchCode: {
524
- $exists: true,
525
- $eq: movieTheaterBranchCodeEq
526
- }
716
+ if (useScreeningRoomType === true) {
717
+ const doc = yield this.placeModel.findOneAndUpdate({
718
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
719
+ 'project.id': { $eq: screeningRoomSection.project.id },
720
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
721
+ branchCode: { $eq: screeningRoom.branchCode },
722
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
723
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoomSection].branchCode': screeningRoomSection.branchCode }, (screeningRoomSection.name !== undefined && screeningRoomSection !== null)
724
+ ? {
725
+ 'containsPlace.$[screeningRoomSection].name': screeningRoomSection.name
527
726
  }
528
- });
529
- }
530
- // ルームコード
531
- const containedInPlaceBranchCodeEq = (_g = (_f = searchConditions.containedInPlace) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
532
- if (typeof containedInPlaceBranchCodeEq === 'string') {
533
- matchStages.push({
534
- $match: {
535
- 'containsPlace.branchCode': {
536
- $exists: true,
537
- $eq: containedInPlaceBranchCodeEq
538
- }
727
+ : undefined), (Array.isArray(screeningRoomSection.additionalProperty))
728
+ ? {
729
+ 'containsPlace.$[screeningRoomSection].additionalProperty': screeningRoomSection.additionalProperty
539
730
  }
540
- });
541
- }
542
- // セクションコード
543
- const sectionBranchCodeEq = (_h = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
544
- if (typeof sectionBranchCodeEq === 'string') {
545
- matchStages.push({
546
- $match: {
547
- 'containsPlace.containsPlace.branchCode': {
548
- $exists: true,
549
- $eq: sectionBranchCodeEq
550
- }
731
+ : undefined), (Array.isArray(screeningRoomSection.containsPlace) && screeningRoomSection.containsPlace.length > 0)
732
+ ? {
733
+ 'containsPlace.$[screeningRoomSection].containsPlace': screeningRoomSection.containsPlace.map((p) => {
734
+ return Object.assign(Object.assign(Object.assign({ typeOf: p.typeOf, branchCode: p.branchCode }, (p.name !== undefined && p.name !== null) ? { name: p.name } : undefined), (Array.isArray(p.seatingType)) ? { seatingType: p.seatingType } : undefined), (Array.isArray(p.additionalProperty)) ? { additionalProperty: p.additionalProperty } : undefined);
735
+ })
551
736
  }
552
- });
737
+ : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
738
+ new: true,
739
+ arrayFilters: [
740
+ { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
741
+ ],
742
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
743
+ })
744
+ .exec();
745
+ if (doc === null) {
746
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
747
+ }
748
+ return doc.toObject();
553
749
  }
554
- const nameCodeRegex = (_j = searchConditions.name) === null || _j === void 0 ? void 0 : _j.$regex;
555
- if (typeof nameCodeRegex === 'string') {
556
- matchStages.push({
557
- $match: {
558
- $or: [
559
- {
560
- 'containsPlace.containsPlace.name.ja': {
561
- $exists: true,
562
- $regex: new RegExp(nameCodeRegex)
563
- }
564
- },
565
- {
566
- 'containsPlace.containsPlace.name.en': {
567
- $exists: true,
568
- $regex: new RegExp(nameCodeRegex)
569
- }
570
- }
571
- ]
750
+ else {
751
+ const doc = yield this.placeModel.findOneAndUpdate({
752
+ typeOf: { $eq: factory.placeType.MovieTheater },
753
+ 'project.id': { $eq: screeningRoomSection.project.id },
754
+ branchCode: movieTheater.branchCode,
755
+ 'containsPlace.branchCode': screeningRoom.branchCode,
756
+ 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
757
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].branchCode': screeningRoomSection.branchCode }, (screeningRoomSection.name !== undefined && screeningRoomSection !== null)
758
+ ? {
759
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].name': screeningRoomSection.name
572
760
  }
573
- });
574
- }
575
- const branchCodeRegex = (_k = searchConditions.branchCode) === null || _k === void 0 ? void 0 : _k.$regex;
576
- if (typeof branchCodeRegex === 'string') {
577
- matchStages.push({
578
- $match: {
579
- 'containsPlace.containsPlace.branchCode': {
580
- $exists: true,
581
- $regex: new RegExp(branchCodeRegex)
582
- }
761
+ : undefined), (Array.isArray(screeningRoomSection.additionalProperty))
762
+ ? {
763
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].additionalProperty': screeningRoomSection.additionalProperty
583
764
  }
584
- });
585
- }
586
- const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
587
- if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
588
- matchStages.push({
589
- $match: {
590
- 'containsPlace.containsPlace.additionalProperty': {
591
- $exists: true,
592
- $elemMatch: additionalPropertyElemMatch
593
- }
765
+ : undefined), (Array.isArray(screeningRoomSection.containsPlace) && screeningRoomSection.containsPlace.length > 0)
766
+ ? {
767
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': screeningRoomSection.containsPlace.map((p) => {
768
+ return Object.assign(Object.assign(Object.assign({ typeOf: p.typeOf, branchCode: p.branchCode }, (p.name !== undefined && p.name !== null) ? { name: p.name } : undefined), (Array.isArray(p.seatingType)) ? { seatingType: p.seatingType } : undefined), (Array.isArray(p.additionalProperty)) ? { additionalProperty: p.additionalProperty } : undefined);
769
+ })
594
770
  }
595
- });
596
- }
597
- const aggregate = this.placeModel.aggregate([
598
- { $unwind: '$containsPlace' },
599
- { $unwind: '$containsPlace.containsPlace' },
600
- ...matchStages,
601
- {
602
- $project: Object.assign({ _id: 0, typeOf: '$containsPlace.containsPlace.typeOf', branchCode: '$containsPlace.containsPlace.branchCode', name: '$containsPlace.containsPlace.name', containedInPlace: {
603
- typeOf: '$containsPlace.typeOf',
604
- branchCode: '$containsPlace.branchCode',
605
- name: '$containsPlace.name',
606
- containedInPlace: {
607
- id: '$_id',
608
- typeOf: '$typeOf',
609
- branchCode: '$branchCode',
610
- name: '$name'
611
- }
612
- }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
613
- ? {
614
- seatCount: {
615
- $cond: {
616
- if: { $isArray: '$containsPlace.containsPlace.containsPlace' },
617
- then: { $size: '$containsPlace.containsPlace.containsPlace' },
618
- else: 0
619
- }
620
- }
621
- }
622
- : undefined)
623
- }
624
- ]);
625
- // tslint:disable-next-line:no-single-line-block-comment
626
- /* istanbul ignore else */
627
- if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
628
- const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
629
- aggregate.limit(searchConditions.limit * page)
630
- .skip(searchConditions.limit * (page - 1));
631
- }
632
- return aggregate.exec();
633
- });
634
- }
635
- deleteScreeningRoomSection(screeningRoomSection) {
636
- return __awaiter(this, void 0, void 0, function* () {
637
- const doc = yield this.placeModel.findOneAndUpdate({
638
- 'project.id': { $eq: screeningRoomSection.project.id },
639
- branchCode: screeningRoomSection.containedInPlace.containedInPlace.branchCode,
640
- 'containsPlace.branchCode': screeningRoomSection.containedInPlace.branchCode,
641
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
642
- }, {
643
- $pull: {
644
- 'containsPlace.$[screeningRoom].containsPlace': {
645
- branchCode: screeningRoomSection.branchCode
771
+ : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
772
+ new: true,
773
+ arrayFilters: [
774
+ { 'screeningRoom.branchCode': screeningRoom.branchCode },
775
+ { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
776
+ ],
777
+ projection: {
778
+ _id: 1,
779
+ typeOf: 1
646
780
  }
781
+ })
782
+ .exec();
783
+ if (doc === null) {
784
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
647
785
  }
648
- }, {
649
- new: true,
650
- arrayFilters: [
651
- { 'screeningRoom.branchCode': screeningRoomSection.containedInPlace.branchCode }
652
- ]
653
- })
654
- .exec();
655
- if (doc === null) {
656
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
786
+ return doc.toObject();
657
787
  }
658
788
  });
659
789
  }
660
- // tslint:disable-next-line:max-func-body-length
661
- searchScreeningRooms(searchConditions) {
662
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
790
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
791
+ searchScreeningRoomSections(searchConditions, useScreeningRoomType) {
792
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
663
793
  return __awaiter(this, void 0, void 0, function* () {
664
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
665
- const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
666
- if (typeof projectIdEq === 'string') {
667
- matchStages.push({
668
- $match: { 'project.id': { $eq: projectIdEq } }
669
- });
670
- }
671
- // 施設ID
672
- const containedInPlaceIdEq = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
673
- if (typeof containedInPlaceIdEq === 'string') {
674
- matchStages.push({
675
- $match: {
676
- _id: { $eq: new mongoose_1.Types.ObjectId(containedInPlaceIdEq) }
677
- }
678
- });
679
- }
680
- if (searchConditions.containedInPlace !== undefined) {
794
+ if (useScreeningRoomType === true) {
795
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
796
+ const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
797
+ if (typeof projectIdEq === 'string') {
798
+ matchStages.push({
799
+ $match: { 'project.id': { $eq: projectIdEq } }
800
+ });
801
+ }
681
802
  // 施設コード
682
- if (searchConditions.containedInPlace.branchCode !== undefined) {
683
- if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
684
- matchStages.push({
685
- $match: {
686
- branchCode: {
687
- $exists: true,
688
- $eq: searchConditions.containedInPlace.branchCode.$eq
689
- }
803
+ const movieTheaterBranchCodeEq = (_e = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
804
+ if (typeof movieTheaterBranchCodeEq === 'string') {
805
+ matchStages.push({
806
+ $match: {
807
+ 'containedInPlace.branchCode': {
808
+ $exists: true,
809
+ $eq: movieTheaterBranchCodeEq
690
810
  }
691
- });
692
- }
811
+ }
812
+ });
693
813
  }
694
- }
695
- // ルームコード
696
- if (searchConditions.branchCode !== undefined) {
697
- if (typeof searchConditions.branchCode.$eq === 'string') {
814
+ // ルームコード
815
+ const containedInPlaceBranchCodeEq = (_g = (_f = searchConditions.containedInPlace) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
816
+ if (typeof containedInPlaceBranchCodeEq === 'string') {
817
+ matchStages.push({
818
+ $match: {
819
+ branchCode: {
820
+ $eq: containedInPlaceBranchCodeEq
821
+ }
822
+ }
823
+ });
824
+ }
825
+ // セクションコード
826
+ const sectionBranchCodeEq = (_h = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
827
+ if (typeof sectionBranchCodeEq === 'string') {
698
828
  matchStages.push({
699
829
  $match: {
700
830
  'containsPlace.branchCode': {
701
831
  $exists: true,
702
- $eq: searchConditions.branchCode.$eq
832
+ $eq: sectionBranchCodeEq
703
833
  }
704
834
  }
705
835
  });
706
836
  }
707
- }
708
- const branchCodeRegex = (_e = searchConditions.branchCode) === null || _e === void 0 ? void 0 : _e.$regex;
709
- if (typeof branchCodeRegex === 'string') {
710
- matchStages.push({
711
- $match: {
712
- 'containsPlace.branchCode': {
713
- $exists: true,
714
- $regex: new RegExp(branchCodeRegex)
715
- }
716
- }
717
- });
718
- }
719
- const nameCodeRegex = (_f = searchConditions.name) === null || _f === void 0 ? void 0 : _f.$regex;
720
- if (typeof nameCodeRegex === 'string') {
721
- matchStages.push({
722
- $match: {
723
- $or: [
724
- {
725
- 'containsPlace.name.ja': {
726
- $exists: true,
727
- $regex: new RegExp(nameCodeRegex)
728
- }
729
- },
730
- {
731
- 'containsPlace.name.en': {
732
- $exists: true,
733
- $regex: new RegExp(nameCodeRegex)
837
+ const nameCodeRegex = (_j = searchConditions.name) === null || _j === void 0 ? void 0 : _j.$regex;
838
+ if (typeof nameCodeRegex === 'string') {
839
+ matchStages.push({
840
+ $match: {
841
+ $or: [
842
+ {
843
+ 'containsPlace.name.ja': {
844
+ $exists: true,
845
+ $regex: new RegExp(nameCodeRegex)
846
+ }
847
+ },
848
+ {
849
+ 'containsPlace.name.en': {
850
+ $exists: true,
851
+ $regex: new RegExp(nameCodeRegex)
852
+ }
734
853
  }
854
+ ]
855
+ }
856
+ });
857
+ }
858
+ const branchCodeRegex = (_k = searchConditions.branchCode) === null || _k === void 0 ? void 0 : _k.$regex;
859
+ if (typeof branchCodeRegex === 'string') {
860
+ matchStages.push({
861
+ $match: {
862
+ 'containsPlace.branchCode': {
863
+ $exists: true,
864
+ $regex: new RegExp(branchCodeRegex)
865
+ }
866
+ }
867
+ });
868
+ }
869
+ const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
870
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
871
+ matchStages.push({
872
+ $match: {
873
+ 'containsPlace.additionalProperty': {
874
+ $exists: true,
875
+ $elemMatch: additionalPropertyElemMatch
735
876
  }
736
- ]
877
+ }
878
+ });
879
+ }
880
+ const aggregate = this.placeModel.aggregate([
881
+ { $unwind: '$containsPlace' },
882
+ ...matchStages,
883
+ {
884
+ $project: Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', containedInPlace: {
885
+ typeOf: '$typeOf',
886
+ branchCode: '$branchCode',
887
+ name: '$name',
888
+ containedInPlace: {
889
+ id: '$containedInPlace.id',
890
+ typeOf: '$containedInPlace.typeOf',
891
+ branchCode: '$containedInPlace.branchCode',
892
+ name: '$containedInPlace.name'
893
+ }
894
+ }, additionalProperty: '$containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
895
+ ? {
896
+ seatCount: {
897
+ $cond: {
898
+ if: { $isArray: '$containsPlace.containsPlace' },
899
+ then: { $size: '$containsPlace.containsPlace' },
900
+ else: 0
901
+ }
902
+ }
903
+ }
904
+ : undefined)
737
905
  }
738
- });
906
+ ]);
907
+ // tslint:disable-next-line:no-single-line-block-comment
908
+ /* istanbul ignore else */
909
+ if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
910
+ const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
911
+ aggregate.limit(searchConditions.limit * page)
912
+ .skip(searchConditions.limit * (page - 1));
913
+ }
914
+ return aggregate.exec();
739
915
  }
740
- const openSeatingAllowed = searchConditions.openSeatingAllowed;
741
- if (typeof openSeatingAllowed === 'boolean') {
742
- matchStages.push({
743
- $match: {
744
- 'containsPlace.openSeatingAllowed': {
745
- $exists: true,
746
- $eq: openSeatingAllowed
916
+ else {
917
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
918
+ const projectIdEq = (_p = (_o = searchConditions.project) === null || _o === void 0 ? void 0 : _o.id) === null || _p === void 0 ? void 0 : _p.$eq;
919
+ if (typeof projectIdEq === 'string') {
920
+ matchStages.push({
921
+ $match: { 'project.id': { $eq: projectIdEq } }
922
+ });
923
+ }
924
+ // 施設コード
925
+ const movieTheaterBranchCodeEq = (_s = (_r = (_q = searchConditions.containedInPlace) === null || _q === void 0 ? void 0 : _q.containedInPlace) === null || _r === void 0 ? void 0 : _r.branchCode) === null || _s === void 0 ? void 0 : _s.$eq;
926
+ if (typeof movieTheaterBranchCodeEq === 'string') {
927
+ matchStages.push({
928
+ $match: {
929
+ branchCode: {
930
+ $exists: true,
931
+ $eq: movieTheaterBranchCodeEq
932
+ }
933
+ }
934
+ });
935
+ }
936
+ // ルームコード
937
+ const containedInPlaceBranchCodeEq = (_u = (_t = searchConditions.containedInPlace) === null || _t === void 0 ? void 0 : _t.branchCode) === null || _u === void 0 ? void 0 : _u.$eq;
938
+ if (typeof containedInPlaceBranchCodeEq === 'string') {
939
+ matchStages.push({
940
+ $match: {
941
+ 'containsPlace.branchCode': {
942
+ $exists: true,
943
+ $eq: containedInPlaceBranchCodeEq
944
+ }
945
+ }
946
+ });
947
+ }
948
+ // セクションコード
949
+ const sectionBranchCodeEq = (_v = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _v === void 0 ? void 0 : _v.$eq;
950
+ if (typeof sectionBranchCodeEq === 'string') {
951
+ matchStages.push({
952
+ $match: {
953
+ 'containsPlace.containsPlace.branchCode': {
954
+ $exists: true,
955
+ $eq: sectionBranchCodeEq
956
+ }
957
+ }
958
+ });
959
+ }
960
+ const nameCodeRegex = (_w = searchConditions.name) === null || _w === void 0 ? void 0 : _w.$regex;
961
+ if (typeof nameCodeRegex === 'string') {
962
+ matchStages.push({
963
+ $match: {
964
+ $or: [
965
+ {
966
+ 'containsPlace.containsPlace.name.ja': {
967
+ $exists: true,
968
+ $regex: new RegExp(nameCodeRegex)
969
+ }
970
+ },
971
+ {
972
+ 'containsPlace.containsPlace.name.en': {
973
+ $exists: true,
974
+ $regex: new RegExp(nameCodeRegex)
975
+ }
976
+ }
977
+ ]
978
+ }
979
+ });
980
+ }
981
+ const branchCodeRegex = (_x = searchConditions.branchCode) === null || _x === void 0 ? void 0 : _x.$regex;
982
+ if (typeof branchCodeRegex === 'string') {
983
+ matchStages.push({
984
+ $match: {
985
+ 'containsPlace.containsPlace.branchCode': {
986
+ $exists: true,
987
+ $regex: new RegExp(branchCodeRegex)
988
+ }
989
+ }
990
+ });
991
+ }
992
+ const additionalPropertyElemMatch = (_y = searchConditions.additionalProperty) === null || _y === void 0 ? void 0 : _y.$elemMatch;
993
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
994
+ matchStages.push({
995
+ $match: {
996
+ 'containsPlace.containsPlace.additionalProperty': {
997
+ $exists: true,
998
+ $elemMatch: additionalPropertyElemMatch
999
+ }
1000
+ }
1001
+ });
1002
+ }
1003
+ const aggregate = this.placeModel.aggregate([
1004
+ { $unwind: '$containsPlace' },
1005
+ { $unwind: '$containsPlace.containsPlace' },
1006
+ ...matchStages,
1007
+ {
1008
+ $project: Object.assign({ _id: 0, typeOf: '$containsPlace.containsPlace.typeOf', branchCode: '$containsPlace.containsPlace.branchCode', name: '$containsPlace.containsPlace.name', containedInPlace: {
1009
+ typeOf: '$containsPlace.typeOf',
1010
+ branchCode: '$containsPlace.branchCode',
1011
+ name: '$containsPlace.name',
1012
+ containedInPlace: {
1013
+ id: { $toString: '$_id' },
1014
+ // id: '$_id',
1015
+ typeOf: '$typeOf',
1016
+ branchCode: '$branchCode',
1017
+ name: '$name'
1018
+ }
1019
+ }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_z = searchConditions.$projection) === null || _z === void 0 ? void 0 : _z.seatCount) === 1)
1020
+ ? {
1021
+ seatCount: {
1022
+ $cond: {
1023
+ if: { $isArray: '$containsPlace.containsPlace.containsPlace' },
1024
+ then: { $size: '$containsPlace.containsPlace.containsPlace' },
1025
+ else: 0
1026
+ }
1027
+ }
1028
+ }
1029
+ : undefined)
1030
+ }
1031
+ ]);
1032
+ // tslint:disable-next-line:no-single-line-block-comment
1033
+ /* istanbul ignore else */
1034
+ if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
1035
+ const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
1036
+ aggregate.limit(searchConditions.limit * page)
1037
+ .skip(searchConditions.limit * (page - 1));
1038
+ }
1039
+ return aggregate.exec();
1040
+ }
1041
+ });
1042
+ }
1043
+ deleteScreeningRoomSection(screeningRoomSection, useScreeningRoomType) {
1044
+ return __awaiter(this, void 0, void 0, function* () {
1045
+ if (useScreeningRoomType === true) {
1046
+ const doc = yield this.placeModel.findOneAndUpdate({
1047
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
1048
+ 'project.id': { $eq: screeningRoomSection.project.id },
1049
+ 'containedInPlace.branchCode': {
1050
+ $exists: true,
1051
+ $eq: screeningRoomSection.containedInPlace.containedInPlace.branchCode
1052
+ },
1053
+ branchCode: { $eq: screeningRoomSection.containedInPlace.branchCode },
1054
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
1055
+ }, {
1056
+ $pull: {
1057
+ containsPlace: {
1058
+ branchCode: screeningRoomSection.branchCode
747
1059
  }
748
1060
  }
749
- });
1061
+ }, {
1062
+ new: true,
1063
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
1064
+ })
1065
+ .exec();
1066
+ if (doc === null) {
1067
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
1068
+ }
1069
+ return doc.toObject();
750
1070
  }
751
- const additionalPropertyElemMatch = (_g = searchConditions.additionalProperty) === null || _g === void 0 ? void 0 : _g.$elemMatch;
752
- if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
753
- matchStages.push({
754
- $match: {
755
- 'containsPlace.additionalProperty': {
756
- $exists: true,
757
- $elemMatch: additionalPropertyElemMatch
1071
+ else {
1072
+ const doc = yield this.placeModel.findOneAndUpdate({
1073
+ typeOf: { $eq: factory.placeType.MovieTheater },
1074
+ 'project.id': { $eq: screeningRoomSection.project.id },
1075
+ branchCode: screeningRoomSection.containedInPlace.containedInPlace.branchCode,
1076
+ 'containsPlace.branchCode': screeningRoomSection.containedInPlace.branchCode,
1077
+ 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
1078
+ }, {
1079
+ $pull: {
1080
+ 'containsPlace.$[screeningRoom].containsPlace': {
1081
+ branchCode: screeningRoomSection.branchCode
758
1082
  }
759
1083
  }
760
- });
1084
+ }, {
1085
+ new: true,
1086
+ arrayFilters: [
1087
+ { 'screeningRoom.branchCode': screeningRoomSection.containedInPlace.branchCode }
1088
+ ],
1089
+ projection: {
1090
+ _id: 1,
1091
+ typeOf: 1
1092
+ }
1093
+ })
1094
+ .exec();
1095
+ if (doc === null) {
1096
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
1097
+ }
1098
+ return doc.toObject();
1099
+ }
1100
+ });
1101
+ }
1102
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
1103
+ searchScreeningRooms(searchConditions, useScreeningRoomType) {
1104
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
1105
+ return __awaiter(this, void 0, void 0, function* () {
1106
+ if (useScreeningRoomType === true) {
1107
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
1108
+ const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
1109
+ if (typeof projectIdEq === 'string') {
1110
+ matchStages.push({
1111
+ $match: { 'project.id': { $eq: projectIdEq } }
1112
+ });
1113
+ }
1114
+ // 施設ID
1115
+ const containedInPlaceIdEq = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
1116
+ if (typeof containedInPlaceIdEq === 'string') {
1117
+ matchStages.push({
1118
+ $match: {
1119
+ 'containedInPlace.id': {
1120
+ $exists: true,
1121
+ $eq: containedInPlaceIdEq
1122
+ }
1123
+ }
1124
+ });
1125
+ }
1126
+ if (searchConditions.containedInPlace !== undefined) {
1127
+ // 施設コード
1128
+ if (searchConditions.containedInPlace.branchCode !== undefined) {
1129
+ if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
1130
+ matchStages.push({
1131
+ $match: {
1132
+ 'containedInPlace.branchCode': {
1133
+ $exists: true,
1134
+ $eq: searchConditions.containedInPlace.branchCode.$eq
1135
+ }
1136
+ }
1137
+ });
1138
+ }
1139
+ }
1140
+ }
1141
+ const branchCodeEq = (_e = searchConditions.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
1142
+ if (typeof branchCodeEq === 'string') {
1143
+ matchStages.push({
1144
+ $match: {
1145
+ branchCode: { $eq: branchCodeEq }
1146
+ }
1147
+ });
1148
+ }
1149
+ const branchCodeIn = (_f = searchConditions.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
1150
+ if (Array.isArray(branchCodeIn)) {
1151
+ matchStages.push({
1152
+ $match: {
1153
+ branchCode: { $in: branchCodeIn }
1154
+ }
1155
+ });
1156
+ }
1157
+ const branchCodeRegex = (_g = searchConditions.branchCode) === null || _g === void 0 ? void 0 : _g.$regex;
1158
+ if (typeof branchCodeRegex === 'string') {
1159
+ matchStages.push({
1160
+ $match: {
1161
+ branchCode: {
1162
+ $regex: new RegExp(branchCodeRegex)
1163
+ }
1164
+ }
1165
+ });
1166
+ }
1167
+ const nameCodeRegex = (_h = searchConditions.name) === null || _h === void 0 ? void 0 : _h.$regex;
1168
+ if (typeof nameCodeRegex === 'string') {
1169
+ matchStages.push({
1170
+ $match: {
1171
+ $or: [
1172
+ {
1173
+ 'name.ja': {
1174
+ $exists: true,
1175
+ $regex: new RegExp(nameCodeRegex)
1176
+ }
1177
+ },
1178
+ {
1179
+ 'name.en': {
1180
+ $exists: true,
1181
+ $regex: new RegExp(nameCodeRegex)
1182
+ }
1183
+ }
1184
+ ]
1185
+ }
1186
+ });
1187
+ }
1188
+ const openSeatingAllowed = searchConditions.openSeatingAllowed;
1189
+ if (typeof openSeatingAllowed === 'boolean') {
1190
+ matchStages.push({
1191
+ $match: {
1192
+ openSeatingAllowed: {
1193
+ $exists: true,
1194
+ $eq: openSeatingAllowed
1195
+ }
1196
+ }
1197
+ });
1198
+ }
1199
+ const additionalPropertyElemMatch = (_j = searchConditions.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
1200
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
1201
+ matchStages.push({
1202
+ $match: {
1203
+ additionalProperty: {
1204
+ $exists: true,
1205
+ $elemMatch: additionalPropertyElemMatch
1206
+ }
1207
+ }
1208
+ });
1209
+ }
1210
+ const aggregate = this.placeModel.aggregate([
1211
+ { $sort: { branchCode: factory.sortType.Ascending } },
1212
+ // { $unwind: '$containsPlace' },
1213
+ ...matchStages,
1214
+ {
1215
+ $project: Object.assign(Object.assign({ _id: 0, typeOf: '$typeOf', branchCode: '$branchCode', name: '$name', address: '$address', containedInPlace: {
1216
+ id: '$containedInPlace.id',
1217
+ typeOf: '$containedInPlace.typeOf',
1218
+ branchCode: '$containedInPlace.branchCode',
1219
+ name: '$containedInPlace.name'
1220
+ }, openSeatingAllowed: '$openSeatingAllowed', additionalProperty: '$additionalProperty', maximumAttendeeCapacity: '$maximumAttendeeCapacity' }, (((_k = searchConditions.$projection) === null || _k === void 0 ? void 0 : _k.sectionCount) === 1)
1221
+ ? {
1222
+ sectionCount: {
1223
+ $cond: {
1224
+ if: { $isArray: '$containsPlace' },
1225
+ then: { $size: '$containsPlace' },
1226
+ else: 0
1227
+ }
1228
+ }
1229
+ }
1230
+ : undefined), (((_l = searchConditions.$projection) === null || _l === void 0 ? void 0 : _l.seatCount) === 1)
1231
+ ? {
1232
+ seatCount: {
1233
+ $sum: {
1234
+ $map: {
1235
+ input: '$containsPlace',
1236
+ in: {
1237
+ $cond: {
1238
+ if: { $isArray: '$$this.containsPlace' },
1239
+ then: { $size: '$$this.containsPlace' },
1240
+ else: 0
1241
+ }
1242
+ }
1243
+ }
1244
+ }
1245
+ }
1246
+ }
1247
+ : undefined)
1248
+ }
1249
+ ]);
1250
+ // tslint:disable-next-line:no-single-line-block-comment
1251
+ /* istanbul ignore else */
1252
+ if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
1253
+ const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
1254
+ aggregate.limit(searchConditions.limit * page)
1255
+ .skip(searchConditions.limit * (page - 1));
1256
+ }
1257
+ return aggregate.exec();
1258
+ }
1259
+ else {
1260
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
1261
+ const projectIdEq = (_o = (_m = searchConditions.project) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$eq;
1262
+ if (typeof projectIdEq === 'string') {
1263
+ matchStages.push({
1264
+ $match: { 'project.id': { $eq: projectIdEq } }
1265
+ });
1266
+ }
1267
+ // 施設ID
1268
+ const containedInPlaceIdEq = (_q = (_p = searchConditions.containedInPlace) === null || _p === void 0 ? void 0 : _p.id) === null || _q === void 0 ? void 0 : _q.$eq;
1269
+ if (typeof containedInPlaceIdEq === 'string') {
1270
+ matchStages.push({
1271
+ $match: {
1272
+ _id: { $eq: new mongoose_1.Types.ObjectId(containedInPlaceIdEq) }
1273
+ }
1274
+ });
1275
+ }
1276
+ if (searchConditions.containedInPlace !== undefined) {
1277
+ // 施設コード
1278
+ if (searchConditions.containedInPlace.branchCode !== undefined) {
1279
+ if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
1280
+ matchStages.push({
1281
+ $match: {
1282
+ branchCode: {
1283
+ $exists: true,
1284
+ $eq: searchConditions.containedInPlace.branchCode.$eq
1285
+ }
1286
+ }
1287
+ });
1288
+ }
1289
+ }
1290
+ }
1291
+ const branchCodeEq = (_r = searchConditions.branchCode) === null || _r === void 0 ? void 0 : _r.$eq;
1292
+ if (typeof branchCodeEq === 'string') {
1293
+ matchStages.push({
1294
+ $match: {
1295
+ 'containsPlace.branchCode': { $exists: true, $eq: branchCodeEq }
1296
+ }
1297
+ });
1298
+ }
1299
+ const branchCodeIn = (_s = searchConditions.branchCode) === null || _s === void 0 ? void 0 : _s.$in;
1300
+ if (Array.isArray(branchCodeIn)) {
1301
+ matchStages.push({
1302
+ $match: {
1303
+ 'containsPlace.branchCode': { $exists: true, $in: branchCodeIn }
1304
+ }
1305
+ });
1306
+ }
1307
+ const branchCodeRegex = (_t = searchConditions.branchCode) === null || _t === void 0 ? void 0 : _t.$regex;
1308
+ if (typeof branchCodeRegex === 'string') {
1309
+ matchStages.push({
1310
+ $match: {
1311
+ 'containsPlace.branchCode': {
1312
+ $exists: true,
1313
+ $regex: new RegExp(branchCodeRegex)
1314
+ }
1315
+ }
1316
+ });
1317
+ }
1318
+ const nameCodeRegex = (_u = searchConditions.name) === null || _u === void 0 ? void 0 : _u.$regex;
1319
+ if (typeof nameCodeRegex === 'string') {
1320
+ matchStages.push({
1321
+ $match: {
1322
+ $or: [
1323
+ {
1324
+ 'containsPlace.name.ja': {
1325
+ $exists: true,
1326
+ $regex: new RegExp(nameCodeRegex)
1327
+ }
1328
+ },
1329
+ {
1330
+ 'containsPlace.name.en': {
1331
+ $exists: true,
1332
+ $regex: new RegExp(nameCodeRegex)
1333
+ }
1334
+ }
1335
+ ]
1336
+ }
1337
+ });
1338
+ }
1339
+ const openSeatingAllowed = searchConditions.openSeatingAllowed;
1340
+ if (typeof openSeatingAllowed === 'boolean') {
1341
+ matchStages.push({
1342
+ $match: {
1343
+ 'containsPlace.openSeatingAllowed': {
1344
+ $exists: true,
1345
+ $eq: openSeatingAllowed
1346
+ }
1347
+ }
1348
+ });
1349
+ }
1350
+ const additionalPropertyElemMatch = (_v = searchConditions.additionalProperty) === null || _v === void 0 ? void 0 : _v.$elemMatch;
1351
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
1352
+ matchStages.push({
1353
+ $match: {
1354
+ 'containsPlace.additionalProperty': {
1355
+ $exists: true,
1356
+ $elemMatch: additionalPropertyElemMatch
1357
+ }
1358
+ }
1359
+ });
1360
+ }
1361
+ const aggregate = this.placeModel.aggregate([
1362
+ { $unwind: '$containsPlace' },
1363
+ ...matchStages,
1364
+ {
1365
+ $project: Object.assign(Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', address: '$containsPlace.address', containedInPlace: {
1366
+ id: { $toString: '$_id' },
1367
+ // id: '$_id',
1368
+ typeOf: '$typeOf',
1369
+ branchCode: '$branchCode',
1370
+ name: '$name'
1371
+ }, openSeatingAllowed: '$containsPlace.openSeatingAllowed', additionalProperty: '$containsPlace.additionalProperty', maximumAttendeeCapacity: '$containsPlace.maximumAttendeeCapacity' }, (((_w = searchConditions.$projection) === null || _w === void 0 ? void 0 : _w.sectionCount) === 1)
1372
+ ? {
1373
+ sectionCount: {
1374
+ $cond: {
1375
+ if: { $isArray: '$containsPlace.containsPlace' },
1376
+ then: { $size: '$containsPlace.containsPlace' },
1377
+ else: 0
1378
+ }
1379
+ }
1380
+ }
1381
+ : undefined), (((_x = searchConditions.$projection) === null || _x === void 0 ? void 0 : _x.seatCount) === 1)
1382
+ ? {
1383
+ seatCount: {
1384
+ $sum: {
1385
+ $map: {
1386
+ input: '$containsPlace.containsPlace',
1387
+ in: {
1388
+ $cond: {
1389
+ if: { $isArray: '$$this.containsPlace' },
1390
+ then: { $size: '$$this.containsPlace' },
1391
+ else: 0
1392
+ }
1393
+ }
1394
+ }
1395
+ }
1396
+ }
1397
+ }
1398
+ : undefined)
1399
+ }
1400
+ ]);
1401
+ // tslint:disable-next-line:no-single-line-block-comment
1402
+ /* istanbul ignore else */
1403
+ if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
1404
+ const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
1405
+ aggregate.limit(searchConditions.limit * page)
1406
+ .skip(searchConditions.limit * (page - 1));
1407
+ }
1408
+ return aggregate.exec();
761
1409
  }
762
- const aggregate = this.placeModel.aggregate([
763
- { $unwind: '$containsPlace' },
764
- ...matchStages,
765
- {
766
- $project: Object.assign(Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', address: '$containsPlace.address', containedInPlace: {
767
- id: '$_id',
1410
+ });
1411
+ }
1412
+ findScreeningRoomsByBranchCode(params) {
1413
+ return __awaiter(this, void 0, void 0, function* () {
1414
+ if (params.useScreeningRoomType === true) {
1415
+ const matchStages = [
1416
+ { $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } },
1417
+ {
1418
+ $match: { 'containedInPlace.id': { $exists: true, $eq: params.containedInPlace.id.$eq } }
1419
+ },
1420
+ {
1421
+ $match: { branchCode: { $eq: params.branchCode.$eq } }
1422
+ }
1423
+ ];
1424
+ const aggregate = this.placeModel.aggregate([
1425
+ // { $unwind: '$containsPlace' },
1426
+ ...matchStages,
1427
+ {
1428
+ $project: {
1429
+ _id: 0,
768
1430
  typeOf: '$typeOf',
769
1431
  branchCode: '$branchCode',
770
- name: '$name'
771
- }, openSeatingAllowed: '$containsPlace.openSeatingAllowed', additionalProperty: '$containsPlace.additionalProperty' }, (((_h = searchConditions.$projection) === null || _h === void 0 ? void 0 : _h.sectionCount) === 1)
772
- ? {
773
- sectionCount: {
774
- $cond: {
775
- if: { $isArray: '$containsPlace.containsPlace' },
776
- then: { $size: '$containsPlace.containsPlace' },
777
- else: 0
1432
+ name: '$name',
1433
+ containsPlace: '$containsPlace',
1434
+ seatCount: {
1435
+ $sum: {
1436
+ $map: {
1437
+ input: '$containsPlace',
1438
+ in: {
1439
+ $cond: {
1440
+ if: { $isArray: '$$this.containsPlace' },
1441
+ then: { $size: '$$this.containsPlace' },
1442
+ else: 0
1443
+ }
1444
+ }
1445
+ }
778
1446
  }
779
1447
  }
780
1448
  }
781
- : undefined), (((_j = searchConditions.$projection) === null || _j === void 0 ? void 0 : _j.seatCount) === 1)
782
- ? {
1449
+ }
1450
+ ]);
1451
+ const docs = yield aggregate.limit(1)
1452
+ .exec();
1453
+ if (docs.length < 1) {
1454
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
1455
+ }
1456
+ return docs[0];
1457
+ }
1458
+ else {
1459
+ const matchStages = [
1460
+ { $match: { typeOf: { $eq: factory.placeType.MovieTheater } } },
1461
+ {
1462
+ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.containedInPlace.id.$eq) } }
1463
+ },
1464
+ {
1465
+ $match: { 'containsPlace.branchCode': { $exists: true, $eq: params.branchCode.$eq } }
1466
+ }
1467
+ ];
1468
+ const aggregate = this.placeModel.aggregate([
1469
+ { $unwind: '$containsPlace' },
1470
+ ...matchStages,
1471
+ {
1472
+ $project: {
1473
+ _id: 0,
1474
+ typeOf: '$containsPlace.typeOf',
1475
+ branchCode: '$containsPlace.branchCode',
1476
+ name: '$containsPlace.name',
1477
+ containsPlace: '$containsPlace.containsPlace',
783
1478
  seatCount: {
784
1479
  $sum: {
785
1480
  $map: {
@@ -795,62 +1490,20 @@ class MongoRepository {
795
1490
  }
796
1491
  }
797
1492
  }
798
- : undefined)
799
- }
800
- ]);
801
- // tslint:disable-next-line:no-single-line-block-comment
802
- /* istanbul ignore else */
803
- if (typeof searchConditions.limit === 'number' && searchConditions.limit > 0) {
804
- const page = (typeof searchConditions.page === 'number' && searchConditions.page > 0) ? searchConditions.page : 1;
805
- aggregate.limit(searchConditions.limit * page)
806
- .skip(searchConditions.limit * (page - 1));
807
- }
808
- return aggregate.exec();
809
- });
810
- }
811
- findScreeningRoomsByBranchCode(params) {
812
- return __awaiter(this, void 0, void 0, function* () {
813
- const matchStages = [
814
- { $match: { typeOf: { $eq: factory.placeType.MovieTheater } } },
815
- {
816
- $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.containedInPlace.id.$eq) } }
817
- },
818
- {
819
- $match: { 'containsPlace.branchCode': { $exists: true, $eq: params.branchCode.$eq } }
820
- }
821
- ];
822
- const aggregate = this.placeModel.aggregate([
823
- { $unwind: '$containsPlace' },
824
- ...matchStages,
825
- {
826
- $project: {
827
- _id: 0,
828
- typeOf: '$containsPlace.typeOf',
829
- branchCode: '$containsPlace.branchCode',
830
- name: '$containsPlace.name',
831
- // address: '$containsPlace.address',
832
- // containedInPlace: {
833
- // id: '$_id',
834
- // typeOf: '$typeOf',
835
- // branchCode: '$branchCode',
836
- // name: '$name'
837
- // },
838
- // openSeatingAllowed: '$containsPlace.openSeatingAllowed',
839
- // additionalProperty: '$containsPlace.additionalProperty',
840
- containsPlace: '$containsPlace.containsPlace'
841
1493
  }
1494
+ ]);
1495
+ const docs = yield aggregate.limit(1)
1496
+ .exec();
1497
+ if (docs.length < 1) {
1498
+ throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
842
1499
  }
843
- ]);
844
- const docs = yield aggregate.limit(1)
845
- .exec();
846
- if (docs.length < 1) {
847
- throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
1500
+ return docs[0];
848
1501
  }
849
- return docs[0];
850
1502
  });
851
1503
  }
852
- createSeat(seat) {
853
- var _a, _b;
1504
+ // tslint:disable-next-line:max-func-body-length
1505
+ createSeat(seat, useScreeningRoomType) {
1506
+ var _a, _b, _c, _d;
854
1507
  return __awaiter(this, void 0, void 0, function* () {
855
1508
  const screeningRoomSection = seat.containedInPlace;
856
1509
  if (typeof (screeningRoomSection === null || screeningRoomSection === void 0 ? void 0 : screeningRoomSection.branchCode) !== 'string') {
@@ -866,50 +1519,80 @@ class MongoRepository {
866
1519
  }
867
1520
  // 施設存在確認
868
1521
  let doc = yield this.placeModel.findOne({
1522
+ typeOf: { $eq: factory.placeType.MovieTheater },
869
1523
  'project.id': { $eq: seat.project.id },
870
- branchCode: movieTheater.branchCode,
871
- 'containsPlace.branchCode': screeningRoom.branchCode,
872
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
873
- }, {
874
- _id: 1
875
- })
1524
+ branchCode: { $eq: movieTheater.branchCode }
1525
+ }, { _id: 1 })
876
1526
  .exec();
877
1527
  if (doc === null) {
878
1528
  throw new factory.errors.NotFound(factory.placeType.MovieTheater);
879
1529
  }
880
- doc = yield this.placeModel.findOneAndUpdate({
881
- 'project.id': { $eq: seat.project.id },
882
- branchCode: movieTheater.branchCode,
883
- 'containsPlace.branchCode': screeningRoom.branchCode,
884
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
885
- }, {
886
- $push: {
887
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': Object.assign(Object.assign({ typeOf: seat.typeOf, branchCode: seat.branchCode, additionalProperty: seat.additionalProperty }, (typeof ((_a = seat.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = seat.name) === null || _b === void 0 ? void 0 : _b.en) === 'string') ? { name: seat.name } : undefined), (Array.isArray(seat.seatingType)) ? { seatingType: seat.seatingType } : undefined)
1530
+ if (useScreeningRoomType === true) {
1531
+ doc = yield this.placeModel.findOneAndUpdate({
1532
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
1533
+ 'project.id': { $eq: seat.project.id },
1534
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
1535
+ branchCode: { $eq: screeningRoom.branchCode },
1536
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
1537
+ }, {
1538
+ $push: {
1539
+ 'containsPlace.$[screeningRoomSection].containsPlace': Object.assign(Object.assign({ typeOf: seat.typeOf, branchCode: seat.branchCode, additionalProperty: seat.additionalProperty }, (typeof ((_a = seat.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = seat.name) === null || _b === void 0 ? void 0 : _b.en) === 'string') ? { name: seat.name } : undefined), (Array.isArray(seat.seatingType)) ? { seatingType: seat.seatingType } : undefined)
1540
+ }
1541
+ }, {
1542
+ new: true,
1543
+ arrayFilters: [
1544
+ {
1545
+ 'screeningRoomSection.branchCode': { $eq: screeningRoomSection.branchCode },
1546
+ 'screeningRoomSection.containsPlace.branchCode': { $ne: seat.branchCode }
1547
+ }
1548
+ ],
1549
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
1550
+ })
1551
+ .exec();
1552
+ // 存在しなければコード重複
1553
+ if (doc === null) {
1554
+ throw new factory.errors.AlreadyInUse(factory.placeType.Seat, ['branchCode']);
888
1555
  }
889
- }, {
890
- new: true,
891
- arrayFilters: [
892
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
893
- {
894
- 'screeningRoomSection.branchCode': screeningRoomSection.branchCode,
895
- 'screeningRoomSection.containsPlace.branchCode': { $ne: seat.branchCode }
1556
+ return doc.toObject();
1557
+ }
1558
+ else {
1559
+ doc = yield this.placeModel.findOneAndUpdate({
1560
+ typeOf: { $eq: factory.placeType.MovieTheater },
1561
+ 'project.id': { $eq: seat.project.id },
1562
+ branchCode: movieTheater.branchCode,
1563
+ 'containsPlace.branchCode': screeningRoom.branchCode,
1564
+ 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
1565
+ }, {
1566
+ $push: {
1567
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': Object.assign(Object.assign({ typeOf: seat.typeOf, branchCode: seat.branchCode, additionalProperty: seat.additionalProperty }, (typeof ((_c = seat.name) === null || _c === void 0 ? void 0 : _c.ja) === 'string' || typeof ((_d = seat.name) === null || _d === void 0 ? void 0 : _d.en) === 'string') ? { name: seat.name } : undefined), (Array.isArray(seat.seatingType)) ? { seatingType: seat.seatingType } : undefined)
1568
+ }
1569
+ }, {
1570
+ new: true,
1571
+ arrayFilters: [
1572
+ { 'screeningRoom.branchCode': screeningRoom.branchCode },
1573
+ {
1574
+ 'screeningRoomSection.branchCode': screeningRoomSection.branchCode,
1575
+ 'screeningRoomSection.containsPlace.branchCode': { $ne: seat.branchCode }
1576
+ }
1577
+ ],
1578
+ projection: {
1579
+ _id: 1,
1580
+ branchCode: 1,
1581
+ typeOf: 1
896
1582
  }
897
- ],
898
- projection: {
899
- _id: 1,
900
- 'project.id': 1,
901
- branchCode: 1
1583
+ })
1584
+ .exec();
1585
+ // 存在しなければコード重複
1586
+ if (doc === null) {
1587
+ throw new factory.errors.AlreadyInUse(factory.placeType.Seat, ['branchCode']);
902
1588
  }
903
- })
904
- .exec();
905
- // 存在しなければコード重複
906
- if (doc === null) {
907
- throw new factory.errors.AlreadyInUse(factory.placeType.Seat, ['branchCode']);
1589
+ return doc.toObject();
908
1590
  }
909
1591
  });
910
1592
  }
911
- updateSeat(seat, $unset) {
912
- var _a, _b;
1593
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
1594
+ updateSeat(seat, $unset, useScreeningRoomType) {
1595
+ var _a, _b, _c, _d;
913
1596
  return __awaiter(this, void 0, void 0, function* () {
914
1597
  const screeningRoomSection = seat.containedInPlace;
915
1598
  if (typeof (screeningRoomSection === null || screeningRoomSection === void 0 ? void 0 : screeningRoomSection.branchCode) !== 'string') {
@@ -923,253 +1606,602 @@ class MongoRepository {
923
1606
  if (typeof (movieTheater === null || movieTheater === void 0 ? void 0 : movieTheater.branchCode) !== 'string') {
924
1607
  throw new factory.errors.ArgumentNull('containedInPlace.containedInPlace.containedInPlace.branchCode');
925
1608
  }
926
- const doc = yield this.placeModel.findOneAndUpdate({
927
- 'project.id': { $eq: seat.project.id },
928
- branchCode: movieTheater.branchCode,
929
- 'containsPlace.branchCode': screeningRoom.branchCode,
930
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode,
931
- 'containsPlace.containsPlace.containsPlace.branchCode': seat.branchCode
932
- }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].branchCode': seat.branchCode }, (typeof ((_a = seat.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = seat.name) === null || _b === void 0 ? void 0 : _b.en) === 'string')
933
- ? {
934
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': seat.name
935
- }
936
- : undefined), (Array.isArray(seat.seatingType))
937
- ? {
938
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': seat.seatingType
939
- }
940
- : undefined), (Array.isArray(seat.additionalProperty))
941
- ? {
942
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': seat.additionalProperty
943
- }
944
- : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
945
- new: true,
946
- arrayFilters: [
947
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
948
- { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode },
949
- { 'seat.branchCode': seat.branchCode }
950
- ],
951
- projection: {
952
- _id: 1,
953
- 'project.id': 1,
954
- branchCode: 1
1609
+ if (useScreeningRoomType === true) {
1610
+ const doc = yield this.placeModel.findOneAndUpdate({
1611
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
1612
+ 'project.id': { $eq: seat.project.id },
1613
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
1614
+ branchCode: { $eq: screeningRoom.branchCode },
1615
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode },
1616
+ 'containsPlace.containsPlace.branchCode': { $eq: seat.branchCode }
1617
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].branchCode': seat.branchCode }, (typeof ((_a = seat.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string' || typeof ((_b = seat.name) === null || _b === void 0 ? void 0 : _b.en) === 'string')
1618
+ ? {
1619
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': seat.name
1620
+ }
1621
+ : undefined), (Array.isArray(seat.seatingType))
1622
+ ? {
1623
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': seat.seatingType
1624
+ }
1625
+ : undefined), (Array.isArray(seat.additionalProperty))
1626
+ ? {
1627
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': seat.additionalProperty
1628
+ }
1629
+ : undefined), { $unset: Object.assign(Object.assign({ noExistingAttributeName: 1 }, (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].name'])
1630
+ === 1
1631
+ || ($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoomSection].containsPlace.$[seat].name']) === 1)
1632
+ ? {
1633
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': 1
1634
+ }
1635
+ : undefined), (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType'])
1636
+ === 1
1637
+ || ($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType']) === 1)
1638
+ ? {
1639
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': 1
1640
+ }
1641
+ : undefined) }), {
1642
+ new: true,
1643
+ arrayFilters: [
1644
+ { 'screeningRoomSection.branchCode': { $eq: screeningRoomSection.branchCode } },
1645
+ { 'seat.branchCode': { $eq: seat.branchCode } }
1646
+ ],
1647
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
1648
+ })
1649
+ .exec();
1650
+ if (doc === null) {
1651
+ throw new factory.errors.NotFound(factory.placeType.Seat);
1652
+ }
1653
+ return doc.toObject();
1654
+ }
1655
+ else {
1656
+ const doc = yield this.placeModel.findOneAndUpdate({
1657
+ typeOf: { $eq: factory.placeType.MovieTheater },
1658
+ 'project.id': { $eq: seat.project.id },
1659
+ branchCode: movieTheater.branchCode,
1660
+ 'containsPlace.branchCode': screeningRoom.branchCode,
1661
+ 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode,
1662
+ 'containsPlace.containsPlace.containsPlace.branchCode': seat.branchCode
1663
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].branchCode': seat.branchCode }, (typeof ((_c = seat.name) === null || _c === void 0 ? void 0 : _c.ja) === 'string' || typeof ((_d = seat.name) === null || _d === void 0 ? void 0 : _d.en) === 'string')
1664
+ ? {
1665
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': seat.name
1666
+ }
1667
+ : undefined), (Array.isArray(seat.seatingType))
1668
+ ? {
1669
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': seat.seatingType
1670
+ }
1671
+ : undefined), (Array.isArray(seat.additionalProperty))
1672
+ ? {
1673
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': seat.additionalProperty
1674
+ }
1675
+ : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
1676
+ new: true,
1677
+ arrayFilters: [
1678
+ { 'screeningRoom.branchCode': screeningRoom.branchCode },
1679
+ { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode },
1680
+ { 'seat.branchCode': seat.branchCode }
1681
+ ],
1682
+ projection: {
1683
+ _id: 1,
1684
+ // 'project.id': 1,
1685
+ branchCode: 1,
1686
+ typeOf: 1
1687
+ }
1688
+ })
1689
+ .exec();
1690
+ if (doc === null) {
1691
+ throw new factory.errors.NotFound(factory.placeType.Seat);
955
1692
  }
956
- })
957
- .exec();
958
- if (doc === null) {
959
- throw new factory.errors.NotFound(factory.placeType.Seat);
1693
+ return doc.toObject();
960
1694
  }
961
1695
  });
962
1696
  }
963
1697
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
964
- searchSeats(params) {
965
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
1698
+ searchSeats(params, useScreeningRoomType) {
1699
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
966
1700
  return __awaiter(this, void 0, void 0, function* () {
967
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
968
- const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
969
- if (typeof projectIdEq === 'string') {
970
- matchStages.push({
971
- $match: { 'project.id': { $eq: projectIdEq } }
972
- });
973
- }
974
- const containedInPlaceBranchCodeEq = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$eq;
975
- if (typeof containedInPlaceBranchCodeEq === 'string') {
976
- matchStages.push({
977
- $match: {
978
- 'containsPlace.containsPlace.branchCode': {
979
- $exists: true,
980
- $eq: containedInPlaceBranchCodeEq
1701
+ if (useScreeningRoomType === true) {
1702
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
1703
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
1704
+ if (typeof projectIdEq === 'string') {
1705
+ matchStages.push({
1706
+ $match: { 'project.id': { $eq: projectIdEq } }
1707
+ });
1708
+ }
1709
+ const containedInPlaceBranchCodeEq = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$eq;
1710
+ if (typeof containedInPlaceBranchCodeEq === 'string') {
1711
+ matchStages.push({
1712
+ $match: {
1713
+ 'containsPlace.branchCode': {
1714
+ $exists: true,
1715
+ $eq: containedInPlaceBranchCodeEq
1716
+ }
981
1717
  }
982
- }
983
- });
984
- }
985
- const containedInPlaceBranchCodeIn = (_f = (_e = params.containedInPlace) === null || _e === void 0 ? void 0 : _e.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
986
- if (Array.isArray(containedInPlaceBranchCodeIn)) {
987
- matchStages.push({
988
- $match: {
989
- 'containsPlace.containsPlace.branchCode': {
990
- $exists: true,
991
- $in: containedInPlaceBranchCodeIn
1718
+ });
1719
+ }
1720
+ const containedInPlaceBranchCodeIn = (_f = (_e = params.containedInPlace) === null || _e === void 0 ? void 0 : _e.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
1721
+ if (Array.isArray(containedInPlaceBranchCodeIn)) {
1722
+ matchStages.push({
1723
+ $match: {
1724
+ 'containsPlace.branchCode': {
1725
+ $exists: true,
1726
+ $in: containedInPlaceBranchCodeIn
1727
+ }
1728
+ }
1729
+ });
1730
+ }
1731
+ if (params.containedInPlace !== undefined) {
1732
+ if (params.containedInPlace.containedInPlace !== undefined) {
1733
+ if (params.containedInPlace.containedInPlace.branchCode !== undefined) {
1734
+ if (typeof params.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1735
+ matchStages.push({
1736
+ $match: {
1737
+ branchCode: {
1738
+ $eq: params.containedInPlace.containedInPlace.branchCode.$eq
1739
+ }
1740
+ }
1741
+ });
1742
+ }
1743
+ }
1744
+ if (params.containedInPlace.containedInPlace.containedInPlace !== undefined) {
1745
+ if (params.containedInPlace.containedInPlace.containedInPlace.branchCode !== undefined) {
1746
+ if (typeof params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1747
+ matchStages.push({
1748
+ $match: {
1749
+ 'containedInPlace.branchCode': {
1750
+ $exists: true,
1751
+ $eq: params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq
1752
+ }
1753
+ }
1754
+ });
1755
+ }
1756
+ }
992
1757
  }
993
1758
  }
994
- });
995
- }
996
- if (params.containedInPlace !== undefined) {
997
- if (params.containedInPlace.containedInPlace !== undefined) {
998
- if (params.containedInPlace.containedInPlace.branchCode !== undefined) {
999
- if (typeof params.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1000
- matchStages.push({
1001
- $match: {
1002
- 'containsPlace.branchCode': {
1759
+ }
1760
+ // 座席コード
1761
+ if (params.branchCode !== undefined) {
1762
+ if (typeof params.branchCode.$eq === 'string') {
1763
+ matchStages.push({
1764
+ $match: {
1765
+ 'containsPlace.containsPlace.branchCode': {
1766
+ $exists: true,
1767
+ $eq: params.branchCode.$eq
1768
+ }
1769
+ }
1770
+ });
1771
+ }
1772
+ }
1773
+ const branchCodeIn = (_g = params.branchCode) === null || _g === void 0 ? void 0 : _g.$in;
1774
+ if (Array.isArray(branchCodeIn)) {
1775
+ matchStages.push({
1776
+ $match: {
1777
+ 'containsPlace.containsPlace.branchCode': {
1778
+ $exists: true,
1779
+ $in: branchCodeIn
1780
+ }
1781
+ }
1782
+ });
1783
+ }
1784
+ const branchCodeRegex = (_h = params.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
1785
+ if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
1786
+ matchStages.push({
1787
+ $match: {
1788
+ 'containsPlace.containsPlace.branchCode': {
1789
+ $exists: true,
1790
+ $regex: new RegExp(branchCodeRegex)
1791
+ }
1792
+ }
1793
+ });
1794
+ }
1795
+ const nameRegex = (_j = params.name) === null || _j === void 0 ? void 0 : _j.$regex;
1796
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
1797
+ matchStages.push({
1798
+ $match: {
1799
+ $or: [
1800
+ {
1801
+ 'containsPlace.containsPlace.name.ja': {
1802
+ $exists: true,
1803
+ $regex: new RegExp(nameRegex)
1804
+ }
1805
+ },
1806
+ {
1807
+ 'containsPlace.containsPlace.name.en': {
1003
1808
  $exists: true,
1004
- $eq: params.containedInPlace.containedInPlace.branchCode.$eq
1809
+ $regex: new RegExp(nameRegex)
1005
1810
  }
1006
1811
  }
1007
- });
1812
+ ]
1813
+ }
1814
+ });
1815
+ }
1816
+ const seatingTypeEq = (_k = params.seatingType) === null || _k === void 0 ? void 0 : _k.$eq;
1817
+ if (typeof seatingTypeEq === 'string') {
1818
+ matchStages.push({
1819
+ $match: {
1820
+ 'containsPlace.containsPlace.seatingType': {
1821
+ $exists: true,
1822
+ $eq: seatingTypeEq
1823
+ }
1824
+ }
1825
+ });
1826
+ }
1827
+ let includeScreeningRooms = true;
1828
+ if (params.$projection !== undefined && params.$projection !== null
1829
+ && params.$projection['containedInPlace.containedInPlace'] === 0) {
1830
+ includeScreeningRooms = false;
1831
+ }
1832
+ const additionalPropertyElemMatch = (_l = params.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
1833
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
1834
+ matchStages.push({
1835
+ $match: {
1836
+ 'containsPlace.containsPlace.additionalProperty': {
1837
+ $exists: true,
1838
+ $elemMatch: additionalPropertyElemMatch
1839
+ }
1840
+ }
1841
+ });
1842
+ }
1843
+ const aggregate = this.placeModel.aggregate([
1844
+ { $unwind: '$containsPlace' },
1845
+ { $unwind: '$containsPlace.containsPlace' },
1846
+ // { $unwind: '$containsPlace.containsPlace.containsPlace' },
1847
+ ...matchStages,
1848
+ {
1849
+ $project: {
1850
+ _id: 0,
1851
+ typeOf: '$containsPlace.containsPlace.typeOf',
1852
+ branchCode: '$containsPlace.containsPlace.branchCode',
1853
+ name: '$containsPlace.containsPlace.name',
1854
+ seatingType: '$containsPlace.containsPlace.seatingType',
1855
+ containedInPlace: Object.assign({ typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name' }, (includeScreeningRooms)
1856
+ ? {
1857
+ containedInPlace: {
1858
+ typeOf: '$typeOf',
1859
+ branchCode: '$branchCode',
1860
+ name: '$name',
1861
+ containedInPlace: {
1862
+ id: '$containedInPlace.id',
1863
+ typeOf: '$containedInPlace.typeOf',
1864
+ branchCode: '$containedInPlace.branchCode',
1865
+ name: '$containedInPlace.name'
1866
+ }
1867
+ }
1868
+ }
1869
+ : undefined),
1870
+ additionalProperty: '$containsPlace.containsPlace.additionalProperty'
1008
1871
  }
1009
1872
  }
1010
- if (params.containedInPlace.containedInPlace.containedInPlace !== undefined) {
1011
- if (params.containedInPlace.containedInPlace.containedInPlace.branchCode !== undefined) {
1012
- if (typeof params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1873
+ ]);
1874
+ if (typeof params.limit === 'number' && params.limit > 0) {
1875
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
1876
+ aggregate.limit(params.limit * page)
1877
+ .skip(params.limit * (page - 1));
1878
+ }
1879
+ return aggregate.exec();
1880
+ }
1881
+ else {
1882
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
1883
+ const projectIdEq = (_o = (_m = params.project) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$eq;
1884
+ if (typeof projectIdEq === 'string') {
1885
+ matchStages.push({
1886
+ $match: { 'project.id': { $eq: projectIdEq } }
1887
+ });
1888
+ }
1889
+ const containedInPlaceBranchCodeEq = (_q = (_p = params.containedInPlace) === null || _p === void 0 ? void 0 : _p.branchCode) === null || _q === void 0 ? void 0 : _q.$eq;
1890
+ if (typeof containedInPlaceBranchCodeEq === 'string') {
1891
+ matchStages.push({
1892
+ $match: {
1893
+ 'containsPlace.containsPlace.branchCode': {
1894
+ $exists: true,
1895
+ $eq: containedInPlaceBranchCodeEq
1896
+ }
1897
+ }
1898
+ });
1899
+ }
1900
+ const containedInPlaceBranchCodeIn = (_s = (_r = params.containedInPlace) === null || _r === void 0 ? void 0 : _r.branchCode) === null || _s === void 0 ? void 0 : _s.$in;
1901
+ if (Array.isArray(containedInPlaceBranchCodeIn)) {
1902
+ matchStages.push({
1903
+ $match: {
1904
+ 'containsPlace.containsPlace.branchCode': {
1905
+ $exists: true,
1906
+ $in: containedInPlaceBranchCodeIn
1907
+ }
1908
+ }
1909
+ });
1910
+ }
1911
+ if (params.containedInPlace !== undefined) {
1912
+ if (params.containedInPlace.containedInPlace !== undefined) {
1913
+ if (params.containedInPlace.containedInPlace.branchCode !== undefined) {
1914
+ if (typeof params.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1013
1915
  matchStages.push({
1014
1916
  $match: {
1015
- branchCode: {
1917
+ 'containsPlace.branchCode': {
1016
1918
  $exists: true,
1017
- $eq: params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq
1919
+ $eq: params.containedInPlace.containedInPlace.branchCode.$eq
1018
1920
  }
1019
1921
  }
1020
1922
  });
1021
1923
  }
1022
1924
  }
1925
+ if (params.containedInPlace.containedInPlace.containedInPlace !== undefined) {
1926
+ if (params.containedInPlace.containedInPlace.containedInPlace.branchCode !== undefined) {
1927
+ if (typeof params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1928
+ matchStages.push({
1929
+ $match: {
1930
+ branchCode: {
1931
+ $exists: true,
1932
+ $eq: params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq
1933
+ }
1934
+ }
1935
+ });
1936
+ }
1937
+ }
1938
+ }
1023
1939
  }
1024
1940
  }
1025
- }
1026
- // 座席コード
1027
- if (params.branchCode !== undefined) {
1028
- if (typeof params.branchCode.$eq === 'string') {
1941
+ // 座席コード
1942
+ if (params.branchCode !== undefined) {
1943
+ if (typeof params.branchCode.$eq === 'string') {
1944
+ matchStages.push({
1945
+ $match: {
1946
+ 'containsPlace.containsPlace.containsPlace.branchCode': {
1947
+ $exists: true,
1948
+ $eq: params.branchCode.$eq
1949
+ }
1950
+ }
1951
+ });
1952
+ }
1953
+ }
1954
+ const branchCodeIn = (_t = params.branchCode) === null || _t === void 0 ? void 0 : _t.$in;
1955
+ if (Array.isArray(branchCodeIn)) {
1029
1956
  matchStages.push({
1030
1957
  $match: {
1031
1958
  'containsPlace.containsPlace.containsPlace.branchCode': {
1032
1959
  $exists: true,
1033
- $eq: params.branchCode.$eq
1960
+ $in: branchCodeIn
1034
1961
  }
1035
1962
  }
1036
1963
  });
1037
1964
  }
1038
- }
1039
- const branchCodeIn = (_g = params.branchCode) === null || _g === void 0 ? void 0 : _g.$in;
1040
- if (Array.isArray(branchCodeIn)) {
1041
- matchStages.push({
1042
- $match: {
1043
- 'containsPlace.containsPlace.containsPlace.branchCode': {
1044
- $exists: true,
1045
- $in: branchCodeIn
1046
- }
1047
- }
1048
- });
1049
- }
1050
- const branchCodeRegex = (_h = params.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
1051
- if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
1052
- matchStages.push({
1053
- $match: {
1054
- 'containsPlace.containsPlace.containsPlace.branchCode': {
1055
- $exists: true,
1056
- $regex: new RegExp(branchCodeRegex)
1965
+ const branchCodeRegex = (_u = params.branchCode) === null || _u === void 0 ? void 0 : _u.$regex;
1966
+ if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
1967
+ matchStages.push({
1968
+ $match: {
1969
+ 'containsPlace.containsPlace.containsPlace.branchCode': {
1970
+ $exists: true,
1971
+ $regex: new RegExp(branchCodeRegex)
1972
+ }
1057
1973
  }
1058
- }
1059
- });
1060
- }
1061
- const nameRegex = (_j = params.name) === null || _j === void 0 ? void 0 : _j.$regex;
1062
- if (typeof nameRegex === 'string' && nameRegex.length > 0) {
1063
- matchStages.push({
1064
- $match: {
1065
- $or: [
1066
- {
1067
- 'containsPlace.containsPlace.containsPlace.name.ja': {
1068
- $exists: true,
1069
- $regex: new RegExp(nameRegex)
1070
- }
1071
- },
1072
- {
1073
- 'containsPlace.containsPlace.containsPlace.name.en': {
1074
- $exists: true,
1075
- $regex: new RegExp(nameRegex)
1974
+ });
1975
+ }
1976
+ const nameRegex = (_v = params.name) === null || _v === void 0 ? void 0 : _v.$regex;
1977
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
1978
+ matchStages.push({
1979
+ $match: {
1980
+ $or: [
1981
+ {
1982
+ 'containsPlace.containsPlace.containsPlace.name.ja': {
1983
+ $exists: true,
1984
+ $regex: new RegExp(nameRegex)
1985
+ }
1986
+ },
1987
+ {
1988
+ 'containsPlace.containsPlace.containsPlace.name.en': {
1989
+ $exists: true,
1990
+ $regex: new RegExp(nameRegex)
1991
+ }
1076
1992
  }
1993
+ ]
1994
+ }
1995
+ });
1996
+ }
1997
+ const seatingTypeEq = (_w = params.seatingType) === null || _w === void 0 ? void 0 : _w.$eq;
1998
+ if (typeof seatingTypeEq === 'string') {
1999
+ matchStages.push({
2000
+ $match: {
2001
+ 'containsPlace.containsPlace.containsPlace.seatingType': {
2002
+ $exists: true,
2003
+ $eq: seatingTypeEq
2004
+ }
2005
+ }
2006
+ });
2007
+ }
2008
+ let includeScreeningRooms = true;
2009
+ if (params.$projection !== undefined && params.$projection !== null
2010
+ && params.$projection['containedInPlace.containedInPlace'] === 0) {
2011
+ includeScreeningRooms = false;
2012
+ }
2013
+ const additionalPropertyElemMatch = (_x = params.additionalProperty) === null || _x === void 0 ? void 0 : _x.$elemMatch;
2014
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
2015
+ matchStages.push({
2016
+ $match: {
2017
+ 'containsPlace.containsPlace.containsPlace.additionalProperty': {
2018
+ $exists: true,
2019
+ $elemMatch: additionalPropertyElemMatch
1077
2020
  }
1078
- ]
2021
+ }
2022
+ });
2023
+ }
2024
+ const aggregate = this.placeModel.aggregate([
2025
+ { $unwind: '$containsPlace' },
2026
+ { $unwind: '$containsPlace.containsPlace' },
2027
+ { $unwind: '$containsPlace.containsPlace.containsPlace' },
2028
+ ...matchStages,
2029
+ {
2030
+ $project: {
2031
+ _id: 0,
2032
+ typeOf: '$containsPlace.containsPlace.containsPlace.typeOf',
2033
+ branchCode: '$containsPlace.containsPlace.containsPlace.branchCode',
2034
+ name: '$containsPlace.containsPlace.containsPlace.name',
2035
+ seatingType: '$containsPlace.containsPlace.containsPlace.seatingType',
2036
+ containedInPlace: Object.assign({ typeOf: '$containsPlace.containsPlace.typeOf', branchCode: '$containsPlace.containsPlace.branchCode', name: '$containsPlace.containsPlace.name' }, (includeScreeningRooms)
2037
+ ? {
2038
+ containedInPlace: {
2039
+ typeOf: '$containsPlace.typeOf',
2040
+ branchCode: '$containsPlace.branchCode',
2041
+ name: '$containsPlace.name',
2042
+ containedInPlace: {
2043
+ id: { $toString: '$_id' },
2044
+ // id: '$_id',
2045
+ typeOf: '$typeOf',
2046
+ branchCode: '$branchCode',
2047
+ name: '$name'
2048
+ }
2049
+ }
2050
+ }
2051
+ : undefined),
2052
+ additionalProperty: '$containsPlace.containsPlace.containsPlace.additionalProperty'
2053
+ }
1079
2054
  }
1080
- });
2055
+ ]);
2056
+ if (typeof params.limit === 'number' && params.limit > 0) {
2057
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
2058
+ aggregate.limit(params.limit * page)
2059
+ .skip(params.limit * (page - 1));
2060
+ }
2061
+ return aggregate.exec();
1081
2062
  }
1082
- const seatingTypeEq = (_k = params.seatingType) === null || _k === void 0 ? void 0 : _k.$eq;
1083
- if (typeof seatingTypeEq === 'string') {
1084
- matchStages.push({
1085
- $match: {
1086
- 'containsPlace.containsPlace.containsPlace.seatingType': {
1087
- $exists: true,
1088
- $eq: seatingTypeEq
2063
+ });
2064
+ }
2065
+ deleteSeat(seat, useScreeningRoomType) {
2066
+ return __awaiter(this, void 0, void 0, function* () {
2067
+ if (useScreeningRoomType === true) {
2068
+ const doc = yield this.placeModel.findOneAndUpdate({
2069
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
2070
+ 'project.id': { $eq: seat.project.id },
2071
+ 'containedInPlace.branchCode': {
2072
+ $exists: true,
2073
+ $eq: seat.containedInPlace.containedInPlace.containedInPlace.branchCode
2074
+ },
2075
+ branchCode: { $eq: seat.containedInPlace.containedInPlace.branchCode },
2076
+ 'containsPlace.branchCode': { $eq: seat.containedInPlace.branchCode },
2077
+ 'containsPlace.containsPlace.branchCode': { $eq: seat.branchCode }
2078
+ }, {
2079
+ $pull: {
2080
+ 'containsPlace.$[screeningRoomSection].containsPlace': {
2081
+ branchCode: seat.branchCode
1089
2082
  }
1090
2083
  }
1091
- });
1092
- }
1093
- let includeScreeningRooms = true;
1094
- if (params.$projection !== undefined && params.$projection !== null
1095
- && params.$projection['containedInPlace.containedInPlace'] === 0) {
1096
- includeScreeningRooms = false;
2084
+ }, {
2085
+ new: true,
2086
+ arrayFilters: [
2087
+ { 'screeningRoomSection.branchCode': { $eq: seat.containedInPlace.branchCode } }
2088
+ ],
2089
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
2090
+ })
2091
+ .exec();
2092
+ if (doc === null) {
2093
+ throw new factory.errors.NotFound(factory.placeType.Seat);
2094
+ }
2095
+ return doc.toObject();
1097
2096
  }
1098
- const additionalPropertyElemMatch = (_l = params.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
1099
- if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
1100
- matchStages.push({
1101
- $match: {
1102
- 'containsPlace.containsPlace.containsPlace.additionalProperty': {
1103
- $exists: true,
1104
- $elemMatch: additionalPropertyElemMatch
2097
+ else {
2098
+ const doc = yield this.placeModel.findOneAndUpdate({
2099
+ typeOf: { $eq: factory.placeType.MovieTheater },
2100
+ 'project.id': { $eq: seat.project.id },
2101
+ branchCode: seat.containedInPlace.containedInPlace.containedInPlace.branchCode,
2102
+ 'containsPlace.branchCode': seat.containedInPlace.containedInPlace.branchCode,
2103
+ 'containsPlace.containsPlace.branchCode': seat.containedInPlace.branchCode,
2104
+ 'containsPlace.containsPlace.containsPlace.branchCode': seat.branchCode
2105
+ }, {
2106
+ $pull: {
2107
+ 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': {
2108
+ branchCode: seat.branchCode
1105
2109
  }
1106
2110
  }
1107
- });
1108
- }
1109
- const aggregate = this.placeModel.aggregate([
1110
- { $unwind: '$containsPlace' },
1111
- { $unwind: '$containsPlace.containsPlace' },
1112
- { $unwind: '$containsPlace.containsPlace.containsPlace' },
1113
- ...matchStages,
1114
- {
1115
- $project: {
1116
- _id: 0,
1117
- typeOf: '$containsPlace.containsPlace.containsPlace.typeOf',
1118
- branchCode: '$containsPlace.containsPlace.containsPlace.branchCode',
1119
- name: '$containsPlace.containsPlace.containsPlace.name',
1120
- seatingType: '$containsPlace.containsPlace.containsPlace.seatingType',
1121
- containedInPlace: Object.assign({ typeOf: '$containsPlace.containsPlace.typeOf', branchCode: '$containsPlace.containsPlace.branchCode', name: '$containsPlace.containsPlace.name' }, (includeScreeningRooms)
1122
- ? {
1123
- containedInPlace: {
1124
- typeOf: '$containsPlace.typeOf',
1125
- branchCode: '$containsPlace.branchCode',
1126
- name: '$containsPlace.name',
1127
- containedInPlace: {
1128
- id: '$_id',
1129
- typeOf: '$typeOf',
1130
- branchCode: '$branchCode',
1131
- name: '$name'
1132
- }
1133
- }
1134
- }
1135
- : undefined),
1136
- additionalProperty: '$containsPlace.containsPlace.containsPlace.additionalProperty'
2111
+ }, {
2112
+ new: true,
2113
+ arrayFilters: [
2114
+ { 'screeningRoom.branchCode': seat.containedInPlace.containedInPlace.branchCode },
2115
+ { 'screeningRoomSection.branchCode': seat.containedInPlace.branchCode }
2116
+ ],
2117
+ projection: {
2118
+ _id: 1,
2119
+ typeOf: 1
1137
2120
  }
2121
+ })
2122
+ .exec();
2123
+ if (doc === null) {
2124
+ throw new factory.errors.NotFound(factory.placeType.Seat);
1138
2125
  }
1139
- ]);
1140
- if (typeof params.limit === 'number' && params.limit > 0) {
1141
- const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
1142
- aggregate.limit(params.limit * page)
1143
- .skip(params.limit * (page - 1));
2126
+ return doc.toObject();
1144
2127
  }
1145
- return aggregate.exec();
1146
2128
  });
1147
2129
  }
1148
- deleteSeat(seat) {
2130
+ syncScreeningRooms(params) {
1149
2131
  return __awaiter(this, void 0, void 0, function* () {
1150
- const doc = yield this.placeModel.findOneAndUpdate({
1151
- 'project.id': { $eq: seat.project.id },
1152
- branchCode: seat.containedInPlace.containedInPlace.containedInPlace.branchCode,
1153
- 'containsPlace.branchCode': seat.containedInPlace.containedInPlace.branchCode,
1154
- 'containsPlace.containsPlace.branchCode': seat.containedInPlace.branchCode,
1155
- 'containsPlace.containsPlace.containsPlace.branchCode': seat.branchCode
1156
- }, {
1157
- $pull: {
1158
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': {
1159
- branchCode: seat.branchCode
1160
- }
2132
+ if (params.useScreeningRoomType === true) {
2133
+ return;
2134
+ }
2135
+ const movieTheater = yield this.placeModel.findOne({
2136
+ _id: { $eq: params.id },
2137
+ typeOf: { $eq: factory.placeType.MovieTheater }
2138
+ })
2139
+ .select({
2140
+ _id: 1, branchCode: 1, name: 1, project: 1, typeOf: 1, containsPlace: 1
2141
+ })
2142
+ .exec()
2143
+ .then((doc) => {
2144
+ if (doc === null) {
2145
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
2146
+ }
2147
+ return doc.toObject();
2148
+ });
2149
+ let screeningRoomsFromMovieTheater = movieTheater.containsPlace;
2150
+ if (typeof params.screeningRoomBranchCode === 'string' && params.screeningRoomBranchCode.length > 0) {
2151
+ screeningRoomsFromMovieTheater = screeningRoomsFromMovieTheater.filter((place) => place.branchCode === params.screeningRoomBranchCode);
2152
+ }
2153
+ const creatingScreeningRooms = screeningRoomsFromMovieTheater.map((place) => {
2154
+ return Object.assign(Object.assign({}, place), { containedInPlace: {
2155
+ id: movieTheater.id,
2156
+ typeOf: movieTheater.typeOf,
2157
+ branchCode: movieTheater.branchCode,
2158
+ name: movieTheater.name
2159
+ }, containsPlace: (Array.isArray(place.containsPlace)) ? place.containsPlace : [], project: movieTheater.project });
2160
+ });
2161
+ debug('sync processing', creatingScreeningRooms.length, 'screeningRooms...', creatingScreeningRooms);
2162
+ yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
2163
+ const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
2164
+ if (typeof branchCode === 'string' && branchCode.length > 0) {
2165
+ const upsertScreeningRoomResult = yield this.placeModel.findOneAndUpdate({
2166
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
2167
+ 'project.id': { $eq: createScreeningRoom.project.id },
2168
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
2169
+ branchCode: { $eq: createScreeningRoom.branchCode }
2170
+ }, {
2171
+ $setOnInsert: {
2172
+ typeOf: createScreeningRoom.typeOf,
2173
+ project: createScreeningRoom.project,
2174
+ branchCode: createScreeningRoom.branchCode
2175
+ },
2176
+ $set: setFields
2177
+ }, {
2178
+ upsert: true,
2179
+ new: true,
2180
+ projection: { _id: 1 }
2181
+ })
2182
+ .exec();
2183
+ debug('screeningRoom upserted. upsertScreeningRoomResult:', upsertScreeningRoomResult);
1161
2184
  }
2185
+ })));
2186
+ });
2187
+ }
2188
+ unsetContainsPlaceFromMovieTheater(params) {
2189
+ return __awaiter(this, void 0, void 0, function* () {
2190
+ return this.placeModel.findOneAndUpdate({
2191
+ _id: { $eq: params.id },
2192
+ typeOf: { $eq: factory.placeType.MovieTheater },
2193
+ 'containsPlace.branchCode': { $exists: true }
1162
2194
  }, {
1163
- new: true,
1164
- arrayFilters: [
1165
- { 'screeningRoom.branchCode': seat.containedInPlace.containedInPlace.branchCode },
1166
- { 'screeningRoomSection.branchCode': seat.containedInPlace.branchCode }
1167
- ]
2195
+ $unset: { containsPlace: 1 }
1168
2196
  })
1169
- .exec();
1170
- if (doc === null) {
1171
- throw new factory.errors.NotFound(factory.placeType.Seat);
1172
- }
2197
+ .select({ _id: 1 })
2198
+ .exec()
2199
+ .then((doc) => {
2200
+ if (doc === null) {
2201
+ return;
2202
+ }
2203
+ return doc.toObject();
2204
+ });
1173
2205
  });
1174
2206
  }
1175
2207
  deleteByProject(params) {
@@ -1235,7 +2267,7 @@ class MongoRepository {
1235
2267
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
1236
2268
  query.sort({ branchCode: params.sort.branchCode });
1237
2269
  }
1238
- return query.setOptions({ maxTimeMS: 10000 })
2270
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
1239
2271
  .exec()
1240
2272
  .then((docs) => docs.map((doc) => doc.toObject()));
1241
2273
  });