@chevre/domain 20.2.0-alpha.1 → 20.2.0-alpha.11

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.
@@ -0,0 +1,90 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ // const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
10
+
11
+ // tslint:disable-next-line:max-func-body-length
12
+ async function main() {
13
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
14
+
15
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
16
+
17
+ const cursor = eventRepo.getCursor(
18
+ {
19
+ // 'project.id': { $eq: project.id },
20
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
21
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
22
+ startDate: {
23
+ $gte: moment()
24
+ // tslint:disable-next-line:no-magic-numbers
25
+ .add(-6, 'months')
26
+ .toDate()
27
+ }
28
+ // _id: { $eq: 'al6aff83w' }
29
+ },
30
+ {
31
+ // _id: 1,
32
+ }
33
+ );
34
+ console.log('events found');
35
+
36
+ let i = 0;
37
+ let updateCount = 0;
38
+ await cursor.eachAsync(async (doc) => {
39
+ i += 1;
40
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
41
+
42
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
43
+ if (eventOffers === undefined) {
44
+ throw new Error('event.offers undefined');
45
+ }
46
+
47
+ const availableChannel = eventOffers.itemOffered.availableChannel;
48
+
49
+ const alreadyMigrated = availableChannel?.typeOf === 'ServiceChannel';
50
+
51
+ if (alreadyMigrated) {
52
+ console.log(
53
+ 'already exist...', event.project.id, event.id, event.startDate, availableChannel.serviceLocation.branchCode, i);
54
+ } else {
55
+ const newAvailableChannel: chevre.factory.reservation.IServiceChannel = {
56
+ typeOf: 'ServiceChannel',
57
+ serviceLocation: {
58
+ typeOf: event.location.typeOf,
59
+ branchCode: event.location.branchCode,
60
+ name: event.location.name,
61
+ containedInPlace: {
62
+ typeOf: event.superEvent.location.typeOf,
63
+ id: event.superEvent.location.id,
64
+ branchCode: event.superEvent.location.branchCode,
65
+ name: event.superEvent.location.name
66
+ }
67
+ }
68
+ };
69
+ console.log(
70
+ 'updating seller...', event.project.id, event.id, event.startDate, newAvailableChannel.serviceLocation.branchCode, i);
71
+ await eventRepo.updatePartiallyById({
72
+ id: event.id,
73
+ attributes: <any>{
74
+ typeOf: event.typeOf,
75
+ 'offers.itemOffered.availableChannel': newAvailableChannel
76
+ }
77
+ });
78
+ updateCount += 1;
79
+ console.log(
80
+ 'updated...', event.project.id, event.id, event.startDate, i);
81
+ }
82
+ });
83
+
84
+ console.log(i, 'events checked');
85
+ console.log(updateCount, 'events updated');
86
+ }
87
+
88
+ main()
89
+ .then()
90
+ .catch(console.error);
@@ -18,7 +18,6 @@ async function main() {
18
18
  // 'project.id': { $eq: project.id },
19
19
  'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
20
  typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
21
- // typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
22
21
  startDate: {
23
22
  $gte: moment()
24
23
  .add(-1, 'month')
@@ -36,18 +35,37 @@ async function main() {
36
35
  let updateCount = 0;
37
36
  await cursor.eachAsync(async (doc) => {
38
37
  i += 1;
39
- const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
38
+ const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
40
39
 
41
- const locationProjectId = (<any>event.location).project?.id;
42
- if (typeof locationProjectId !== 'string') {
43
- console.log('already deleted', event.id, event.startDate, event.project.id, i);
40
+ // IAMメンバー検索
41
+ const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
42
+ if (eventOffers === undefined) {
43
+ throw new Error('event.offers undefined');
44
+ }
45
+
46
+ const itemOfferedTypeOf = eventOffers.itemOffered.typeOf;
47
+
48
+ const alreadyMigrated = itemOfferedTypeOf === chevre.factory.product.ProductType.EventService;
49
+
50
+ if (alreadyMigrated) {
51
+ console.log(
52
+ 'already exist...', event.project.id, event.id, event.startDate, itemOfferedTypeOf, i);
44
53
  } else {
54
+ console.log(
55
+ 'updating seller...', event.project.id, event.id, event.startDate, i);
56
+ await eventRepo.updatePartiallyById({
57
+ id: event.id,
58
+ attributes: <any>{
59
+ typeOf: event.typeOf,
60
+ 'offers.itemOffered.typeOf': chevre.factory.product.ProductType.EventService
61
+ }
62
+ });
45
63
  updateCount += 1;
46
- console.log('deleting project...', event.id, event.startDate, event.project.id, i);
47
- await eventRepo.deleteUnnecessaryProjectAttributesById({ id: event.id });
48
- console.log('project deleted', event.id, event.startDate, event.project.id, i);
64
+ console.log(
65
+ 'updated...', event.project.id, event.id, event.startDate, i);
49
66
  }
50
67
  });
68
+
51
69
  console.log(i, 'events checked');
52
70
  console.log(updateCount, 'events updated');
53
71
  }
@@ -7,6 +7,7 @@ declare type IScreeningRoomSectionWithoutContainsPlace = Omit<factory.place.scre
7
7
  export declare class MongoRepository {
8
8
  private readonly placeModel;
9
9
  constructor(connection: Connection);
10
+ static CREATE_BUS_STOP_MONGO_CONDITIONS(params: factory.place.busStop.ISearchConditions): any[];
10
11
  static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params: factory.place.movieTheater.ISearchConditions): any[];
11
12
  /**
12
13
  * 施設を保管する
@@ -19,7 +20,6 @@ export declare class MongoRepository {
19
20
  };
20
21
  branchCode: string;
21
22
  }): Promise<factory.place.movieTheater.IPlace>;
22
- countMovieTheaters(params: factory.place.movieTheater.ISearchConditions): Promise<number>;
23
23
  /**
24
24
  * 施設検索
25
25
  */
@@ -114,6 +114,20 @@ export declare class MongoRepository {
114
114
  id: string;
115
115
  };
116
116
  }): Promise<void>;
117
+ saveBusStop(params: factory.place.busStop.IPlace): Promise<factory.place.busStop.IPlace>;
118
+ findBusStopByBranchCode(params: {
119
+ project: {
120
+ id: string;
121
+ };
122
+ branchCode: string;
123
+ }): Promise<factory.place.movieTheater.IPlace>;
124
+ searchBusStops(params: factory.place.busStop.ISearchConditions): Promise<factory.place.busStop.IPlace[]>;
125
+ findBusStopById(params: {
126
+ id: string;
127
+ }, projection?: any): Promise<factory.place.busStop.IPlace>;
128
+ deleteBusStopById(params: {
129
+ id: string;
130
+ }): Promise<void>;
117
131
  getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
118
132
  }
