@chevre/domain 21.2.0-alpha.15 → 21.2.0-alpha.150

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