@chevre/domain 21.2.0-alpha.16 → 21.2.0-alpha.160

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