119
133
  export {};
@@ -32,15 +32,89 @@ class MongoRepository {
32
32
  this.placeModel = connection.model(place_1.modelName);
33
33
  }
34
34
  // tslint:disable-next-line:max-func-body-length
35
+ static CREATE_BUS_STOP_MONGO_CONDITIONS(params) {
36
+ var _a, _b, _c, _d, _e, _f, _g, _h;
37
+ const andConditions = [{ typeOf: { $eq: factory.placeType.BusStop } }];
38
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
39
+ if (typeof projectIdEq === 'string') {
40
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
41
+ }
42
+ const branchCodeEq = (_c = params.branchCode) === null || _c === void 0 ? void 0 : _c.$eq;
43
+ if (typeof branchCodeEq === 'string') {
44
+ andConditions.push({
45
+ branchCode: {
46
+ $exists: true,
47
+ $eq: branchCodeEq
48
+ }
49
+ });
50
+ }
51
+ const branchCodeRegex = (_d = params.branchCode) === null || _d === void 0 ? void 0 : _d.$regex;
52
+ if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
53
+ andConditions.push({
54
+ branchCode: {
55
+ $exists: true,
56
+ $regex: new RegExp(branchCodeRegex)
57
+ }
58
+ });
59
+ }
60
+ const branchCodeIn = (_e = params.branchCode) === null || _e === void 0 ? void 0 : _e.$in;
61
+ if (Array.isArray(branchCodeIn)) {
62
+ andConditions.push({
63
+ branchCode: {
64
+ $exists: true,
65
+ $in: branchCodeIn
66
+ }
67
+ });
68
+ }
69
+ // tslint:disable-next-line:no-single-line-block-comment
70
+ /* istanbul ignore else */
71
+ const idEq = (_f = params.id) === null || _f === void 0 ? void 0 : _f.$eq;
72
+ if (typeof idEq === 'string') {
73
+ andConditions.push({
74
+ _id: {
75
+ $eq: idEq
76
+ }
77
+ });
78
+ }
79
+ const idIn = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$in;
80
+ if (Array.isArray(idIn)) {
81
+ andConditions.push({
82
+ _id: {
83
+ $in: idIn
84
+ }
85
+ });
86
+ }
87
+ const nameRegex = (_h = params.name) === null || _h === void 0 ? void 0 : _h.$regex;
88
+ // tslint:disable-next-line:no-single-line-block-comment
89
+ /* istanbul ignore else */
90
+ if (typeof nameRegex === 'string' && nameRegex.length > 0) {
91
+ andConditions.push({
92
+ $or: [
93
+ {
94
+ 'name.ja': {
95
+ $exists: true,
96
+ $regex: new RegExp(nameRegex)
97
+ }
98
+ },
99
+ {
100
+ 'name.en': {
101
+ $exists: true,
102
+ $regex: new RegExp(nameRegex)
103
+ }
104
+ }
105
+ ]
106
+ });
107
+ }
108
+ return andConditions;
109
+ }
110
+ // tslint:disable-next-line:max-func-body-length
35
111
  static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params) {
36
112
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
37
113
  // MongoDB検索条件
38
114
  const andConditions = [{ typeOf: { $eq: factory.placeType.MovieTheater } }];
39
115
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
40
116
  if (typeof projectIdEq === 'string') {
41
- andConditions.push({
42
- 'project.id': { $eq: projectIdEq }
43
- });
117
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
44
118
  }
45
119
  const branchCodeEq = (_c = params.branchCode) === null || _c === void 0 ? void 0 : _c.$eq;
46
120
  if (typeof branchCodeEq === 'string') {
@@ -173,6 +247,7 @@ class MongoRepository {
173
247
  findMovieTheaterByBranchCode(params) {
174
248
  return __awaiter(this, void 0, void 0, function* () {
175
249
  return this.placeModel.findOne({
250
+ typeOf: { $eq: factory.placeType.MovieTheater },
176
251
  'project.id': { $eq: params.project.id },
177
252
  branchCode: { $eq: params.branchCode }
178
253
  })
@@ -185,14 +260,12 @@ class MongoRepository {
185
260
  });
186
261
  });
187
262
  }
188
- countMovieTheaters(params) {
189
- return __awaiter(this, void 0, void 0, function* () {
190
- const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
191
- return this.placeModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
192
- .setOptions({ maxTimeMS: 10000 })
193
- .exec();
194
- });
195
- }
263
+ // public async countMovieTheaters(params: factory.place.movieTheater.ISearchConditions): Promise<number> {
264
+ // const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
265
+ // return this.placeModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
266
+ // .setOptions({ maxTimeMS: 10000 })
267
+ // .exec();
268
+ // }
196
269
  /**
197
270
  * 施設検索
198
271
  */
@@ -226,7 +299,10 @@ class MongoRepository {
226
299
  */
227
300
  findById(params, projection) {
228
301
  return __awaiter(this, void 0, void 0, function* () {
229
- const doc = yield this.placeModel.findOne({ _id: params.id }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
302
+ const doc = yield this.placeModel.findOne({
303
+ typeOf: { $eq: factory.placeType.MovieTheater },
304
+ _id: { $eq: params.id }
305
+ }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
230
306
  .exec();
231
307
  if (doc === null) {
232
308
  throw new factory.errors.NotFound(this.placeModel.modelName);
@@ -237,7 +313,8 @@ class MongoRepository {
237
313
  deleteMovieTheaterById(params) {
238
314
  return __awaiter(this, void 0, void 0, function* () {
239
315
  yield this.placeModel.findOneAndDelete({
240
- _id: params.id
316
+ typeOf: { $eq: factory.placeType.MovieTheater },
317
+ _id: { $eq: params.id }
241
318
  })
242
319
  .exec()
243
320
  .then((doc) => {
@@ -435,22 +512,17 @@ class MongoRepository {
435
512
  }
436
513
  // tslint:disable-next-line:max-func-body-length
437
514
  searchScreeningRoomSections(searchConditions) {
438
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
515
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
439
516
  return __awaiter(this, void 0, void 0, function* () {
440
- const matchStages = [];
441
- if (searchConditions.project !== undefined) {
442
- if (searchConditions.project.id !== undefined) {
443
- if (typeof searchConditions.project.id.$eq === 'string') {
444
- matchStages.push({
445
- $match: {
446
- 'project.id': { $eq: searchConditions.project.id.$eq }
447
- }
448
- });
449
- }
450
- }
517
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
518
+ const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
519
+ if (typeof projectIdEq === 'string') {
520
+ matchStages.push({
521
+ $match: { 'project.id': { $eq: projectIdEq } }
522
+ });
451
523
  }
452
524
  // 施設コード
453
- const movieTheaterBranchCodeEq = (_c = (_b = (_a = searchConditions.containedInPlace) === null || _a === void 0 ? void 0 : _a.containedInPlace) === null || _b === void 0 ? void 0 : _b.branchCode) === null || _c === void 0 ? void 0 : _c.$eq;
525
+ const movieTheaterBranchCodeEq = (_e = (_d = (_c = searchConditions.containedInPlace) === null || _c === void 0 ? void 0 : _c.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
454
526
  if (typeof movieTheaterBranchCodeEq === 'string') {
455
527
  matchStages.push({
456
528
  $match: {
@@ -462,7 +534,7 @@ class MongoRepository {
462
534
  });
463
535
  }
464
536
  // スクリーンコード
465
- const containedInPlaceBranchCodeEq = (_e = (_d = searchConditions.containedInPlace) === null || _d === void 0 ? void 0 : _d.branchCode) === null || _e === void 0 ? void 0 : _e.$eq;
537
+ const containedInPlaceBranchCodeEq = (_g = (_f = searchConditions.containedInPlace) === null || _f === void 0 ? void 0 : _f.branchCode) === null || _g === void 0 ? void 0 : _g.$eq;
466
538
  if (typeof containedInPlaceBranchCodeEq === 'string') {
467
539
  matchStages.push({
468
540
  $match: {
@@ -474,7 +546,7 @@ class MongoRepository {
474
546
  });
475
547
  }
476
548
  // セクションコード
477
- const sectionBranchCodeEq = (_f = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _f === void 0 ? void 0 : _f.$eq;
549
+ const sectionBranchCodeEq = (_h = searchConditions === null || searchConditions === void 0 ? void 0 : searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
478
550
  if (typeof sectionBranchCodeEq === 'string') {
479
551
  matchStages.push({
480
552
  $match: {
@@ -485,7 +557,7 @@ class MongoRepository {
485
557
  }
486
558
  });
487
559
  }
488
- const nameCodeRegex = (_g = searchConditions.name) === null || _g === void 0 ? void 0 : _g.$regex;
560
+ const nameCodeRegex = (_j = searchConditions.name) === null || _j === void 0 ? void 0 : _j.$regex;
489
561
  if (typeof nameCodeRegex === 'string') {
490
562
  matchStages.push({
491
563
  $match: {
@@ -506,7 +578,7 @@ class MongoRepository {
506
578
  }
507
579
  });
508
580
  }
509
- const branchCodeRegex = (_h = searchConditions.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
581
+ const branchCodeRegex = (_k = searchConditions.branchCode) === null || _k === void 0 ? void 0 : _k.$regex;
510
582
  if (typeof branchCodeRegex === 'string') {
511
583
  matchStages.push({
512
584
  $match: {
@@ -517,7 +589,7 @@ class MongoRepository {
517
589
  }
518
590
  });
519
591
  }
520
- const additionalPropertyElemMatch = (_j = searchConditions.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
592
+ const additionalPropertyElemMatch = (_l = searchConditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
521
593
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
522
594
  matchStages.push({
523
595
  $match: {
@@ -543,7 +615,7 @@ class MongoRepository {
543
615
  branchCode: '$branchCode',
544
616
  name: '$name'
545
617
  }
546
- }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_k = searchConditions.$projection) === null || _k === void 0 ? void 0 : _k.seatCount) === 1)
618
+ }, additionalProperty: '$containsPlace.containsPlace.additionalProperty' }, (((_m = searchConditions.$projection) === null || _m === void 0 ? void 0 : _m.seatCount) === 1)
547
619
  ? {
548
620
  seatCount: {
549
621
  $cond: {
@@ -595,7 +667,7 @@ class MongoRepository {
595
667
  searchScreeningRooms(searchConditions) {
596
668
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
597
669
  return __awaiter(this, void 0, void 0, function* () {
598
- const matchStages = [];
670
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
599
671
  const projectIdEq = (_b = (_a = searchConditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
600
672
  if (typeof projectIdEq === 'string') {
601
673
  matchStages.push({
@@ -855,21 +927,16 @@ class MongoRepository {
855
927
  }
856
928
  // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
857
929
  searchSeats(params) {
858
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
930
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
859
931
  return __awaiter(this, void 0, void 0, function* () {
860
- const matchStages = [];
861
- if (params.project !== undefined) {
862
- if (params.project.id !== undefined) {
863
- if (typeof params.project.id.$eq === 'string') {
864
- matchStages.push({
865
- $match: {
866
- 'project.id': { $eq: params.project.id.$eq }
867
- }
868
- });
869
- }
870
- }
932
+ const matchStages = [{ $match: { typeOf: { $eq: factory.placeType.MovieTheater } } }];
933
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
934
+ if (typeof projectIdEq === 'string') {
935
+ matchStages.push({
936
+ $match: { 'project.id': { $eq: projectIdEq } }
937
+ });
871
938
  }
872
- const containedInPlaceBranchCodeEq = (_b = (_a = params.containedInPlace) === null || _a === void 0 ? void 0 : _a.branchCode) === null || _b === void 0 ? void 0 : _b.$eq;
939
+ const containedInPlaceBranchCodeEq = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$eq;
873
940
  if (typeof containedInPlaceBranchCodeEq === 'string') {
874
941
  matchStages.push({
875
942
  $match: {
@@ -880,7 +947,7 @@ class MongoRepository {
880
947
  }
881
948
  });
882
949
  }
883
- const containedInPlaceBranchCodeIn = (_d = (_c = params.containedInPlace) === null || _c === void 0 ? void 0 : _c.branchCode) === null || _d === void 0 ? void 0 : _d.$in;
950
+ const containedInPlaceBranchCodeIn = (_f = (_e = params.containedInPlace) === null || _e === void 0 ? void 0 : _e.branchCode) === null || _f === void 0 ? void 0 : _f.$in;
884
951
  if (Array.isArray(containedInPlaceBranchCodeIn)) {
885
952
  matchStages.push({
886
953
  $match: {
@@ -934,7 +1001,7 @@ class MongoRepository {
934
1001
  });
935
1002
  }
936
1003
  }
937
- const branchCodeIn = (_e = params.branchCode) === null || _e === void 0 ? void 0 : _e.$in;
1004
+ const branchCodeIn = (_g = params.branchCode) === null || _g === void 0 ? void 0 : _g.$in;
938
1005
  if (Array.isArray(branchCodeIn)) {
939
1006
  matchStages.push({
940
1007
  $match: {
@@ -945,7 +1012,7 @@ class MongoRepository {
945
1012
  }
946
1013
  });
947
1014
  }
948
- const branchCodeRegex = (_f = params.branchCode) === null || _f === void 0 ? void 0 : _f.$regex;
1015
+ const branchCodeRegex = (_h = params.branchCode) === null || _h === void 0 ? void 0 : _h.$regex;
949
1016
  if (typeof branchCodeRegex === 'string' && branchCodeRegex.length > 0) {
950
1017
  matchStages.push({
951
1018
  $match: {
@@ -956,7 +1023,7 @@ class MongoRepository {
956
1023
  }
957
1024
  });
958
1025
  }
959
- const nameRegex = (_g = params.name) === null || _g === void 0 ? void 0 : _g.$regex;
1026
+ const nameRegex = (_j = params.name) === null || _j === void 0 ? void 0 : _j.$regex;
960
1027
  if (typeof nameRegex === 'string' && nameRegex.length > 0) {
961
1028
  matchStages.push({
962
1029
  $match: {
@@ -977,7 +1044,7 @@ class MongoRepository {
977
1044
  }
978
1045
  });
979
1046
  }
980
- const seatingTypeEq = (_h = params.seatingType) === null || _h === void 0 ? void 0 : _h.$eq;
1047
+ const seatingTypeEq = (_k = params.seatingType) === null || _k === void 0 ? void 0 : _k.$eq;
981
1048
  if (typeof seatingTypeEq === 'string') {
982
1049
  matchStages.push({
983
1050
  $match: {
@@ -993,7 +1060,7 @@ class MongoRepository {
993
1060
  && params.$projection['containedInPlace.containedInPlace'] === 0) {
994
1061
  includeScreeningRooms = false;
995
1062
  }
996
- const additionalPropertyElemMatch = (_j = params.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
1063
+ const additionalPropertyElemMatch = (_l = params.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
997
1064
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
998
1065
  matchStages.push({
999
1066
  $match: {
@@ -1078,6 +1145,92 @@ class MongoRepository {
1078
1145
  .exec();
1079
1146
  });
1080
1147
  }
1148
+ saveBusStop(params) {
1149
+ return __awaiter(this, void 0, void 0, function* () {
1150
+ let doc;
1151
+ if (typeof params.id !== 'string' || params.id.length === 0) {
1152
+ doc = yield this.placeModel.create(params);
1153
+ }
1154
+ else {
1155
+ // 上書き禁止属性を除外(2022-08-24~)
1156
+ const { id, branchCode, project, typeOf } = params, updateFields = __rest(params, ["id", "branchCode", "project", "typeOf"]);
1157
+ doc = yield this.placeModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
1158
+ .exec();
1159
+ }
1160
+ if (doc === null) {
1161
+ throw new factory.errors.NotFound(this.placeModel.modelName);
1162
+ }
1163
+ return doc.toObject();
1164
+ });
1165
+ }
1166
+ findBusStopByBranchCode(params) {
1167
+ return __awaiter(this, void 0, void 0, function* () {
1168
+ return this.placeModel.findOne({
1169
+ typeOf: { $eq: factory.placeType.BusStop },
1170
+ 'project.id': { $eq: params.project.id },
1171
+ branchCode: { $eq: params.branchCode }
1172
+ })
1173
+ .exec()
1174
+ .then((doc) => {
1175
+ if (doc === null) {
1176
+ throw new factory.errors.NotFound(`${factory.placeType.BusStop} ${params.branchCode}`);
1177
+ }
1178
+ return doc.toObject();
1179
+ });
1180
+ });
1181
+ }
1182
+ searchBusStops(params) {
1183
+ return __awaiter(this, void 0, void 0, function* () {
1184
+ const conditions = MongoRepository.CREATE_BUS_STOP_MONGO_CONDITIONS(params);
1185
+ // containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
1186
+ const query = this.placeModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
1187
+ __v: 0,
1188
+ createdAt: 0,
1189
+ updatedAt: 0,
1190
+ containsPlace: 0
1191
+ });
1192
+ if (typeof params.limit === 'number') {
1193
+ const page = (typeof params.page === 'number') ? params.page : 1;
1194
+ query.limit(params.limit)
1195
+ .skip(params.limit * (page - 1));
1196
+ }
1197
+ // tslint:disable-next-line:no-single-line-block-comment
1198
+ /* istanbul ignore else */
1199
+ if (params.sort !== undefined) {
1200
+ query.sort(params.sort);
1201
+ }
1202
+ return query.setOptions({ maxTimeMS: 10000 })
1203
+ .exec()
1204
+ .then((docs) => docs.map((doc) => doc.toObject()));
1205
+ });
1206
+ }
1207
+ findBusStopById(params, projection) {
1208
+ return __awaiter(this, void 0, void 0, function* () {
1209
+ const doc = yield this.placeModel.findOne({
1210
+ typeOf: { $eq: factory.placeType.BusStop },
1211
+ _id: { $eq: params.id }
1212
+ }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
1213
+ .exec();
1214
+ if (doc === null) {
1215
+ throw new factory.errors.NotFound(this.placeModel.modelName);
1216
+ }
1217
+ return doc.toObject();
1218
+ });
1219
+ }
1220
+ deleteBusStopById(params) {
1221
+ return __awaiter(this, void 0, void 0, function* () {
1222
+ yield this.placeModel.findOneAndDelete({
1223
+ typeOf: { $eq: factory.placeType.BusStop },
1224
+ _id: { $eq: params.id }
1225
+ })
1226
+ .exec()
1227
+ .then((doc) => {
1228
+ if (doc === null) {
1229
+ throw new factory.errors.NotFound(this.placeModel.modelName);
1230
+ }
1231
+ });
1232
+ });
1233
+ }
1081
1234
  getCursor(conditions, projection) {
1082
1235
  return this.placeModel.find(conditions, projection)
1083
1236
  .sort({ branchCode: factory.sortType.Ascending })