@chevre/domain 21.2.0-alpha.99 → 21.3.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/example/src/chevre/aggregateEventReservation.ts +1 -1
  2. package/example/src/chevre/aggregateSellerPaymentAccepted.ts +27 -0
  3. package/example/src/chevre/aggregation/aggregateSystem.ts +53 -22
  4. package/example/src/chevre/countDelayedTasks.ts +7 -2
  5. package/example/src/chevre/createManyEventsIfNotExist.ts +199 -46
  6. package/example/src/chevre/findScreeningRoomsByBranchCode.ts +2 -2
  7. package/example/src/chevre/giveUpStartDatePassedCertainPeriod.ts +56 -0
  8. package/example/src/chevre/lockStockHolder.ts +5 -2
  9. package/example/src/chevre/migrateCategoryCodeAdditionalProperties.ts +116 -0
  10. package/example/src/chevre/migrateScreeningEventSeriesVersion.ts +79 -0
  11. package/example/src/chevre/ownershipInfosCsv2peopleJson.ts +1 -1
  12. package/example/src/chevre/processRegisterMembership.ts +8 -4
  13. package/example/src/chevre/processRegisterPaymentCard.ts +8 -4
  14. package/example/src/chevre/processReserve.ts +1 -1
  15. package/example/src/chevre/searchAbortedTasks.ts +4 -6
  16. package/example/src/chevre/searchEventSeats.ts +5 -2
  17. package/example/src/chevre/searchHoldReservations.ts +38 -0
  18. package/example/src/chevre/searchPermissions.ts +54 -0
  19. package/example/src/chevre/searchScreeningRooms.ts +33 -0
  20. package/example/src/chevre/sendEmailMessage.ts +1 -2
  21. package/example/src/chevre/syncScreeningRooms.ts +21 -0
  22. package/example/src/chevre/syncScreeningRoomsAll.ts +41 -0
  23. package/example/src/chevre/unsetContainsInPlaceFromMovieTheater.ts +41 -0
  24. package/lib/chevre/factory/order.d.ts +4 -1
  25. package/lib/chevre/factory/order.js +19 -6
  26. package/lib/chevre/repo/account.js +3 -2
  27. package/lib/chevre/repo/accountTransaction.js +2 -1
  28. package/lib/chevre/repo/accountingReport.d.ts +1 -3
  29. package/lib/chevre/repo/action.d.ts +50 -1
  30. package/lib/chevre/repo/action.js +53 -2
  31. package/lib/chevre/repo/additionalProperty.js +2 -1
  32. package/lib/chevre/repo/aggregation.d.ts +3 -0
  33. package/lib/chevre/repo/aggregation.js +3 -0
  34. package/lib/chevre/repo/assetTransaction.js +6 -5
  35. package/lib/chevre/repo/categoryCode.d.ts +1 -1
  36. package/lib/chevre/repo/categoryCode.js +37 -25
  37. package/lib/chevre/repo/code.js +3 -2
  38. package/lib/chevre/repo/comment.js +2 -1
  39. package/lib/chevre/repo/creativeWork.d.ts +1 -1
  40. package/lib/chevre/repo/creativeWork.js +35 -12
  41. package/lib/chevre/repo/customer.js +2 -1
  42. package/lib/chevre/repo/emailMessage.js +2 -1
  43. package/lib/chevre/repo/event.d.ts +30 -2
  44. package/lib/chevre/repo/event.js +87 -36
  45. package/lib/chevre/repo/member.d.ts +14 -0
  46. package/lib/chevre/repo/member.js +31 -3
  47. package/lib/chevre/repo/merchantReturnPolicy.js +2 -1
  48. package/lib/chevre/repo/mongoose/schemas/assetTransaction.d.ts +3 -3
  49. package/lib/chevre/repo/mongoose/schemas/holdReservation.d.ts +75 -0
  50. package/lib/chevre/repo/mongoose/schemas/holdReservation.js +93 -0
  51. package/lib/chevre/repo/mongoose/schemas/offer.d.ts +3 -3
  52. package/lib/chevre/repo/mongoose/schemas/order.d.ts +21 -21
  53. package/lib/chevre/repo/mongoose/schemas/place.d.ts +6 -0
  54. package/lib/chevre/repo/mongoose/schemas/place.js +16 -1
  55. package/lib/chevre/repo/mongoose/schemas/product.js +6 -0
  56. package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +9 -9
  57. package/lib/chevre/repo/mongoose/schemas/transaction.d.ts +3 -3
  58. package/lib/chevre/repo/offer.js +3 -2
  59. package/lib/chevre/repo/offerCatalog.js +0 -27
  60. package/lib/chevre/repo/offerItemCondition.js +2 -1
  61. package/lib/chevre/repo/order.js +8 -7
  62. package/lib/chevre/repo/ownershipInfo.js +2 -7
  63. package/lib/chevre/repo/paymentServiceProvider.d.ts +65 -0
  64. package/lib/chevre/repo/paymentServiceProvider.js +156 -0
  65. package/lib/chevre/repo/place.d.ts +143 -27
  66. package/lib/chevre/repo/place.js +445 -282
  67. package/lib/chevre/repo/priceSpecification.js +3 -2
  68. package/lib/chevre/repo/product.d.ts +5 -3
  69. package/lib/chevre/repo/product.js +92 -5
  70. package/lib/chevre/repo/project.js +2 -1
  71. package/lib/chevre/repo/reservation.d.ts +9 -1
  72. package/lib/chevre/repo/reservation.js +29 -20
  73. package/lib/chevre/repo/role.d.ts +7 -0
  74. package/lib/chevre/repo/role.js +39 -2
  75. package/lib/chevre/repo/seller.d.ts +22 -2
  76. package/lib/chevre/repo/seller.js +82 -6
  77. package/lib/chevre/repo/serviceOutput.js +2 -1
  78. package/lib/chevre/repo/stockHolder.d.ts +143 -7
  79. package/lib/chevre/repo/stockHolder.js +622 -104
  80. package/lib/chevre/repo/task.d.ts +12 -1
  81. package/lib/chevre/repo/task.js +17 -7
  82. package/lib/chevre/repo/transaction.js +6 -5
  83. package/lib/chevre/repo/trip.js +2 -1
  84. package/lib/chevre/repository.d.ts +6 -0
  85. package/lib/chevre/repository.js +8 -1
  86. package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +16 -7
  87. package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +19 -8
  88. package/lib/chevre/service/aggregation/system.d.ts +43 -1
  89. package/lib/chevre/service/aggregation/system.js +112 -2
  90. package/lib/chevre/service/assetTransaction/moneyTransfer.js +1 -1
  91. package/lib/chevre/service/assetTransaction/pay/account/validation.js +1 -1
  92. package/lib/chevre/service/assetTransaction/pay.js +2 -2
  93. package/lib/chevre/service/assetTransaction/refund.js +1 -1
  94. package/lib/chevre/service/assetTransaction/reserve.js +9 -2
  95. package/lib/chevre/service/event.d.ts +3 -0
  96. package/lib/chevre/service/event.js +52 -22
  97. package/lib/chevre/service/iam.d.ts +6 -2
  98. package/lib/chevre/service/iam.js +23 -9
  99. package/lib/chevre/service/offer/event/factory.js +22 -13
  100. package/lib/chevre/service/offer/event/importFromCOA.js +2 -2
  101. package/lib/chevre/service/offer/eventServiceByCOA/factory.js +15 -8
  102. package/lib/chevre/service/offer/eventServiceByCOA.js +7 -9
  103. package/lib/chevre/service/offer/product/factory.js +13 -6
  104. package/lib/chevre/service/offer/product.js +2 -2
  105. package/lib/chevre/service/offer.d.ts +16 -8
  106. package/lib/chevre/service/offer.js +70 -7
  107. package/lib/chevre/service/order/createAccountingReportIfNotExist.js +31 -17
  108. package/lib/chevre/service/order/onOrderStatusChanged/factory.js +1 -1
  109. package/lib/chevre/service/order/onOrderStatusChanged.js +2 -2
  110. package/lib/chevre/service/order/placeOrder.js +4 -4
  111. package/lib/chevre/service/order/returnOrder.js +1 -1
  112. package/lib/chevre/service/order/sendOrder.js +3 -3
  113. package/lib/chevre/service/payment/any/onPaymentStatusChanged.js +4 -6
  114. package/lib/chevre/service/payment/any/onRefund.js +46 -42
  115. package/lib/chevre/service/payment/creditCard.js +2 -2
  116. package/lib/chevre/service/payment/movieTicket/checkByIdentifier.d.ts +1 -1
  117. package/lib/chevre/service/payment/movieTicket/factory.d.ts +1 -1
  118. package/lib/chevre/service/payment/movieTicket/getCredentials.d.ts +1 -1
  119. package/lib/chevre/service/payment/movieTicket/getCredentials.js +1 -1
  120. package/lib/chevre/service/payment/movieTicket/validation.js +16 -9
  121. package/lib/chevre/service/payment/movieTicket.js +2 -2
  122. package/lib/chevre/service/reserve/cancelReservation.js +15 -3
  123. package/lib/chevre/service/reserve/confirmReservation.js +19 -11
  124. package/lib/chevre/service/task/aggregateScreeningEvent.js +1 -1
  125. package/lib/chevre/service/task/cancelPendingReservation.js +1 -1
  126. package/lib/chevre/service/task/cancelReservation.js +1 -1
  127. package/lib/chevre/service/task/deleteTransaction.js +2 -0
  128. package/lib/chevre/service/task/onEventChanged.d.ts +7 -0
  129. package/lib/chevre/service/task/onEventChanged.js +29 -0
  130. package/lib/chevre/service/task/onResourceUpdated.d.ts +7 -0
  131. package/lib/chevre/service/task/onResourceUpdated.js +396 -0
  132. package/lib/chevre/service/task/syncScreeningRooms.d.ts +7 -0
  133. package/lib/chevre/service/task/syncScreeningRooms.js +23 -0
  134. package/lib/chevre/service/task/voidReserveTransaction.js +1 -1
  135. package/lib/chevre/service/transaction/deleteTransaction.d.ts +2 -0
  136. package/lib/chevre/service/transaction/deleteTransaction.js +129 -1
  137. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +1 -0
  138. package/lib/chevre/service/transaction/moneyTransfer/factory.d.ts +1 -1
  139. package/lib/chevre/service/transaction/moneyTransfer.js +1 -1
  140. package/lib/chevre/service/transaction/orderProgramMembership/findCreditCard.js +1 -1
  141. package/lib/chevre/service/transaction/orderProgramMembership/findPaymentCardPermit.js +1 -1
  142. package/lib/chevre/service/transaction/orderProgramMembership.js +1 -1
  143. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +1 -0
  144. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/givePointAward.js +1 -1
  145. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/moneyTransfer.js +1 -1
  146. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/registerService.js +1 -1
  147. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions/sendEmailMessage.js +4 -4
  148. package/lib/chevre/service/transaction/placeOrderInProgress/potentialActions.js +3 -4
  149. package/lib/chevre/service/transaction/placeOrderInProgress/result/acceptedOffers.js +8 -12
  150. package/lib/chevre/service/transaction/placeOrderInProgress.js +6 -4
  151. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +1 -0
  152. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnMoneyTransfer.js +2 -2
  153. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPaymentMethod.js +5 -5
  154. package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.js +2 -2
  155. package/lib/chevre/service/transaction/returnOrder/potentialActions/sendEmailMessage.js +3 -3
  156. package/lib/chevre/service/transaction/returnOrder/potentialActions.js +1 -1
  157. package/lib/chevre/service/transaction/returnOrder.js +3 -1
  158. package/lib/chevre/settings.d.ts +9 -0
  159. package/lib/chevre/settings.js +42 -2
  160. package/package.json +3 -3
  161. package/example/src/chevre/eventCatalog2eventService.ts +0 -123
  162. package/example/src/chevre/migrateOrderAdditionalProperties.ts +0 -85
  163. package/example/src/chevre/migrateStockHolderKeys.ts +0 -89
