@chevre/domain 23.2.0-alpha.3 → 23.2.0-alpha.31

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 (80) hide show
  1. package/example/src/chevre/event/importEventsFromCOAByTitle.ts +1 -1
  2. package/example/src/chevre/eventSeries/migrateEventSeriesOffers.ts +75 -0
  3. package/example/src/chevre/eventSeries/migrateEventSeriesVideoFormat.ts +80 -0
  4. package/example/src/chevre/place/adminEntranceGates.ts +69 -0
  5. package/example/src/chevre/place/checkEntranceGatesCount.ts +82 -0
  6. package/example/src/chevre/place/findRooms.ts +24 -0
  7. package/example/src/chevre/place/findSections.ts +28 -0
  8. package/example/src/chevre/place/migrateSectionIdentifier.ts +92 -0
  9. package/example/src/chevre/place/seatsJson2csv.ts +63 -0
  10. package/example/src/chevre/place/upsertMovieTheatersByBranchCode.ts +41 -0
  11. package/example/src/chevre/place/upsertRoomsByBranchCode.ts +40 -0
  12. package/example/src/chevre/place/upsertSeatSectionsByBranchCode.ts +56 -0
  13. package/example/src/chevre/reIndex.ts +1 -1
  14. package/example/src/chevre/roles/addAdminEventSeriesReadPermissionIfNotExists.ts +49 -0
  15. package/example/src/chevre/roles/addAdminMovieReadPermissionIfNotExists.ts +49 -0
  16. package/example/src/chevre/roles/addAdminMovieTheaterReadPermissionIfNotExists.ts +34 -0
  17. package/example/src/chevre/roles/addAdminMovieTheaterWritePermissionIfNotExists.ts +34 -0
  18. package/example/src/chevre/roles/addAdminRoomReadPermissionIfNotExists.ts +34 -0
  19. package/example/src/chevre/roles/addAdminRoomWritePermissionIfNotExists.ts +34 -0
  20. package/example/src/chevre/unsetUnnecessaryFields.ts +8 -4
  21. package/lib/chevre/factory/event.js +5 -5
  22. package/lib/chevre/repo/aggregateOrder.js +0 -93
  23. package/lib/chevre/repo/aggregateReservation.d.ts +0 -1
  24. package/lib/chevre/repo/aggregateReservation.js +0 -2
  25. package/lib/chevre/repo/creativeWork.js +9 -5
  26. package/lib/chevre/repo/eventOffer.d.ts +8 -0
  27. package/lib/chevre/repo/eventOffer.js +11 -0
  28. package/lib/chevre/repo/eventSeries.js +16 -12
  29. package/lib/chevre/repo/mongoose/schemas/aggregateReservation.js +0 -1
  30. package/lib/chevre/repo/mongoose/schemas/creativeWork.js +10 -9
  31. package/lib/chevre/repo/mongoose/schemas/eventSeries.js +10 -0
  32. package/lib/chevre/repo/mongoose/schemas/place.d.ts +6 -2
  33. package/lib/chevre/repo/place/entranceGate.d.ts +48 -0
  34. package/lib/chevre/repo/place/entranceGate.js +166 -0
  35. package/lib/chevre/repo/place/movieTheater.d.ts +40 -3
  36. package/lib/chevre/repo/place/movieTheater.js +77 -6
  37. package/lib/chevre/repo/place/screeningRoom.d.ts +60 -31
  38. package/lib/chevre/repo/place/screeningRoom.js +227 -135
  39. package/lib/chevre/repo/place/seat.d.ts +47 -45
  40. package/lib/chevre/repo/place/seat.js +175 -45
  41. package/lib/chevre/repo/place/section.d.ts +60 -30
  42. package/lib/chevre/repo/place/section.js +337 -127
  43. package/lib/chevre/repo/task.d.ts +1 -1
  44. package/lib/chevre/repository.d.ts +8 -0
  45. package/lib/chevre/repository.js +16 -0
  46. package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +6 -3
  47. package/lib/chevre/service/event/processUpdateMovieTheater.d.ts +1 -1
  48. package/lib/chevre/service/event/processUpdateMovieTheater.js +13 -11
  49. package/lib/chevre/service/event/saveScreeningEvents.d.ts +1 -1
  50. package/lib/chevre/service/event/saveScreeningEvents.js +6 -5
  51. package/lib/chevre/service/offer/event/authorize/factory.js +4 -1
  52. package/lib/chevre/service/offer/event/searchEventTicketOffers.js +7 -4
  53. package/lib/chevre/service/offer/event/searchOfferAppliesToMovieTicket.js +9 -6
  54. package/lib/chevre/service/offer/event/searchOffersByIds.js +7 -4
  55. package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.js +4 -13
  56. package/lib/chevre/service/offer/onEventChanged.js +7 -5
  57. package/lib/chevre/service/offer.d.ts +5 -0
  58. package/lib/chevre/service/offer.js +34 -9
  59. package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +1 -1
  60. package/lib/chevre/service/order/onOrderStatusChanged/onOrderDeliveredPartially/factory.d.ts +1 -1
  61. package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +1 -1
  62. package/lib/chevre/service/payment/any/factory.d.ts +4 -0
  63. package/lib/chevre/service/payment/any/factory.js +2 -1
  64. package/lib/chevre/service/payment/any.d.ts +4 -0
  65. package/lib/chevre/service/payment/any.js +2 -1
  66. package/lib/chevre/service/task/authorizePayment.js +1 -1
  67. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.d.ts +1 -1
  68. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +5 -3
  69. package/lib/chevre/service/task/createEvent/createEventBySchedule/schedule2events.js +1 -1
  70. package/lib/chevre/service/task/onResourceDeleted.d.ts +6 -0
  71. package/lib/chevre/service/task/onResourceDeleted.js +60 -0
  72. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +3 -7
  73. package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +19 -7
  74. package/lib/chevre/service/task/onResourceUpdated.js +93 -15
  75. package/lib/chevre/service/task/syncResourcesFromCOA.js +1 -1
  76. package/lib/chevre/service/taskHandler.js +1 -0
  77. package/package.json +4 -3
  78. package/example/src/chevre/event/upsertManyScreeningEventByIdentifier.ts +0 -191
  79. package/lib/chevre/service/eventOld.d.ts +0 -60
  80. package/lib/chevre/service/eventOld.js +0 -864
