@chevre/domain 21.2.0-alpha.140 → 21.2.0-alpha.141

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,41 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ // const PROJECT_ID = String(process.env.PROJECT_ID);
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const placeRepo = new chevre.repository.Place(mongoose.connection);
12
+
13
+ const cursor = placeRepo.getCursor(
14
+ {
15
+ typeOf: { $eq: chevre.factory.placeType.MovieTheater }
16
+ },
17
+ {
18
+ _id: 1,
19
+ name: 1,
20
+ project: 1,
21
+ typeOf: 1
22
+ }
23
+ );
24
+ console.log('places found');
25
+
26
+ let i = 0;
27
+ await cursor.eachAsync(async (doc) => {
28
+ i += 1;
29
+ const { id, name, project, typeOf } = <Pick<chevre.factory.place.movieTheater.IPlace, 'id' | 'name' | 'project' | 'typeOf'>>
30
+ doc.toObject();
31
+
32
+ console.log('syncing...', project.id, typeOf, id, name.ja, i);
33
+ // await placeRepo.syncScreeningRooms({ id });
34
+ console.log('synced.', project.id, typeOf, id, name.ja, i);
35
+ });
36
+
37
+ }
38
+
39
+ main()
40
+ .then(console.log)
41
+ .catch(console.error);
@@ -216,6 +216,10 @@ export declare class MongoRepository {
216
216
  * 施設ID
217
217
  */
218
218
  id: string;
219
+ /**
220
+ * 特定のルームのみ同期する場合、ルームコードを指定する
221
+ */
222
+ screeningRoomBranchCode?: string;
219
223
  }): Promise<void>;
220
224
  deleteByProject(params: {
221
225
  project: {
@@ -244,12 +244,49 @@ class MongoRepository {
244
244
  // void化(2023-06-23~)
245
245
  saveMovieTheaterByBranchCode4coa(params) {
246
246
  return __awaiter(this, void 0, void 0, function* () {
247
- yield this.placeModel.updateOne({
247
+ const movieTheaterDoc = yield this.placeModel.findOneAndUpdate({
248
248
  typeOf: { $eq: factory.placeType.MovieTheater },
249
249
  'project.id': { $eq: params.project.id },
250
250
  branchCode: { $eq: params.branchCode }
251
- }, params)
251
+ }, params, {
252
+ new: true,
253
+ projection: { _id: 1 }
254
+ })
252
255
  .exec();
256
+ if (movieTheaterDoc === null) {
257
+ throw new factory.errors.NotFound(factory.placeType.MovieTheater);
258
+ }
259
+ const movieTheater = movieTheaterDoc.toObject();
260
+ // ScreeningRoomも保管する(2023-06-24~)
261
+ const creatingScreeningRooms = params.containsPlace.map((place) => {
262
+ return Object.assign(Object.assign({}, place), { containedInPlace: {
263
+ id: movieTheater.id,
264
+ typeOf: params.typeOf,
265
+ branchCode: params.branchCode,
266
+ name: params.name
267
+ }, containsPlace: (Array.isArray(place.containsPlace)) ? place.containsPlace : [], project: params.project });
268
+ });
269
+ yield Promise.all(creatingScreeningRooms.map((createScreeningRoom) => __awaiter(this, void 0, void 0, function* () {
270
+ const { typeOf, project, branchCode } = createScreeningRoom, setFields = __rest(createScreeningRoom, ["typeOf", "project", "branchCode"]);
271
+ yield this.placeModel.findOneAndUpdate({
272
+ typeOf: { $eq: factory.placeType.ScreeningRoom },
273
+ 'project.id': { $eq: createScreeningRoom.project.id },
274
+ 'containedInPlace.id': { $exists: true, $eq: createScreeningRoom.containedInPlace.id },
275
+ branchCode: { $eq: createScreeningRoom.branchCode }
276
+ }, {
277
+ $setOnInsert: {
278
+ typeOf: createScreeningRoom.typeOf,
279
+ project: createScreeningRoom.project,
280
+ branchCode: createScreeningRoom.branchCode
281
+ },
282
+ $set: setFields
283
+ }, {
284
+ upsert: true,
285
+ new: true,
286
+ projection: { _id: 1 }
287
+ })
288
+ .exec();
289
+ })));
253
290
  });
254
291
  }
255
292
  // 廃止(2023-06-23~)
@@ -1274,7 +1311,10 @@ class MongoRepository {
1274
1311
  }
1275
1312
  syncScreeningRooms(params) {
1276
1313
  return __awaiter(this, void 0, void 0, function* () {
1277
- const movieTheater = yield this.placeModel.findOne({ _id: { $eq: params.id } })
1314
+ const movieTheater = yield this.placeModel.findOne({
1315
+ _id: { $eq: params.id },
1316
+ typeOf: { $eq: factory.placeType.MovieTheater }
1317
+ })
1278
1318
  .select({
1279
1319
  _id: 1, branchCode: 1, name: 1, project: 1, typeOf: 1, containsPlace: 1
1280
1320
  })
@@ -1285,7 +1325,11 @@ class MongoRepository {
1285
1325
  }
1286
1326
  return doc.toObject();
1287
1327
  });
1288
- const creatingScreeningRooms = movieTheater.containsPlace.map((place) => {
1328
+ let screeningRoomsFromMovieTheater = movieTheater.containsPlace;
1329
+ if (typeof params.screeningRoomBranchCode === 'string' && params.screeningRoomBranchCode.length > 0) {
1330
+ screeningRoomsFromMovieTheater = screeningRoomsFromMovieTheater.filter((place) => place.branchCode === params.screeningRoomBranchCode);
1331
+ }
1332
+ const creatingScreeningRooms = screeningRoomsFromMovieTheater.map((place) => {
1289
1333
  return Object.assign(Object.assign({}, place), { containedInPlace: {
1290
1334
  id: movieTheater.id,
1291
1335
  typeOf: movieTheater.typeOf,
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.2.0-alpha.140"
120
+ "version": "21.2.0-alpha.141"
121
121
  }