@@ -21,9 +21,10 @@ 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 mongoose_1 = require("mongoose");
25
24
  const place_1 = require("./mongoose/schemas/place");
26
25
  const factory = require("../factory");
26
+ const settings_1 = require("../settings");
27
+ // const debug = createDebug('chevre-domain:repo:place');
27
28
  /**
28
29
  * 施設リポジトリ
29
30
  */
@@ -220,7 +221,16 @@ class MongoRepository {
220
221
  else {
221
222
  // 上書き禁止属性を除外(2022-08-24~)
222
223
  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 })
224
+ doc = yield this.placeModel.findOneAndUpdate({ _id: params.id }, updateFields, {
225
+ upsert: false,
226
+ new: true,
227
+ projection: {
228
+ __v: 0,
229
+ createdAt: 0,
230
+ updatedAt: 0,
231
+ containsPlace: 0
232
+ }
233
+ })
224
234
  .exec();
225
235
  }
226
236
  if (doc === null) {
@@ -229,50 +239,90 @@ class MongoRepository {
229
239
  return doc.toObject();
230
240
  });
231
241
  }
242
+ // void化(2023-06-23~)
232
243
  saveMovieTheaterByBranchCode4coa(params) {
233
244
  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({
245
+ const { containsPlace } = params, movieTheater4update = __rest(params, ["containsPlace"]);
246
+ const movieTheaterDoc = yield this.placeModel.findOneAndUpdate({
250
247
  typeOf: { $eq: factory.placeType.MovieTheater },
251
248
  'project.id': { $eq: params.project.id },
252
249
  branchCode: { $eq: params.branchCode }
253
- }, {
254
- __v: 0,
255
- createdAt: 0,
256
- updatedAt: 0
250
+ },
251
+ // containsPlaceの保管を廃止(2023-07-04~)
252
+ // params,
253
+ movieTheater4update, {
254
+ new: true,
255
+ projection: { _id: 1 }
257
256
  })
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();
257
+ .exec();
258
+ if (movieTheaterDoc === null) {
259
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
260
+ }
261
+ const movieTheater = movieTheaterDoc.toObject();
262
+ // ScreeningRoomも保管する(2023-06-24~)
263
+ const creatingScreeningRooms = params.containsPlace.map((place) => {
264
+ return Object.assign(Object.assign({}, place), { containedInPlace: {
265
+ id: movieTheater.id,
266
+ typeOf: params.typeOf,
267
+ branchCode: params.branchCode,
268
+ name: params.name
269
+ }, containsPlace: (Array.isArray(place.containsPlace)) ? place.containsPlace : [], project: params.project });
264
270
  });
271
+ yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
272
+ const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
273
+ if (typeof branchCode === 'string' && branchCode.length > 0) {
274
+ yield this.placeModel.findOneAndUpdate({
275
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
276
+ 'project.id': { $eq: createScreeningRoom.project.id },
277
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
278
+ branchCode: { $eq: createScreeningRoom.branchCode }
279
+ }, {
280
+ $setOnInsert: {
281
+ typeOf: createScreeningRoom.typeOf,
282
+ project: createScreeningRoom.project,
283
+ branchCode: createScreeningRoom.branchCode
284
+ },
285
+ $set: setFields
286
+ }, {
287
+ upsert: true,
288
+ new: true,
289
+ projection: { _id: 1 }
290
+ })
291
+ .exec();
292
+ }
293
+ })));
265
294
  });
266
295
  }
267
296
  /**
268
297
  * 施設検索
269
298
  */