@@ -33,6 +33,120 @@ class ScreeningRoomRepo {
33
33
  this.civicStructureModel = connection.model(civicStructure_1.modelName, (0, civicStructure_1.createSchema)());
34
34
  this.placeModel = connection.model(place_1.modelName, (0, place_1.createSchema)());
35
35
  }
36
+ // tslint:disable-next-line:max-func-body-length
37
+ static CREATE_ROOM_MONGO_CONDITIONS(searchConditions) {
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
39
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
40
+ const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
41
+ if (typeof projectIdEq === 'string') {
42
+ matchStages.push({
43
+ $match: { 'project.id': { $eq: projectIdEq } }
44
+ });
45
+ }
46
+ const parentOrganizationIdEq = (_d = (_c = searchConditions.parentOrganization) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
47
+ if (typeof parentOrganizationIdEq === 'string') {
48
+ matchStages.push({
49
+ $match: { 'parentOrganization.id': { $exists: true, $eq: parentOrganizationIdEq } }
50
+ });
51
+ }
52
+ // 施設ID
53
+ const containedInPlaceIdEq = (_f = (_e = searchConditions.containedInPlace) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
54
+ if (typeof containedInPlaceIdEq === 'string') {
55
+ matchStages.push({
56
+ $match: {
57
+ 'containedInPlace.id': {
58
+ $exists: true,
59
+ $eq: containedInPlaceIdEq
60
+ }
61
+ }
62
+ });
63
+ }
64
+ if (searchConditions.containedInPlace !== undefined) {
65
+ // 施設コード
66
+ if (searchConditions.containedInPlace.branchCode !== undefined) {
67
+ if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
68
+ matchStages.push({
69
+ $match: {
70
+ 'containedInPlace.branchCode': {
71
+ $exists: true,
72
+ $eq: searchConditions.containedInPlace.branchCode.$eq
73
+ }
74
+ }
75
+ });
76
+ }
77
+ }
78
+ }
79
+ const branchCodeEq = (_g = searchConditions.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
80
+ if (typeof branchCodeEq === 'string') {
81
+ matchStages.push({
82
+ $match: {
83
+ branchCode: { $eq: branchCodeEq }
84
+ }
85
+ });
86
+ }
87
+ const branchCodeIn = (_h = searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$in;
88
+ if (Array.isArray(branchCodeIn)) {
89
+ matchStages.push({
90
+ $match: {
91
+ branchCode: { $in: branchCodeIn }
92
+ }
93
+ });
94
+ }
95
+ const branchCodeRegex = (_j = searchConditions.branchCode) === null || _j === void 0 ? void 0 : _j.$regex;
96
+ if (typeof branchCodeRegex === 'string') {
97
+ matchStages.push({
98
+ $match: {
99
+ branchCode: {
100
+ $regex: new RegExp(branchCodeRegex)
101
+ }
102
+ }
103
+ });
104
+ }
105
+ const nameCodeRegex = (_k = searchConditions.name) === null || _k === void 0 ? void 0 : _k.$regex;
106
+ if (typeof nameCodeRegex === 'string') {
107
+ matchStages.push({
108
+ $match: {
109
+ $or: [
110
+ {
111
+ 'name.ja': {
112
+ $exists: true,
113
+ $regex: new RegExp(nameCodeRegex)
114
+ }
115
+ },
116
+ {
117
+ 'name.en': {
118
+ $exists: true,
119
+ $regex: new RegExp(nameCodeRegex)
120
+ }
121
+ }
122
+ ]
123
+ }
124
+ });
125
+ }
126
+ const openSeatingAllowed = searchConditions.openSeatingAllowed;
127
+ if (typeof openSeatingAllowed === 'boolean') {
128
+ matchStages.push({
129
+ $match: {
130
+ openSeatingAllowed: {
131
+ $exists: true,
132
+ $eq: openSeatingAllowed
133
+ }
134
+ }
135
+ });
136
+ }
137
+ const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
138
+ if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
139
+ matchStages.push({
140
+ $match: {
141
+ additionalProperty: {
142
+ $exists: true,
143
+ $elemMatch: additionalPropertyElemMatch
144
+ }
145
+ }
146
+ });
147
+ }
148
+ return matchStages;
149
+ }
36
150
  saveScreeningRooms4coa(params) {
37
151
  return __awaiter(this, void 0, void 0, function* () {
38
152
  const { containsPlace } = params, movieTheater4update = __rest(params, ["containsPlace"]);
@@ -79,29 +193,24 @@ class ScreeningRoomRepo {
79
193
  })));
80
194
  });