270
- searchMovieTheaters(params) {
299
+ searchMovieTheaters(params,
300
+ // projection明示指定化(2023-06-22~)
301
+ inclusion, exclusion) {
271
302
  var _a;
272
303
  return __awaiter(this, void 0, void 0, function* () {
273
304
  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));
305
+ let projection = {};
306
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
307
+ inclusion.forEach((field) => {
308
+ projection[field] = 1;
309
+ });
310
+ }
311
+ else {
312
+ projection = {
313
+ __v: 0,
314
+ createdAt: 0,
315
+ updatedAt: 0,
316
+ // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
317
+ containsPlace: 0
318
+ };
319
+ if (Array.isArray(exclusion) && exclusion.length > 0) {
320
+ exclusion.forEach((field) => {
321
+ projection[field] = 0;
322
+ });
323
+ }
324
+ }
325
+ const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
276
326
  if (typeof params.limit === 'number' && params.limit > 0) {
277
327
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
278
328
  query.limit(params.limit)
@@ -283,33 +333,17 @@ class MongoRepository {
283
333
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
284
334
  query.sort({ branchCode: params.sort.branchCode });
285
335
  }
286
- return query.setOptions({ maxTimeMS: 10000 })
336
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
287
337
  .exec()
288
338
  .then((docs) => docs.map((doc) => doc.toObject()));
289
339
  });
290
340
  }
291
- /**
292
- * 施設取得
293
- */
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
- }
307
341
  deleteMovieTheaterById(params) {
308
342
  return __awaiter(this, void 0, void 0, function* () {
309
343
  yield this.placeModel.findOneAndDelete({
310
344
  typeOf: { $eq: factory.placeType.MovieTheater },
311
345
  _id: { $eq: params.id }
312
- })
346
+ }, { projection: { _id: 1 } })
313
347
  .exec()
314
348
  .then((doc) => {
315
349
  if (doc === null) {
@@ -321,94 +355,117 @@ class MongoRepository {
321
355
  createScreeningRoom(screeningRoom) {
322
356
  return __awaiter(this, void 0, void 0, function* () {
323
357
  // 施設存在確認
324
- let doc = yield this.placeModel.findOne({
358
+ const movieTheaterDoc = yield this.placeModel.findOne({
359
+ typeOf: { $eq: factory.placeType.MovieTheater },
325
360
  'project.id': { $eq: screeningRoom.project.id },
326
- branchCode: screeningRoom.containedInPlace.branchCode
327
- }, {
328
- _id: 1
329
- })
361
+ branchCode: { $eq: screeningRoom.containedInPlace.branchCode }
362
+ }, { _id: 1, typeOf: 1, branchCode: 1, name: 1 })
330
363
  .exec();
331
- if (doc === null) {
332
- throw new factory.errors.NotFound('containedInPlace');
364
+ if (movieTheaterDoc === null) {
365
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
333
366
  }
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
- }
348
- }
349
- }, {
350
- new: true,
351
- projection: {
352
- _id: 1,
353
- 'project.id': 1,
354
- branchCode: 1
355
- }
356
- })
367
+ const movieTheater = movieTheaterDoc.toObject();
368
+ const creatingScreeningRoom = Object.assign({ typeOf: screeningRoom.typeOf, branchCode: screeningRoom.branchCode, name: screeningRoom.name, address: screeningRoom.address, additionalProperty: (Array.isArray(screeningRoom.additionalProperty)) ? screeningRoom.additionalProperty : [], containedInPlace: {
369
+ id: movieTheater.id,
370
+ typeOf: movieTheater.typeOf,
371
+ branchCode: movieTheater.branchCode,
372
+ name: movieTheater.name
373
+ }, containsPlace: [], project: screeningRoom.project }, (typeof screeningRoom.openSeatingAllowed === 'boolean')
374
+ ? { openSeatingAllowed: screeningRoom.openSeatingAllowed }
375
+ : undefined);
376
+ const upsertScreeningRoomResult = yield this.placeModel.updateOne({
377
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
378
+ 'project.id': { $eq: creatingScreeningRoom.project.id },
379
+ 'containedInPlace.id': { $exists: true, $eq: creatingScreeningRoom.containedInPlace.id },
380
+ branchCode: { $eq: creatingScreeningRoom.branchCode }
381
+ },
382
+ // 既存であれば何もしない
383
+ { $setOnInsert: creatingScreeningRoom }, { upsert: true })
357
384
  .exec();
358
- // 存在しなければコード重複
359
- if (doc === null) {
385
+ // 既存であればコード重複
386
+ if (upsertScreeningRoomResult.matchedCount > 0) {
360
387
  throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoom, ['branchCode']);
361
388
  }
389
+ return {
390
+ containedInPlace: { id: creatingScreeningRoom.containedInPlace.id },
391
+ typeOf: factory.placeType.ScreeningRoom
392
+ };
362
393
  });
363
394
  }
364
395
  updateScreeningRoom(screeningRoom, $unset) {
365
396
  return __awaiter(this, void 0, void 0, function* () {
366
397
  const doc = yield this.placeModel.findOneAndUpdate({
398
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
367
399
  '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 }
400
+ 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode },
401
+ branchCode: screeningRoom.branchCode
402
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ name: screeningRoom.name }, (screeningRoom.address !== undefined && screeningRoom.address !== null)
403
+ ? { address: screeningRoom.address }
372
404
  : undefined), (typeof screeningRoom.openSeatingAllowed === 'boolean')
373
- ? { 'containsPlace.$[screeningRoom].openSeatingAllowed': screeningRoom.openSeatingAllowed }
405
+ ? { openSeatingAllowed: screeningRoom.openSeatingAllowed }
374
406
  : undefined), (Array.isArray(screeningRoom.additionalProperty))
375
- ? { 'containsPlace.$[screeningRoom].additionalProperty': screeningRoom.additionalProperty }
376
- : undefined), ($unset !== undefined && $unset !== null)
377
- ? { $unset }
407
+ ? { additionalProperty: screeningRoom.additionalProperty }
408
+ : undefined), (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].openSeatingAllowed']) === 1
409
+ || $unset.openSeatingAllowed === 1)
410
+ ? {
411
+ $unset: {
412
+ openSeatingAllowed: 1
413
+ }
414
+ }
378
415
  : undefined), {
379
416
  new: true,
380
- arrayFilters: [
381
- { 'screeningRoom.branchCode': screeningRoom.branchCode }
382
- ],
383
- projection: {
384
- _id: 1,
385
- 'project.id': 1,
386
- branchCode: 1
387
- }
417
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
388
418
  })
389
419
  .exec();
390
420
  if (doc === null) {
391
421
  throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
392
422
  }
423
+ return doc.toObject();
424
+ });
425
+ }
426
+ updateScreeningRoomsByContainedInPlaceId(screeningRoom) {
427
+ var _a;
428
+ return __awaiter(this, void 0, void 0, function* () {
429
+ if (typeof ((_a = screeningRoom.containedInPlace.name) === null || _a === void 0 ? void 0 : _a.ja) === 'string') {
430
+ yield this.placeModel.updateMany({
431
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
432
+ 'project.id': { $eq: screeningRoom.project.id },
433
+ 'containedInPlace.id': { $exists: true, $eq: screeningRoom.containedInPlace.id }
434
+ }, {
435
+ 'containedInPlace.name': screeningRoom.containedInPlace.name
436
+ })
437
+ .exec();
438
+ }
393
439
  });
394
440
  }
395
441
  deleteScreeningRoom(screeningRoom) {
396
442
  return __awaiter(this, void 0, void 0, function* () {
397
- const doc = yield this.placeModel.findOneAndUpdate({
443
+ const doc = yield this.placeModel.findOneAndDelete({
444
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
398
445
  'project.id': { $eq: screeningRoom.project.id },
399
- branchCode: screeningRoom.containedInPlace.branchCode,
400
- 'containsPlace.branchCode': screeningRoom.branchCode
446
+ 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode },
447
+ branchCode: screeningRoom.branchCode
401
448
  }, {
402
- $pull: {
403
- containsPlace: { branchCode: screeningRoom.branchCode }
404
- }
449
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
405
450
  })
406
451
  .exec();
407
452
  if (doc === null) {
408
453
  throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
409
454
  }
455
+ return doc.toObject();
456
+ });
457
+ }
458
+ deleteScreeningRoomsByMovieTheaterId(params) {
459
+ return __awaiter(this, void 0, void 0, function* () {
460
+ yield this.placeModel.deleteMany({
461
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
462
+ 'project.id': { $eq: params.project.id },
463
+ 'containedInPlace.id': { $exists: true, $eq: params.containedInPlace.id }
464
+ })
465
+ .exec();
410
466
  });
411
467
  }
468
+ // tslint:disable-next-line:max-func-body-length
412
469
  createScreeningRoomSection(screeningRoomSection) {
413
470
  return __awaiter(this, void 0, void 0, function* () {
414
471
  const screeningRoom = screeningRoomSection.containedInPlace;
@@ -421,44 +478,40 @@ class MongoRepository {
421
478
  }
422
479
  // 施設存在確認
423
480
  let doc = yield this.placeModel.findOne({
481
+ typeOf: { $eq: factory.placeType.MovieTheater },
424
482
  'project.id': { $eq: screeningRoomSection.project.id },
425
- branchCode: movieTheater.branchCode,
426
- 'containsPlace.branchCode': screeningRoom.branchCode
483
+ branchCode: { $eq: movieTheater.branchCode }
427
484
  }, { _id: 1 })
428
485
  .exec();
429
486
  if (doc === null) {
430
487
  throw new factory.errors.NotFound(factory.placeType.MovieTheater);
431
488
  }
489
+ // セクションコードが存在しなければ追加する
432
490
  doc = yield this.placeModel.findOneAndUpdate({
491
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
433
492
  'project.id': { $eq: screeningRoomSection.project.id },
434
- branchCode: movieTheater.branchCode,
435
- 'containsPlace.branchCode': screeningRoom.branchCode
436
- // 'containsPlace.containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
493
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
494
+ branchCode: { $eq: screeningRoom.branchCode },
495
+ 'containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
437
496
  }, {
438
497
  $push: {
439
- 'containsPlace.$[screeningRoom].containsPlace': Object.assign({ typeOf: screeningRoomSection.typeOf, branchCode: screeningRoomSection.branchCode, name: screeningRoomSection.name }, (Array.isArray(screeningRoomSection.additionalProperty))
498
+ containsPlace: Object.assign({ typeOf: screeningRoomSection.typeOf, branchCode: screeningRoomSection.branchCode, name: screeningRoomSection.name }, (Array.isArray(screeningRoomSection.additionalProperty))
440
499
  ? { additionalProperty: screeningRoomSection.additionalProperty }
441
500
  : undefined)
442
501
  }
443
502
  }, {
444
503
  new: true,
445
- arrayFilters: [
446
- {
447
- 'screeningRoom.branchCode': screeningRoom.branchCode,
448
- 'screeningRoom.containsPlace.branchCode': { $ne: screeningRoomSection.branchCode }
449
- }
450
- ],
451
- projection: {
452
- _id: 1
453
- }
504
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
454
505
  })
455
506
  .exec();
456
507
  // 存在しなければコード重複
457
508
  if (doc === null) {
458
509
  throw new factory.errors.AlreadyInUse(factory.placeType.ScreeningRoomSection, ['branchCode']);
459
510
  }
511
+ return doc.toObject();
460
512
  });
461
513
  }
514
+ // tslint:disable-next-line:max-func-body-length
462
515
  updateScreeningRoomSection(screeningRoomSection, $unset) {
463
516
  return __awaiter(this, void 0, void 0, function* () {
464
517
  const screeningRoom = screeningRoomSection.containedInPlace;
@@ -470,45 +523,44 @@ class MongoRepository {
470
523
  throw new factory.errors.ArgumentNull('containedInPlace.containedInPlace.branchCode');
471
524
  }
472
525
  const doc = yield this.placeModel.findOneAndUpdate({
526
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
473
527
  '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)
528
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
529
+ branchCode: { $eq: screeningRoom.branchCode },
530
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
531
+ }, Object.assign(Object.assign(Object.assign(Object.assign({ 'containsPlace.$[screeningRoomSection].branchCode': screeningRoomSection.branchCode }, (screeningRoomSection.name !== undefined && screeningRoomSection !== null)
478
532
  ? {
479
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].name': screeningRoomSection.name
533
+ 'containsPlace.$[screeningRoomSection].name': screeningRoomSection.name
480
534
  }
481
535
  : undefined), (Array.isArray(screeningRoomSection.additionalProperty))
482
536
  ? {
483
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].additionalProperty': screeningRoomSection.additionalProperty
537
+ 'containsPlace.$[screeningRoomSection].additionalProperty': screeningRoomSection.additionalProperty
484
538
  }
485
539
  : undefined), (Array.isArray(screeningRoomSection.containsPlace) && screeningRoomSection.containsPlace.length > 0)
486
540
  ? {
487
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': screeningRoomSection.containsPlace.map((p) => {
541
+ 'containsPlace.$[screeningRoomSection].containsPlace': screeningRoomSection.containsPlace.map((p) => {
488
542
  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
543
  })
490
544
  }
491
545
  : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
492
546
  new: true,
493
547
  arrayFilters: [
494
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
495
548
  { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode }
496
549
  ],
497
- projection: {
498
- _id: 1
499
- }
550
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
500
551
  })
501
552
  .exec();
502
553
  if (doc === null) {
503
554
  throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
504
555
  }
556
+ return doc.toObject();
505
557
  });
506
558
  }
507
- // tslint:disable-next-line:max-func-body-length
559
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
508
560
  searchScreeningRoomSections(searchConditions) {
509
561
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
510
562
  return __awaiter(this, void 0, void 0, function* () {
511
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
563
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
512
564
  const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
513
565
  if (typeof projectIdEq === 'string') {
514
566
  matchStages.push({
@@ -520,7 +572,7 @@ class MongoRepository {
520
572
  if (typeof movieTheaterBranchCodeEq === 'string') {
521
573
  matchStages.push({
522
574
  $match: {
523
- branchCode: {
575
+ 'containedInPlace.branchCode': {
524
576
  $exists: true,
525
577
  $eq: movieTheaterBranchCodeEq
526
578
  }
@@ -532,8 +584,7 @@ class MongoRepository {
532
584
  if (typeof containedInPlaceBranchCodeEq === 'string') {
533
585
  matchStages.push({
534
586
  $match: {
535
- 'containsPlace.branchCode': {
536
- $exists: true,
587
+ branchCode: {
537
588
  $eq: containedInPlaceBranchCodeEq
538
589
  }
539
590
  }
@@ -544,7 +595,7 @@ class MongoRepository {
544
595
  if (typeof sectionBranchCodeEq === 'string') {
545
596
  matchStages.push({
546
597
  $match: {
547
- 'containsPlace.containsPlace.branchCode': {
598
+ 'containsPlace.branchCode': {
548
599
  $exists: true,
549
600
  $eq: sectionBranchCodeEq
550
601
  }
@@ -557,13 +608,13 @@ class MongoRepository {
557
608
  $match: {
558
609
  $or: [
559
610
  {
560
- 'containsPlace.containsPlace.name.ja': {
611
+ 'containsPlace.name.ja': {
561
612
  $exists: true,
562
613
  $regex: new RegExp(nameCodeRegex)
563
614
  }
564
615
  },
565
616
  {
566
- 'containsPlace.containsPlace.name.en': {
617
+ 'containsPlace.name.en': {
567
618
  $exists: true,
568
619
  $regex: new RegExp(nameCodeRegex)
569
620
  }
@@ -576,7 +627,7 @@ class MongoRepository {
576
627
  if (typeof branchCodeRegex === 'string') {
577
628
  matchStages.push({
578
629
  $match: {
579
- 'containsPlace.containsPlace.branchCode': {
630
+ 'containsPlace.branchCode': {
580
631
  $exists: true,
581
632
  $regex: new RegExp(branchCodeRegex)
582
633
  }
@@ -587,7 +638,7 @@ class MongoRepository {
587
638
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
588
639
  matchStages.push({
589
640
  $match: {
590
- 'containsPlace.containsPlace.additionalProperty': {
641
+ 'containsPlace.additionalProperty': {
591
642
  $exists: true,
592
643
  $elemMatch: additionalPropertyElemMatch
593
644
  }
@@ -596,25 +647,24 @@ class MongoRepository {
596
647
  }
597
648
  const aggregate = this.placeModel.aggregate([
598
649
  { $unwind: '$containsPlace' },
599
- { $unwind: '$containsPlace.containsPlace' },
600
650
  ...matchStages,
601
651
  {
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',
652
+ $project: Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', containedInPlace: {
653
+ typeOf: '$typeOf',
654
+ branchCode: '$branchCode',
655
+ name: '$name',
606
656
  containedInPlace: {
607
- id: '$_id',
608
- typeOf: '$typeOf',
609
- branchCode: '$branchCode',
610
- name: '$name'
657
+ id: '$containedInPlace.id',
658
+ typeOf: '$containedInPlace.typeOf',
659
+ branchCode: '$containedInPlace.branchCode',
660
+ name: '$containedInPlace.name'
611
661
  }
612
- }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
662
+ }, additionalProperty: '$containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
613
663
  ? {
614
664
  seatCount: {
615
665
  $cond: {
616
- if: { $isArray: '$containsPlace.containsPlace.containsPlace' },
617
- then: { $size: '$containsPlace.containsPlace.containsPlace' },
666
+ if: { $isArray: '$containsPlace.containsPlace' },
667
+ then: { $size: '$containsPlace.containsPlace' },
618
668
  else: 0
619
669
  }
620
670
  }
@@ -635,33 +685,36 @@ class MongoRepository {
635
685
  deleteScreeningRoomSection(screeningRoomSection) {
636
686
  return __awaiter(this, void 0, void 0, function* () {
637
687
  const doc = yield this.placeModel.findOneAndUpdate({
688
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
638
689
  'project.id': { $eq: screeningRoomSection.project.id },
639
- branchCode: screeningRoomSection.containedInPlace.containedInPlace.branchCode,
640
- 'containsPlace.branchCode': screeningRoomSection.containedInPlace.branchCode,
641
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
690
+ 'containedInPlace.branchCode': {
691
+ $exists: true,
692
+ $eq: screeningRoomSection.containedInPlace.containedInPlace.branchCode
693
+ },
694
+ branchCode: { $eq: screeningRoomSection.containedInPlace.branchCode },
695
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
642
696
  }, {
643
697
  $pull: {
644
- 'containsPlace.$[screeningRoom].containsPlace': {
698
+ containsPlace: {
645
699
  branchCode: screeningRoomSection.branchCode
646
700
  }
647
701
  }
648
702
  }, {
649
703
  new: true,
650
- arrayFilters: [
651
- { 'screeningRoom.branchCode': screeningRoomSection.containedInPlace.branchCode }
652
- ]
704
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
653
705
  })
654
706
  .exec();
655
707
  if (doc === null) {
656
708
  throw new factory.errors.NotFound(factory.placeType.ScreeningRoomSection);
657
709
  }
710
+ return doc.toObject();
658
711
  });
659
712
  }
660
- // tslint:disable-next-line:max-func-body-length
713
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
661
714
  searchScreeningRooms(searchConditions) {
662
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
715
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
663
716
  return __awaiter(this, void 0, void 0, function* () {
664
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
717
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
665
718
  const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
666
719
  if (typeof projectIdEq === 'string') {
667
720
  matchStages.push({
@@ -673,7 +726,10 @@ class MongoRepository {
673
726
  if (typeof containedInPlaceIdEq === 'string') {
674
727
  matchStages.push({
675
728
  $match: {
676
- _id: { $eq: new mongoose_1.Types.ObjectId(containedInPlaceIdEq) }
729
+ 'containedInPlace.id': {
730
+ $exists: true,
731
+ $eq: containedInPlaceIdEq
732
+ }
677
733
  }
678
734
  });
679
735
  }
@@ -683,7 +739,7 @@ class MongoRepository {
683
739
  if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
684
740
  matchStages.push({
685
741
  $match: {
686
- branchCode: {
742
+ 'containedInPlace.branchCode': {
687
743
  $exists: true,
688
744
  $eq: searchConditions.containedInPlace.branchCode.$eq
689
745
  }
@@ -692,43 +748,45 @@ class MongoRepository {
692
748
  }
693
749
  }
694
750
  }
695
- // ルームコード
696
- if (searchConditions.branchCode !== undefined) {
697
- if (typeof searchConditions.branchCode.$eq === 'string') {
698
- matchStages.push({
699
- $match: {
700
- 'containsPlace.branchCode': {
701
- $exists: true,
702
- $eq: searchConditions.branchCode.$eq
703
- }
704
- }
705
- });
706
- }
751
+ const branchCodeEq = (_e = searchConditions.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
752
+ if (typeof branchCodeEq === 'string') {
753
+ matchStages.push({
754
+ $match: {
755
+ branchCode: { $eq: branchCodeEq }
756
+ }
757
+ });
758
+ }
759
+ const branchCodeIn = (_f = searchConditions.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
760
+ if (Array.isArray(branchCodeIn)) {
761
+ matchStages.push({
762
+ $match: {
763
+ branchCode: { $in: branchCodeIn }
764
+ }
765
+ });
707
766
  }
708
- const branchCodeRegex = (_e = searchConditions.branchCode) === null || _e === void 0 ? void 0 : _e.$regex;
767
+ const branchCodeRegex = (_g = searchConditions.branchCode) === null || _g === void 0 ? void 0 : _g.$regex;
709
768
  if (typeof branchCodeRegex === 'string') {
710
769
  matchStages.push({
711
770
  $match: {
712
- 'containsPlace.branchCode': {
713
- $exists: true,
771
+ branchCode: {
714
772
  $regex: new RegExp(branchCodeRegex)
715
773
  }
716
774
  }
717
775
  });
718
776
  }
719
- const nameCodeRegex = (_f = searchConditions.name) === null || _f === void 0 ? void 0 : _f.$regex;
777
+ const nameCodeRegex = (_h = searchConditions.name) === null || _h === void 0 ? void 0 : _h.$regex;
720
778
  if (typeof nameCodeRegex === 'string') {
721
779
  matchStages.push({
722
780
  $match: {
723
781
  $or: [
724
782
  {
725
- 'containsPlace.name.ja': {
783
+ 'name.ja': {
726
784
  $exists: true,
727
785
  $regex: new RegExp(nameCodeRegex)
728
786
  }
729
787
  },
730
788
  {
731
- 'containsPlace.name.en': {
789
+ 'name.en': {
732
790
  $exists: true,
733
791
  $regex: new RegExp(nameCodeRegex)
734
792
  }
@@ -741,18 +799,18 @@ class MongoRepository {
741
799
  if (typeof openSeatingAllowed === 'boolean') {
742
800
  matchStages.push({
743
801
  $match: {
744
- 'containsPlace.openSeatingAllowed': {
802
+ openSeatingAllowed: {
745
803
  $exists: true,
746
804
  $eq: openSeatingAllowed
747
805
  }
748
806
  }
749
807
  });
750
808
  }
751
- const additionalPropertyElemMatch = (_g = searchConditions.additionalProperty) === null || _g === void 0 ? void 0 : _g.$elemMatch;
809
+ const additionalPropertyElemMatch = (_j = searchConditions.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
752
810
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
753
811
  matchStages.push({
754
812
  $match: {
755
- 'containsPlace.additionalProperty': {
813
+ additionalProperty: {
756
814
  $exists: true,
757
815
  $elemMatch: additionalPropertyElemMatch
758
816
  }
@@ -760,30 +818,31 @@ class MongoRepository {
760
818
  });
761
819
  }
762
820
  const aggregate = this.placeModel.aggregate([
763
- { $unwind: '$containsPlace' },
821
+ { $sort: { branchCode: factory.sortType.Ascending } },
822
+ // { $unwind: '$containsPlace' },
764
823
  ...matchStages,
765
824
  {
766
- $project: Object.assign(Object.assign({ _id: 0, typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name', address: '$containsPlace.address', containedInPlace: {
767
- id: '$_id',
768
- typeOf: '$typeOf',
769
- branchCode: '$branchCode',
770
- name: '$name'
771
- }, openSeatingAllowed: '$containsPlace.openSeatingAllowed', additionalProperty: '$containsPlace.additionalProperty' }, (((_h = searchConditions.$projection) === null || _h === void 0 ? void 0 : _h.sectionCount) === 1)
825
+ $project: Object.assign(Object.assign({ _id: 0, typeOf: '$typeOf', branchCode: '$branchCode', name: '$name', address: '$address', containedInPlace: {
826
+ id: '$containedInPlace.id',
827
+ typeOf: '$containedInPlace.typeOf',
828
+ branchCode: '$containedInPlace.branchCode',
829
+ name: '$containedInPlace.name'
830
+ }, openSeatingAllowed: '$openSeatingAllowed', additionalProperty: '$additionalProperty', maximumAttendeeCapacity: '$maximumAttendeeCapacity' }, (((_k = searchConditions.$projection) === null || _k === void 0 ? void 0 : _k.sectionCount) === 1)
772
831
  ? {
773
832
  sectionCount: {
774
833
  $cond: {
775
- if: { $isArray: '$containsPlace.containsPlace' },
776
- then: { $size: '$containsPlace.containsPlace' },
834
+ if: { $isArray: '$containsPlace' },
835
+ then: { $size: '$containsPlace' },
777
836
  else: 0
778
837
  }
779
838
  }
780
839
  }
781
- : undefined), (((_j = searchConditions.$projection) === null || _j === void 0 ? void 0 : _j.seatCount) === 1)
840
+ : undefined), (((_l = searchConditions.$projection) === null || _l === void 0 ? void 0 : _l.seatCount) === 1)
782
841
  ? {
783
842
  seatCount: {
784
843
  $sum: {
785
844
  $map: {
786
- input: '$containsPlace.containsPlace',
845
+ input: '$containsPlace',
787
846
  in: {
788
847
  $cond: {
789
848
  if: { $isArray: '$$this.containsPlace' },
@@ -811,33 +870,38 @@ class MongoRepository {
811
870
  findScreeningRoomsByBranchCode(params) {
812
871
  return __awaiter(this, void 0, void 0, function* () {
813
872
  const matchStages = [
814
- { $match: { typeOf: { $eq: factory.placeType.MovieTheater } } },
873
+ { $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } },
815
874
  {
816
- $match: { _id: { $eq: new mongoose_1.Types.ObjectId(params.containedInPlace.id.$eq) } }
875
+ $match: { 'containedInPlace.id': { $exists: true, $eq: params.containedInPlace.id.$eq } }
817
876
  },
818
877
  {
819
- $match: { 'containsPlace.branchCode': { $exists: true, $eq: params.branchCode.$eq } }
878
+ $match: { branchCode: { $eq: params.branchCode.$eq } }
820
879
  }
821
880
  ];
822
881
  const aggregate = this.placeModel.aggregate([
823
- { $unwind: '$containsPlace' },
882
+ // { $unwind: '$containsPlace' },
824
883
  ...matchStages,
825
884
  {
826
885
  $project: {
827
886
  _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'
887
+ typeOf: '$typeOf',
888
+ branchCode: '$branchCode',
889
+ name: '$name',
890
+ containsPlace: '$containsPlace',
891
+ seatCount: {
892
+ $sum: {
893
+ $map: {
894
+ input: '$containsPlace',
895
+ in: {
896
+ $cond: {
897
+ if: { $isArray: '$$this.containsPlace' },
898
+ then: { $size: '$$this.containsPlace' },
899
+ else: 0
900
+ }
901
+ }
902
+ }
903
+ }
904
+ }
841
905
  }
842
906
  }
843
907
  ]);
@@ -849,6 +913,7 @@ class MongoRepository {
849
913
  return docs[0];
850
914
  });
851
915
  }
916
+ // tslint:disable-next-line:max-func-body-length
852
917
  createSeat(seat) {
853
918
  var _a, _b;
854
919
  return __awaiter(this, void 0, void 0, function* () {
@@ -866,48 +931,43 @@ class MongoRepository {
866
931
  }
867
932
  // 施設存在確認
868
933
  let doc = yield this.placeModel.findOne({
934
+ typeOf: { $eq: factory.placeType.MovieTheater },
869
935
  '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
- })
936
+ branchCode: { $eq: movieTheater.branchCode }
937
+ }, { _id: 1 })
876
938
  .exec();
877
939
  if (doc === null) {
878
940
  throw new factory.errors.NotFound(factory.placeType.MovieTheater);
879
941
  }
880
942
  doc = yield this.placeModel.findOneAndUpdate({
943
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
881
944
  'project.id': { $eq: seat.project.id },
882
- branchCode: movieTheater.branchCode,
883
- 'containsPlace.branchCode': screeningRoom.branchCode,
884
- 'containsPlace.containsPlace.branchCode': screeningRoomSection.branchCode
945
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
946
+ branchCode: { $eq: screeningRoom.branchCode },
947
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode }
885
948
  }, {
886
949
  $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)
950
+ '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
951
  }
889
952
  }, {
890
953
  new: true,
891
954
  arrayFilters: [
892
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
893
955
  {
894
- 'screeningRoomSection.branchCode': screeningRoomSection.branchCode,
956
+ 'screeningRoomSection.branchCode': { $eq: screeningRoomSection.branchCode },
895
957
  'screeningRoomSection.containsPlace.branchCode': { $ne: seat.branchCode }
896
958
  }
897
959
  ],
898
- projection: {
899
- _id: 1,
900
- 'project.id': 1,
901
- branchCode: 1
902
- }
960
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
903
961
  })
904
962
  .exec();
905
963
  // 存在しなければコード重複
906
964
  if (doc === null) {
907
965
  throw new factory.errors.AlreadyInUse(factory.placeType.Seat, ['branchCode']);
908
966
  }
967
+ return doc.toObject();
909
968
  });
910
969
  }
970
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
911
971
  updateSeat(seat, $unset) {
912
972
  var _a, _b;
913
973
  return __awaiter(this, void 0, void 0, function* () {
@@ -924,47 +984,56 @@ class MongoRepository {
924
984
  throw new factory.errors.ArgumentNull('containedInPlace.containedInPlace.containedInPlace.branchCode');
925
985
  }
926
986
  const doc = yield this.placeModel.findOneAndUpdate({
987
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
927
988
  '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')
989
+ 'containedInPlace.branchCode': { $exists: true, $eq: movieTheater.branchCode },
990
+ branchCode: { $eq: screeningRoom.branchCode },
991
+ 'containsPlace.branchCode': { $eq: screeningRoomSection.branchCode },
992
+ 'containsPlace.containsPlace.branchCode': { $eq: seat.branchCode }
993
+ }, 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')
933
994
  ? {
934
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': seat.name
995
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': seat.name
935
996
  }
936
997
  : undefined), (Array.isArray(seat.seatingType))
937
998
  ? {
938
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': seat.seatingType
999
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': seat.seatingType
939
1000
  }
940
1001
  : undefined), (Array.isArray(seat.additionalProperty))
941
1002
  ? {
942
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': seat.additionalProperty
1003
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].additionalProperty': seat.additionalProperty
943
1004
  }
944
- : undefined), ($unset !== undefined && $unset !== null) ? { $unset } : undefined), {
1005
+ : undefined), { $unset: Object.assign(Object.assign({ noExistingAttributeName: 1 }, (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].name'])
1006
+ === 1
1007
+ || ($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoomSection].containsPlace.$[seat].name']) === 1)
1008
+ ? {
1009
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].name': 1
1010
+ }
1011
+ : undefined), (($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType'])
1012
+ === 1
1013
+ || ($unset === null || $unset === void 0 ? void 0 : $unset['containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType']) === 1)
1014
+ ? {
1015
+ 'containsPlace.$[screeningRoomSection].containsPlace.$[seat].seatingType': 1
1016
+ }
1017
+ : undefined) }), {
945
1018
  new: true,
946
1019
  arrayFilters: [
947
- { 'screeningRoom.branchCode': screeningRoom.branchCode },
948
- { 'screeningRoomSection.branchCode': screeningRoomSection.branchCode },
949
- { 'seat.branchCode': seat.branchCode }
1020
+ { 'screeningRoomSection.branchCode': { $eq: screeningRoomSection.branchCode } },
1021
+ { 'seat.branchCode': { $eq: seat.branchCode } }
950
1022
  ],
951
- projection: {
952
- _id: 1,
953
- 'project.id': 1,
954
- branchCode: 1
955
- }
1023
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
956
1024
  })
957
1025
  .exec();
958
1026
  if (doc === null) {
959
1027
  throw new factory.errors.NotFound(factory.placeType.Seat);
960
1028
  }
1029
+ return doc.toObject();
961
1030
  });
962
1031
  }
963
1032
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
964
1033
  searchSeats(params) {
965
1034
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
966
1035
  return __awaiter(this, void 0, void 0, function* () {
967
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
1036
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
968
1037
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
969
1038
  if (typeof projectIdEq === 'string') {
970
1039
  matchStages.push({
@@ -975,7 +1044,7 @@ class MongoRepository {
975
1044
  if (typeof containedInPlaceBranchCodeEq === 'string') {
976
1045
  matchStages.push({
977
1046
  $match: {
978
- 'containsPlace.containsPlace.branchCode': {
1047
+ 'containsPlace.branchCode': {
979
1048
  $exists: true,
980
1049
  $eq: containedInPlaceBranchCodeEq
981
1050
  }
@@ -986,7 +1055,7 @@ class MongoRepository {
986
1055
  if (Array.isArray(containedInPlaceBranchCodeIn)) {
987
1056
  matchStages.push({
988
1057
  $match: {
989
- 'containsPlace.containsPlace.branchCode': {
1058
+ 'containsPlace.branchCode': {
990
1059
  $exists: true,
991
1060
  $in: containedInPlaceBranchCodeIn
992
1061
  }
@@ -999,8 +1068,7 @@ class MongoRepository {
999
1068
  if (typeof params.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1000
1069
  matchStages.push({
1001
1070
  $match: {
1002
- 'containsPlace.branchCode': {
1003
- $exists: true,
1071
+ branchCode: {
1004
1072
  $eq: params.containedInPlace.containedInPlace.branchCode.$eq
1005
1073
  }
1006
1074
  }
@@ -1012,7 +1080,7 @@ class MongoRepository {
1012
1080
  if (typeof params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq === 'string') {
1013
1081
  matchStages.push({
1014
1082
  $match: {
1015
- branchCode: {
1083
+ 'containedInPlace.branchCode': {
1016
1084
  $exists: true,
1017
1085
  $eq: params.containedInPlace.containedInPlace.containedInPlace.branchCode.$eq
1018
1086
  }
@@ -1028,7 +1096,7 @@ class MongoRepository {
1028
1096
  if (typeof params.branchCode.$eq === 'string') {
1029
1097
  matchStages.push({
1030
1098
  $match: {
1031
- 'containsPlace.containsPlace.containsPlace.branchCode': {
1099
+ 'containsPlace.containsPlace.branchCode': {
1032
1100
  $exists: true,
1033
1101
  $eq: params.branchCode.$eq
1034
1102
  }
@@ -1040,7 +1108,7 @@ class MongoRepository {
1040
1108
  if (Array.isArray(branchCodeIn)) {
1041
1109
  matchStages.push({
1042
1110
  $match: {
1043
- 'containsPlace.containsPlace.containsPlace.branchCode': {
1111
+ 'containsPlace.containsPlace.branchCode': {
1044
1112
  $exists: true,
1045
1113
  $in: branchCodeIn
1046
1114
  }
@@ -1051,7 +1119,7 @@ class MongoRepository {
1051
1119
  if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
1052
1120
  matchStages.push({
1053
1121
  $match: {
1054
- 'containsPlace.containsPlace.containsPlace.branchCode': {
1122
+ 'containsPlace.containsPlace.branchCode': {
1055
1123
  $exists: true,
1056
1124
  $regex: new RegExp(branchCodeRegex)
1057
1125
  }
@@ -1064,13 +1132,13 @@ class MongoRepository {
1064
1132
  $match: {
1065
1133
  $or: [
1066
1134
  {
1067
- 'containsPlace.containsPlace.containsPlace.name.ja': {
1135
+ 'containsPlace.containsPlace.name.ja': {
1068
1136
  $exists: true,
1069
1137
  $regex: new RegExp(nameRegex)
1070
1138
  }
1071
1139
  },
1072
1140
  {
1073
- 'containsPlace.containsPlace.containsPlace.name.en': {
1141
+ 'containsPlace.containsPlace.name.en': {
1074
1142
  $exists: true,
1075
1143
  $regex: new RegExp(nameRegex)
1076
1144
  }
@@ -1083,7 +1151,7 @@ class MongoRepository {
1083
1151
  if (typeof seatingTypeEq === 'string') {
1084
1152
  matchStages.push({
1085
1153
  $match: {
1086
- 'containsPlace.containsPlace.containsPlace.seatingType': {
1154
+ 'containsPlace.containsPlace.seatingType': {
1087
1155
  $exists: true,
1088
1156
  $eq: seatingTypeEq
1089
1157
  }
@@ -1099,7 +1167,7 @@ class MongoRepository {
1099
1167
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
1100
1168
  matchStages.push({
1101
1169
  $match: {
1102
- 'containsPlace.containsPlace.containsPlace.additionalProperty': {
1170
+ 'containsPlace.containsPlace.additionalProperty': {
1103
1171
  $exists: true,
1104
1172
  $elemMatch: additionalPropertyElemMatch
1105
1173
  }
@@ -1109,31 +1177,31 @@ class MongoRepository {
1109
1177
  const aggregate = this.placeModel.aggregate([
1110
1178
  { $unwind: '$containsPlace' },
1111
1179
  { $unwind: '$containsPlace.containsPlace' },
1112
- { $unwind: '$containsPlace.containsPlace.containsPlace' },
1180
+ // { $unwind: '$containsPlace.containsPlace.containsPlace' },
1113
1181
  ...matchStages,
1114
1182
  {
1115
1183
  $project: {
1116
1184
  _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)
1185
+ typeOf: '$containsPlace.containsPlace.typeOf',
1186
+ branchCode: '$containsPlace.containsPlace.branchCode',
1187
+ name: '$containsPlace.containsPlace.name',
1188
+ seatingType: '$containsPlace.containsPlace.seatingType',
1189
+ containedInPlace: Object.assign({ typeOf: '$containsPlace.typeOf', branchCode: '$containsPlace.branchCode', name: '$containsPlace.name' }, (includeScreeningRooms)
1122
1190
  ? {
1123
1191
  containedInPlace: {
1124
- typeOf: '$containsPlace.typeOf',
1125
- branchCode: '$containsPlace.branchCode',
1126
- name: '$containsPlace.name',
1192
+ typeOf: '$typeOf',
1193
+ branchCode: '$branchCode',
1194
+ name: '$name',
1127
1195
  containedInPlace: {
1128
- id: '$_id',
1129
- typeOf: '$typeOf',
1130
- branchCode: '$branchCode',
1131
- name: '$name'
1196
+ id: '$containedInPlace.id',
1197
+ typeOf: '$containedInPlace.typeOf',
1198
+ branchCode: '$containedInPlace.branchCode',
1199
+ name: '$containedInPlace.name'
1132
1200
  }
1133
1201
  }
1134
1202
  }
1135
1203
  : undefined),
1136
- additionalProperty: '$containsPlace.containsPlace.containsPlace.additionalProperty'
1204
+ additionalProperty: '$containsPlace.containsPlace.additionalProperty'
1137
1205
  }
1138
1206
  }
1139
1207
  ]);
@@ -1148,28 +1216,123 @@ class MongoRepository {
1148
1216
  deleteSeat(seat) {
1149
1217
  return __awaiter(this, void 0, void 0, function* () {
1150
1218
  const doc = yield this.placeModel.findOneAndUpdate({
1219
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
1151
1220
  '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
1221
+ 'containedInPlace.branchCode': {
1222
+ $exists: true,
1223
+ $eq: seat.containedInPlace.containedInPlace.containedInPlace.branchCode
1224
+ },
1225
+ branchCode: { $eq: seat.containedInPlace.containedInPlace.branchCode },
1226
+ 'containsPlace.branchCode': { $eq: seat.containedInPlace.branchCode },
1227
+ 'containsPlace.containsPlace.branchCode': { $eq: seat.branchCode }
1156
1228
  }, {
1157
1229
  $pull: {
1158
- 'containsPlace.$[screeningRoom].containsPlace.$[screeningRoomSection].containsPlace': {
1230
+ 'containsPlace.$[screeningRoomSection].containsPlace': {
1159
1231
  branchCode: seat.branchCode
1160
1232
  }
1161
1233
  }
1162
1234
  }, {
1163
1235
  new: true,
1164
1236
  arrayFilters: [
1165
- { 'screeningRoom.branchCode': seat.containedInPlace.containedInPlace.branchCode },
1166
- { 'screeningRoomSection.branchCode': seat.containedInPlace.branchCode }
1167
- ]
1237
+ { 'screeningRoomSection.branchCode': { $eq: seat.containedInPlace.branchCode } }
1238
+ ],
1239
+ projection: { 'containedInPlace.id': 1, typeOf: 1 }
1168
1240
  })
1169
1241
  .exec();
1170
1242
  if (doc === null) {
1171
1243
  throw new factory.errors.NotFound(factory.placeType.Seat);
1172
1244
  }
1245
+ return doc.toObject();
1246
+ });
1247
+ }
1248
+ // tslint:disable-next-line:prefer-function-over-method
1249
+ syncScreeningRooms(__) {
1250
+ return __awaiter(this, void 0, void 0, function* () {
1251
+ return;
1252
+ // const movieTheater = <Pick<
1253
+ // factory.place.movieTheater.IPlace,
1254
+ // 'id' | 'branchCode' | 'name' | 'project' | 'typeOf' | 'containsPlace'
1255
+ // >>await this.placeModel.findOne({
1256
+ // _id: { $eq: params.id },
1257
+ // typeOf: { $eq: factory.placeType.MovieTheater }
1258
+ // })
1259
+ // .select({
1260
+ // _id: 1, branchCode: 1, name: 1, project: 1, typeOf: 1, containsPlace: 1
1261
+ // })
1262
+ // .exec()
1263
+ // .then((doc) => {
1264
+ // if (doc === null) {
1265
+ // throw new factory.errors.NotFound(factory.placeType.MovieTheater);
1266
+ // }
1267
+ // return doc.toObject();
1268
+ // });
1269
+ // let screeningRoomsFromMovieTheater = movieTheater.containsPlace;
1270
+ // if (typeof params.screeningRoomBranchCode === 'string' && params.screeningRoomBranchCode.length > 0) {
1271
+ // screeningRoomsFromMovieTheater = screeningRoomsFromMovieTheater.filter(
1272
+ // (place) => place.branchCode === params.screeningRoomBranchCode
1273
+ // );
1274
+ // }
1275
+ // const creatingScreeningRooms: ICreatingScreeningRoom[] = screeningRoomsFromMovieTheater.map((place) => {
1276
+ // return {
1277
+ // ...place,
1278
+ // containedInPlace: {
1279
+ // id: movieTheater.id,
1280
+ // typeOf: movieTheater.typeOf,
1281
+ // branchCode: movieTheater.branchCode,
1282
+ // name: movieTheater.name
1283
+ // },
1284
+ // containsPlace: (Array.isArray(place.containsPlace)) ? place.containsPlace : [],
1285
+ // project: movieTheater.project
1286
+ // };
1287
+ // });
1288
+ // debug('sync processing', creatingScreeningRooms.length, 'screeningRooms...', creatingScreeningRooms);
1289
+ // await Promise.all(creatingScreeningRooms.map(async (createScreeningRoom) => {
1290
+ // const { typeOf, project, branchCode, ...setFields } = createScreeningRoom;
1291
+ // if (typeof branchCode === 'string' && branchCode.length > 0) {
1292
+ // const upsertScreeningRoomResult = await this.placeModel.findOneAndUpdate(
1293
+ // {
1294
+ // typeOf: { $eq: factory.placeType.ScreeningRoom },
1295
+ // 'project.id': { $eq: createScreeningRoom.project.id },
1296
+ // 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
1297
+ // branchCode: { $eq: createScreeningRoom.branchCode }
1298
+ // },
1299
+ // {
1300
+ // $setOnInsert: {
1301
+ // typeOf: createScreeningRoom.typeOf,
1302
+ // project: createScreeningRoom.project,
1303
+ // branchCode: createScreeningRoom.branchCode
1304
+ // },
1305
+ // $set: setFields
1306
+ // },
1307
+ // {
1308
+ // upsert: true,
1309
+ // new: true,
1310
+ // projection: { _id: 1 }
1311
+ // }
1312
+ // )
1313
+ // .exec();
1314
+ // debug('screeningRoom upserted. upsertScreeningRoomResult:', upsertScreeningRoomResult);
1315
+ // }
1316
+ // }));
1317
+ });
1318
+ }
1319
+ unsetContainsPlaceFromMovieTheater(params) {
1320
+ return __awaiter(this, void 0, void 0, function* () {
1321
+ return this.placeModel.findOneAndUpdate({
1322
+ _id: { $eq: params.id },
1323
+ typeOf: { $eq: factory.placeType.MovieTheater },
1324
+ 'containsPlace.branchCode': { $exists: true }
1325
+ }, {
1326
+ $unset: { containsPlace: 1 }
1327
+ })
1328
+ .select({ _id: 1 })
1329
+ .exec()
1330
+ .then((doc) => {
1331
+ if (doc === null) {
1332
+ return;
1333
+ }
1334
+ return doc.toObject();
1335
+ });
1173
1336
  });
1174
1337
  }
1175
1338
  deleteByProject(params) {
@@ -1235,7 +1398,7 @@ class MongoRepository {
1235
1398
  if (((_a = params.sort) === null || _a === void 0 ? void 0 : _a.branchCode) !== undefined) {
1236
1399
  query.sort({ branchCode: params.sort.branchCode });
1237
1400
  }
1238
- return query.setOptions({ maxTimeMS: 10000 })
1401
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
1239
1402
  .exec()
1240
1403
  .then((docs) => docs.map((doc) => doc.toObject()));
1241
1404
  });