81
195
  }
82
- createScreeningRoom(screeningRoom) {
196
+ createRoom(screeningRoom, options) {
83
197
  return __awaiter(this, void 0, void 0, function* () {
84
- var _a;
198
+ const { project, parentOrganization, movieTheaterCode } = options;
85
199
  // 施設存在確認
86
- const movieTheaterDoc = yield this.civicStructureModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.MovieTheater }, 'project.id': { $eq: screeningRoom.project.id }, branchCode: { $eq: screeningRoom.containedInPlace.branchCode } }, (typeof ((_a = screeningRoom.parentOrganization) === null || _a === void 0 ? void 0 : _a.id) === 'string')
87
- ? { 'parentOrganization.id': { $exists: true, $eq: screeningRoom.parentOrganization.id } }
200
+ const movieTheater = yield this.civicStructureModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.MovieTheater }, 'project.id': { $eq: project.id }, branchCode: { $eq: movieTheaterCode } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
201
+ ? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
88
202
  : undefined), { _id: 0, id: { $toString: '$_id' }, typeOf: 1, branchCode: 1, name: 1, parentOrganization: 1 })
89
203
  .lean()
90
204
  .exec();
91
- if (movieTheaterDoc === null) {
205
+ if (movieTheater === null) {
92
206
  throw new factory.errors.NotFound(factory.placeType.MovieTheater);
93
207
  }
94
- // const movieTheater = <Pick<
95
- // factory.place.movieTheater.IPlace,
96
- // 'id' | 'typeOf' | 'branchCode' | 'name' | 'parentOrganization'
97
- // >>movieTheaterDoc.toObject();
98
- const movieTheater = movieTheaterDoc;
99
- const creatingScreeningRoom = Object.assign({ typeOf: screeningRoom.typeOf, branchCode: screeningRoom.branchCode, name: screeningRoom.name, address: screeningRoom.address, additionalProperty: (Array.isArray(screeningRoom.additionalProperty)) ? screeningRoom.additionalProperty : [], containedInPlace: {
208
+ const creatingScreeningRoom = Object.assign({ typeOf: factory.placeType.ScreeningRoom, branchCode: screeningRoom.branchCode, name: screeningRoom.name, address: screeningRoom.address, additionalProperty: (Array.isArray(screeningRoom.additionalProperty)) ? screeningRoom.additionalProperty : [], containedInPlace: {
100
209
  id: movieTheater.id,
101
210
  typeOf: movieTheater.typeOf,
102
211
  branchCode: movieTheater.branchCode,
103
212
  name: movieTheater.name
104
- }, containsPlace: [], project: screeningRoom.project,
213
+ }, containsPlace: [], project: { id: project.id, typeOf: factory.organizationType.Project },
105
214
  // 必須化(2023-07-14~)
106
215
  parentOrganization: movieTheater.parentOrganization }, (typeof screeningRoom.openSeatingAllowed === 'boolean')
107
216
  ? { openSeatingAllowed: screeningRoom.openSeatingAllowed }
@@ -125,11 +234,11 @@ class ScreeningRoomRepo {
125
234
  };
126
235
  });
127
236
  }
128
- updateScreeningRoom(screeningRoom, $unset) {
237
+ updateRoomByBranchCode(screeningRoom, $unset, options) {
129
238
  return __awaiter(this, void 0, void 0, function* () {
130
- var _a;
131
- const doc = yield this.placeModel.findOneAndUpdate(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: screeningRoom.project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode }, branchCode: screeningRoom.branchCode }, (typeof ((_a = screeningRoom.parentOrganization) === null || _a === void 0 ? void 0 : _a.id) === 'string')
132
- ? { 'parentOrganization.id': { $exists: true, $eq: screeningRoom.parentOrganization.id } }
239
+ const { project, parentOrganization, movieTheaterCode } = options;
240
+ const doc = yield this.placeModel.findOneAndUpdate(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode }, branchCode: screeningRoom.branchCode }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
241
+ ? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
133
242
  : undefined), Object.assign(Object.assign(Object.assign(Object.assign({ name: screeningRoom.name }, (screeningRoom.address !== undefined && screeningRoom.address !== null)
134
243
  ? { address: screeningRoom.address }
135
244
  : undefined), (typeof screeningRoom.openSeatingAllowed === 'boolean')
@@ -169,11 +278,72 @@ class ScreeningRoomRepo {
169
278
  }
170
279
  });
171
280
  }
172
- deleteScreeningRoom(screeningRoom) {
281
+ /**
282
+ * コードをキーにして冪等作成
283
+ * 2026-01-12~
284
+ */
285
+ upsertRoomsByBranchCode(params, options) {
173
286
  return __awaiter(this, void 0, void 0, function* () {
174
- var _a;
175
- const doc = yield this.placeModel.findOneAndDelete(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: screeningRoom.project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode }, branchCode: screeningRoom.branchCode }, (typeof ((_a = screeningRoom.parentOrganization) === null || _a === void 0 ? void 0 : _a.id) === 'string')
176
- ? { 'parentOrganization.id': { $exists: true, $eq: screeningRoom.parentOrganization.id } }
287
+ const { project, parentOrganization, movieTheaterId } = options;
288
+ // 施設存在確認
289
+ const movieTheater = yield this.civicStructureModel.findOne(Object.assign({ typeOf: { $eq: factory.placeType.MovieTheater }, 'project.id': { $eq: project.id }, _id: { $eq: movieTheaterId } }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
290
+ ? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
291
+ : undefined), { _id: 0, id: { $toString: '$_id' }, typeOf: 1, branchCode: 1, name: 1, parentOrganization: 1 })
292
+ .lean()
293
+ .exec();
294
+ if (movieTheater === null) {
295
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
296
+ }
297
+ const containedInPlace = {
298
+ id: movieTheater.id,
299
+ typeOf: movieTheater.typeOf,
300
+ branchCode: movieTheater.branchCode,
301
+ name: movieTheater.name
302
+ };
303
+ const bulkWriteOps = [];
304
+ if (Array.isArray(params)) {
305
+ params.forEach(({ $set, $unset }) => {
306
+ const { branchCode } = $set, setFields = __rest($set, ["branchCode"]);
307
+ if (typeof branchCode !== 'string' || branchCode === '') {
308
+ throw new factory.errors.ArgumentNull('branchCode');
309
+ }
310
+ // リソースのユニークネスを保証するfilter
311
+ const filter = {
312
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
313
+ 'project.id': { $eq: project.id },
314
+ 'containedInPlace.id': { $eq: movieTheaterId },
315
+ branchCode: { $eq: branchCode }
316
+ };
317
+ const initialRoom = {
318
+ typeOf: factory.placeType.ScreeningRoom,
319
+ project: { id: project.id, typeOf: factory.organizationType.Project },
320
+ branchCode,
321
+ containedInPlace,
322
+ containsPlace: [],
323
+ parentOrganization: movieTheater.parentOrganization
324
+ };
325
+ const setOnInsert = initialRoom;
326
+ const update = Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined);
327
+ const updateOne = {
328
+ filter,
329
+ update,
330
+ upsert: true
331
+ };
332
+ bulkWriteOps.push({ updateOne });
333
+ });
334
+ }
335
+ if (bulkWriteOps.length > 0) {
336
+ const bulkWriteResult = yield this.placeModel.bulkWrite(bulkWriteOps, { ordered: false });
337
+ return { bulkWriteResult };
338
+ }
339
+ return {};
340
+ });
341
+ }
342
+ deleteRoomByBranchCode(screeningRoom, options) {
343
+ return __awaiter(this, void 0, void 0, function* () {
344
+ const { project, parentOrganization, movieTheaterCode } = options;
345
+ const doc = yield this.placeModel.findOneAndDelete(Object.assign({ typeOf: { $eq: factory.placeType.ScreeningRoom }, 'project.id': { $eq: project.id }, 'containedInPlace.branchCode': { $exists: true, $eq: movieTheaterCode }, branchCode: screeningRoom.branchCode }, (typeof (parentOrganization === null || parentOrganization === void 0 ? void 0 : parentOrganization.id) === 'string')
346
+ ? { 'parentOrganization.id': { $exists: true, $eq: parentOrganization.id } }
177
347
  : undefined), {
178
348
  projection: { 'containedInPlace.id': 1, typeOf: 1 }
179
349
  })
@@ -194,130 +364,19 @@ class ScreeningRoomRepo {
194
364
  .exec();
195
365
  });
196
366
  }
197
- // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
198
367
  searchScreeningRooms(searchConditions) {
199
368
  return __awaiter(this, void 0, void 0, function* () {
200
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
201
- const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.ScreeningRoom } } }];
202
- const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
203
- if (typeof projectIdEq === 'string') {
204
- matchStages.push({
205
- $match: { 'project.id': { $eq: projectIdEq } }
206
- });
207
- }
208
- const parentOrganizationIdEq = (_d = (_c = searchConditions.parentOrganization) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
209
- if (typeof parentOrganizationIdEq === 'string') {
210
- matchStages.push({
211
- $match: { 'parentOrganization.id': { $exists: true, $eq: parentOrganizationIdEq } }
212
- });
213
- }
214
- // 施設ID
215
- const containedInPlaceIdEq = (_f = (_e = searchConditions.containedInPlace) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
216
- if (typeof containedInPlaceIdEq === 'string') {
217
- matchStages.push({
218
- $match: {
219
- 'containedInPlace.id': {
220
- $exists: true,
221
- $eq: containedInPlaceIdEq
222
- }
223
- }
224
- });
225
- }
226
- if (searchConditions.containedInPlace !== undefined) {
227
- // 施設コード
228
- if (searchConditions.containedInPlace.branchCode !== undefined) {
229
- if (typeof searchConditions.containedInPlace.branchCode.$eq === 'string') {
230
- matchStages.push({
231
- $match: {
232
- 'containedInPlace.branchCode': {
233
- $exists: true,
234
- $eq: searchConditions.containedInPlace.branchCode.$eq
235
- }
236
- }
237
- });
238
- }
239
- }
240
- }
241
- const branchCodeEq = (_g = searchConditions.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
242
- if (typeof branchCodeEq === 'string') {
243
- matchStages.push({
244
- $match: {
245
- branchCode: { $eq: branchCodeEq }
246
- }
247
- });
248
- }
249
- const branchCodeIn = (_h = searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$in;
250
- if (Array.isArray(branchCodeIn)) {
251
- matchStages.push({
252
- $match: {
253
- branchCode: { $in: branchCodeIn }
254
- }
255
- });
256
- }
257
- const branchCodeRegex = (_j = searchConditions.branchCode) === null || _j === void 0 ? void 0 : _j.$regex;
258
- if (typeof branchCodeRegex === 'string') {
259
- matchStages.push({
260
- $match: {
261
- branchCode: {
262
- $regex: new RegExp(branchCodeRegex)
263
- }
264
- }
265
- });
266
- }
267
- const nameCodeRegex = (_k = searchConditions.name) === null || _k === void 0 ? void 0 : _k.$regex;
268
- if (typeof nameCodeRegex === 'string') {
269
- matchStages.push({
270
- $match: {
271
- $or: [
272
- {
273
- 'name.ja': {
274
- $exists: true,
275
- $regex: new RegExp(nameCodeRegex)
276
- }
277
- },
278
- {
279
- 'name.en': {
280
- $exists: true,
281
- $regex: new RegExp(nameCodeRegex)
282
- }
283
- }
284
- ]
285
- }
286
- });
287
- }
288
- const openSeatingAllowed = searchConditions.openSeatingAllowed;
289
- if (typeof openSeatingAllowed === 'boolean') {
290
- matchStages.push({
291
- $match: {
292
- openSeatingAllowed: {
293
- $exists: true,
294
- $eq: openSeatingAllowed
295
- }
296
- }
297
- });
298
- }
299
- const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
300
- if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
301
- matchStages.push({
302
- $match: {
303
- additionalProperty: {
304
- $exists: true,
305
- $elemMatch: additionalPropertyElemMatch
306
- }
307
- }
308
- });
309
- }
369
+ var _a, _b;
310
370
  const aggregate = this.placeModel.aggregate([
311
371
  { $sort: { branchCode: factory.sortType.Ascending } },
312
- // { $unwind: '$containsPlace' },
313
- ...matchStages,
372
+ ...ScreeningRoomRepo.CREATE_ROOM_MONGO_CONDITIONS(searchConditions),
314
373
  {
315
374
  $project: Object.assign(Object.assign({ _id: 0, typeOf: '$typeOf', branchCode: '$branchCode', name: '$name', address: '$address', containedInPlace: {
316
375
  id: '$containedInPlace.id',
317
376
  typeOf: '$containedInPlace.typeOf',
318
377
  branchCode: '$containedInPlace.branchCode',
319
378
  name: '$containedInPlace.name'
320
- }, openSeatingAllowed: '$openSeatingAllowed', additionalProperty: '$additionalProperty', maximumAttendeeCapacity: '$maximumAttendeeCapacity' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.sectionCount) === 1)
379
+ }, openSeatingAllowed: '$openSeatingAllowed', additionalProperty: '$additionalProperty', maximumAttendeeCapacity: '$maximumAttendeeCapacity' }, (((_a = searchConditions.$projection) === null || _a === void 0 ? void 0 : _a.sectionCount) === 1)
321
380
  ? {
322
381
  sectionCount: {
323
382
  $cond: {
@@ -327,7 +386,7 @@ class ScreeningRoomRepo {
327
386
  }
328
387
  }
329
388
  }
330
- : undefined), (((_o = searchConditions.$projection) === null || _o === void 0 ? void 0 : _o.seatCount) === 1)
389
+ : undefined), (((_b = searchConditions.$projection) === null || _b === void 0 ? void 0 : _b.seatCount) === 1)
331
390
  ? {
332
391
  seatCount: {
333
392
  $sum: {
@@ -359,6 +418,34 @@ class ScreeningRoomRepo {
359
418
  .exec();
360
419
  });
361
420
  }
421
+ findRooms(params) {
422
+ return __awaiter(this, void 0, void 0, function* () {
423
+ const aggregate = this.placeModel.aggregate([
424
+ ...ScreeningRoomRepo.CREATE_ROOM_MONGO_CONDITIONS(params),
425
+ {
426
+ $project: {
427
+ _id: 0,
428
+ branchCode: '$branchCode',
429
+ name: '$name',
430
+ address: '$address',
431
+ openSeatingAllowed: '$openSeatingAllowed',
432
+ additionalProperty: '$additionalProperty',
433
+ maximumAttendeeCapacity: '$maximumAttendeeCapacity'
434
+ }
435
+ },
436
+ { $sort: { branchCode: factory.sortType.Ascending } }
437
+ ]);
438
+ const { limit, page } = params;
439
+ if (typeof limit === 'number' && limit > 0) {
440
+ const pageMustBePositive = (typeof page === 'number' && page > 0) ? page : 1;
441
+ aggregate.skip(limit * (pageMustBePositive - 1))
442
+ .limit(limit);
443
+ }
444
+ return aggregate
445
+ .option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
446
+ .exec();
447
+ });
448
+ }
362
449
  /**
363
450
  * セクションと座席も含めたひとつのルームを取得する
364
451
  */
@@ -430,5 +517,10 @@ class ScreeningRoomRepo {
430
517
  .exec();
431
518
  });
432
519
  }
520
+ getCursor(conditions, projection) {
521
+ return this.placeModel.find(conditions, projection)
522
+ .sort({ branchCode: factory.sortType.Ascending })
523
+ .cursor();
524
+ }
433
525
  }
434
526
  exports.ScreeningRoomRepo = ScreeningRoomRepo;
@@ -1,6 +1,19 @@
1
- import type { AnyExpression, Connection, PipelineStage } from 'mongoose';
1
+ import type { BulkWriteResult } from 'mongodb';
2
+ import { AnyExpression, Connection, PipelineStage } from 'mongoose';
2
3
  import * as factory from '../../factory';
3
4
  type IMatchStage = PipelineStage.Match;
5
+ type ICreatingSeat = Pick<factory.place.seat.IPlace, 'additionalProperty' | 'branchCode' | 'name' | 'maximumAttendeeCapacity' | 'seatingType'>;
6
+ interface IUpdateOptions {
7
+ project: {
8
+ id: string;
9
+ };
10
+ parentOrganization?: {
11
+ id?: string;
12
+ };
13
+ movieTheaterCode: string;
14
+ roomCode: string;
15
+ sectionCode: string;
16
+ }
4
17
  /**
5
18
  * 座席編集時レスポンス
6
19
  */
@@ -27,25 +40,27 @@ export declare class SeatRepo {
27
40
  static CREATE_MATCH_STAGES(params: factory.place.seat.ISearchConditions, options: {
28
41
  filterTypeOf: boolean;
29
42
  }): IMatchStage[];
30
- createSeat(seat: factory.place.seat.IPlace & {
31
- parentOrganization?: {
32
- id?: string;
33
- };
34
- }): Promise<IUpdateSeatResult>;
35
- updateSeat(seat: Omit<factory.place.seat.IPlace, 'containedInPlace'> & {
36
- containedInPlace: {
37
- branchCode: string;
38
- containedInPlace: {
39
- branchCode: string;
40
- containedInPlace: {
41
- branchCode: string;
42
- };
43
- };
44
- };
45
- parentOrganization?: {
46
- id?: string;
43
+ createSeat(seat: ICreatingSeat, options: IUpdateOptions): Promise<IUpdateSeatResult>;
44
+ /**
45
+ * コードをキーにして冪等追加
46
+ */
47
+ addSeatsByBranchCodeIfNotExist(params: {
48
+ $set: ICreatingSeat;
49
+ }[], options: IUpdateOptions): Promise<{
50
+ bulkWriteResult: BulkWriteResult;
51
+ } | void>;
52
+ /**
53
+ * コードをキーにして冪等編集
54
+ */
55
+ updateSeatsByBranchCode(params: {
56
+ $set: ICreatingSeat;
57
+ $unset?: {
58
+ [key in keyof ICreatingSeat]?: 1;
47
59
  };
48
- }, $unset: any): Promise<IUpdateSeatResult>;
60
+ }[], options: IUpdateOptions): Promise<{
61
+ bulkWriteResult: BulkWriteResult;
62
+ } | void>;
63
+ updateSeatByBranchCode(seat: ICreatingSeat, $unset: any, options: IUpdateOptions): Promise<IUpdateSeatResult>;
49
64
  searchSeats(params: factory.place.seat.ISearchConditions): Promise<factory.place.seat.IPlace[]>;
50
65
  projectSeatsByScreeningRoom(params: Pick<factory.place.seat.ISearchConditions, '$projection' | 'additionalProperty' | 'branchCode' | 'seatingType' | 'name' | 'limit' | 'page'> & {
51
66
  project: {
@@ -137,35 +152,22 @@ export declare class SeatRepo {
137
152
  };
138
153
  };
139
154
  }): Promise<string[]>;
140
- deleteSeat(seat: {
141
- project: {
142
- id: string;
143
- };
144
- parentOrganization?: {
145
- id?: string;
146
- };
155
+ /**
156
+ * コードをキーにして冪等削除
157
+ */
158
+ deleteSeatsByBranchCode(params: {
147
159
  /**
148
160
  * 座席コード
149
161
  */
150
162
  branchCode: string;
151
- containedInPlace: {
152
- /**
153
- * セクションコード
154
- */
155
- branchCode: string;
156
- containedInPlace: {
157
- /**
158
- * ルームコード
159
- */
160
- branchCode: string;
161
- containedInPlace: {
162
- /**
163
- * 施設コード
164
- */
165
- branchCode: string;
166
- };
167
- };
168
- };
169
- }): Promise<IUpdateSeatResult>;
163
+ }[], options: IUpdateOptions): Promise<{
164
+ bulkWriteResult: BulkWriteResult;
165
+ } | void>;
166
+ deleteSeatByBranchCode(seat: {
167
+ /**
168
+ * 座席コード
169
+ */
170
+ branchCode: string;
171
+ }, options: IUpdateOptions): Promise<IUpdateSeatResult>;
170
172
  }
171
173
  export {};