@chevre/domain 21.11.0-alpha.3 → 21.11.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.
- package/example/src/chevre/place/migrateHasPOS.ts +76 -0
- package/lib/chevre/repo/place/hasPOS.d.ts +1 -1
- package/lib/chevre/repo/place/hasPOS.js +6 -6
- package/lib/chevre/repo/place.d.ts +0 -13
- package/lib/chevre/repo/place.js +36 -20
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.d.ts +16 -0
- package/lib/chevre/service/task/onResourceUpdated/onHasPOSUpdated.js +75 -0
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +15 -0
- package/lib/chevre/service/task/onResourceUpdated.js +9 -0
- package/package.json +2 -2
- package/example/src/chevre/migrateScreeningRoomOrganizer.ts +0 -91
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
// const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = placeRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
// 'project.id': { $eq: project.id },
|
|
19
|
+
// 'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
20
|
+
typeOf: {
|
|
21
|
+
$eq: chevre.factory.placeType.MovieTheater
|
|
22
|
+
}
|
|
23
|
+
// organizer: { $exists: false }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
branchCode: 1,
|
|
27
|
+
_id: 1, name: 1, project: 1, hasPOS: 1
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
console.log('places found');
|
|
31
|
+
|
|
32
|
+
let i = 0;
|
|
33
|
+
let updateCount = 0;
|
|
34
|
+
await cursor.eachAsync(async (doc) => {
|
|
35
|
+
i += 1;
|
|
36
|
+
const movieTheater: Pick<chevre.factory.place.movieTheater.IPlace,
|
|
37
|
+
'branchCode' | 'id' | 'name' | 'project' | 'hasPOS'> = doc.toObject();
|
|
38
|
+
console.log(movieTheater);
|
|
39
|
+
|
|
40
|
+
if (!Array.isArray(movieTheater.hasPOS)) {
|
|
41
|
+
console.log('has no pos', movieTheater.project.id, movieTheater.branchCode, movieTheater.name.ja, i);
|
|
42
|
+
} else {
|
|
43
|
+
const alreadyMigrated = movieTheater.hasPOS.every((pos) => pos.branchCode === pos.id);
|
|
44
|
+
if (alreadyMigrated) {
|
|
45
|
+
console.log('already migrated...', movieTheater.project.id, movieTheater.branchCode, movieTheater.name.ja, i);
|
|
46
|
+
} else {
|
|
47
|
+
if (movieTheater.hasPOS.length > 0) {
|
|
48
|
+
const newHasPOS: chevre.factory.place.movieTheater.IPOS[] = movieTheater.hasPOS.map((pos) => {
|
|
49
|
+
return {
|
|
50
|
+
id: pos.id,
|
|
51
|
+
branchCode: pos.id,
|
|
52
|
+
name: pos.name
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
console.log('updating place...', movieTheater.project.id, movieTheater.branchCode, movieTheater.name.ja, i, newHasPOS);
|
|
56
|
+
await placeRepo.saveMovieTheater(<any>{
|
|
57
|
+
project: movieTheater.project,
|
|
58
|
+
branchCode: movieTheater.branchCode,
|
|
59
|
+
id: movieTheater.id,
|
|
60
|
+
typeOf: chevre.factory.placeType.MovieTheater,
|
|
61
|
+
hasPOS: newHasPOS
|
|
62
|
+
});
|
|
63
|
+
updateCount += 1;
|
|
64
|
+
console.log('updated.', movieTheater.project.id, movieTheater.branchCode, movieTheater.name.ja, i);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
console.log(i, 'places checked');
|
|
71
|
+
console.log(updateCount, 'places updated');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main()
|
|
75
|
+
.then()
|
|
76
|
+
.catch(console.error);
|
|
@@ -14,7 +14,7 @@ interface IOperator {
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class MongoRepository {
|
|
16
16
|
private readonly placeModel;
|
|
17
|
-
private readonly
|
|
17
|
+
private readonly operator;
|
|
18
18
|
constructor(connection: Connection, operater: IOperator);
|
|
19
19
|
search(params: {
|
|
20
20
|
limit?: number;
|
|
@@ -20,13 +20,13 @@ const settings_1 = require("../../settings");
|
|
|
20
20
|
class MongoRepository {
|
|
21
21
|
constructor(connection, operater) {
|
|
22
22
|
this.placeModel = connection.model(place_1.modelName, place_1.schema);
|
|
23
|
-
this.
|
|
23
|
+
this.operator = operater;
|
|
24
24
|
}
|
|
25
25
|
search(params) {
|
|
26
26
|
var _a, _b, _c, _d;
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
28
|
const matchStages = [
|
|
29
|
-
{ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(this.
|
|
29
|
+
{ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(this.operator.id) } } }
|
|
30
30
|
];
|
|
31
31
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
32
32
|
if (typeof projectIdEq === 'string') {
|
|
@@ -71,7 +71,7 @@ class MongoRepository {
|
|
|
71
71
|
// 施設存在確認
|
|
72
72
|
let doc = yield this.placeModel.findOne({
|
|
73
73
|
'project.id': { $eq: params.project.id },
|
|
74
|
-
_id: { $eq: this.
|
|
74
|
+
_id: { $eq: this.operator.id }
|
|
75
75
|
}, { _id: 1, typeOf: 1 })
|
|
76
76
|
.exec();
|
|
77
77
|
if (doc === null) {
|
|
@@ -84,7 +84,7 @@ class MongoRepository {
|
|
|
84
84
|
};
|
|
85
85
|
doc = yield this.placeModel.findOneAndUpdate({
|
|
86
86
|
'project.id': { $eq: params.project.id },
|
|
87
|
-
_id: { $eq: this.
|
|
87
|
+
_id: { $eq: this.operator.id },
|
|
88
88
|
'hasPOS.branchCode': { $ne: params.branchCode }
|
|
89
89
|
}, {
|
|
90
90
|
$push: { hasPOS: creatingPOS }
|
|
@@ -104,7 +104,7 @@ class MongoRepository {
|
|
|
104
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
105
|
const doc = yield this.placeModel.findOneAndUpdate({
|
|
106
106
|
'project.id': { $eq: params.project.id },
|
|
107
|
-
_id: { $eq: this.
|
|
107
|
+
_id: { $eq: this.operator.id },
|
|
108
108
|
'hasPOS.branchCode': { $eq: params.branchCode }
|
|
109
109
|
}, Object.assign({}, (params.name !== undefined && params.name !== null)
|
|
110
110
|
? { 'hasPOS.$[pos].name': params.name }
|
|
@@ -126,7 +126,7 @@ class MongoRepository {
|
|
|
126
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
127
|
const doc = yield this.placeModel.findOneAndUpdate({
|
|
128
128
|
'project.id': { $eq: params.project.id },
|
|
129
|
-
_id: { $eq: this.
|
|
129
|
+
_id: { $eq: this.operator.id },
|
|
130
130
|
'hasPOS.branchCode': { $eq: params.branchCode }
|
|
131
131
|
}, {
|
|
132
132
|
$pull: { hasPOS: { branchCode: { $eq: params.branchCode } } }
|
|
@@ -81,19 +81,6 @@ export declare class MongoRepository {
|
|
|
81
81
|
};
|
|
82
82
|
typeOf: factory.placeType.ScreeningRoom;
|
|
83
83
|
}>;
|
|
84
|
-
addParentOrganization2ScreeningRoom(screeningRoom: Pick<factory.place.screeningRoom.IPlace, 'branchCode' | 'parentOrganization' | 'project'> & {
|
|
85
|
-
containedInPlace: {
|
|
86
|
-
branchCode: string;
|
|
87
|
-
};
|
|
88
|
-
}): Promise<{
|
|
89
|
-
containedInPlace: {
|
|
90
|
-
/**
|
|
91
|
-
* 施設ID
|
|
92
|
-
*/
|
|
93
|
-
id: string;
|
|
94
|
-
};
|
|
95
|
-
typeOf: factory.placeType.ScreeningRoom;
|
|
96
|
-
}>;
|
|
97
84
|
updateScreeningRoomsByContainedInPlaceId(screeningRoom: {
|
|
98
85
|
project: {
|
|
99
86
|
id: string;
|
package/lib/chevre/repo/place.js
CHANGED
|
@@ -423,26 +423,42 @@ class MongoRepository {
|
|
|
423
423
|
return doc.toObject();
|
|
424
424
|
});
|
|
425
425
|
}
|
|
426
|
-
addParentOrganization2ScreeningRoom(
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
}
|
|
426
|
+
// public async addParentOrganization2ScreeningRoom(
|
|
427
|
+
// screeningRoom: Pick<factory.place.screeningRoom.IPlace, 'branchCode' | 'parentOrganization' | 'project'> & {
|
|
428
|
+
// containedInPlace: {
|
|
429
|
+
// branchCode: string;
|
|
430
|
+
// };
|
|
431
|
+
// }
|
|
432
|
+
// ): Promise<{
|
|
433
|
+
// containedInPlace: {
|
|
434
|
+
// /**
|
|
435
|
+
// * 施設ID
|
|
436
|
+
// */
|
|
437
|
+
// id: string;
|
|
438
|
+
// };
|
|
439
|
+
// typeOf: factory.placeType.ScreeningRoom;
|
|
440
|
+
// }> {
|
|
441
|
+
// const doc = await this.placeModel.findOneAndUpdate(
|
|
442
|
+
// {
|
|
443
|
+
// typeOf: { $eq: factory.placeType.ScreeningRoom },
|
|
444
|
+
// 'project.id': { $eq: screeningRoom.project.id },
|
|
445
|
+
// 'containedInPlace.branchCode': { $exists: true, $eq: screeningRoom.containedInPlace.branchCode },
|
|
446
|
+
// branchCode: screeningRoom.branchCode
|
|
447
|
+
// },
|
|
448
|
+
// {
|
|
449
|
+
// parentOrganization: screeningRoom.parentOrganization
|
|
450
|
+
// },
|
|
451
|
+
// {
|
|
452
|
+
// new: true,
|
|
453
|
+
// projection: { 'containedInPlace.id': 1, typeOf: 1 }
|
|
454
|
+
// }
|
|
455
|
+
// )
|
|
456
|
+
// .exec();
|
|
457
|
+
// if (doc === null) {
|
|
458
|
+
// throw new factory.errors.NotFound(factory.placeType.ScreeningRoom);
|
|
459
|
+
// }
|
|
460
|
+
// return doc.toObject();
|
|
461
|
+
// }
|
|
446
462
|
updateScreeningRoomsByContainedInPlaceId(screeningRoom) {
|
|
447
463
|
var _a;
|
|
448
464
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as factory from '../../../factory';
|
|
2
|
+
import { MongoRepository as PlaceRepo } from '../../../repo/place';
|
|
3
|
+
import { MongoRepository as TaskRepo } from '../../../repo/task';
|
|
4
|
+
export declare function createInformHasPOSTasks(params: {
|
|
5
|
+
project: {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* 施設ID
|
|
10
|
+
*/
|
|
11
|
+
ids: string[];
|
|
12
|
+
typeOf: factory.placeType.MovieTheater;
|
|
13
|
+
}): (repos: {
|
|
14
|
+
place: PlaceRepo;
|
|
15
|
+
task: TaskRepo;
|
|
16
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createInformHasPOSTasks = void 0;
|
|
13
|
+
const factory = require("../../../factory");
|
|
14
|
+
const settings_1 = require("../../../settings");
|
|
15
|
+
const informResources = settings_1.settings.onResourceUpdated.informResource;
|
|
16
|
+
function createInformHasPOSTasks(params) {
|
|
17
|
+
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (params.ids.length !== 1) {
|
|
19
|
+
throw new factory.errors.Argument('id', 'id.length must be 1');
|
|
20
|
+
}
|
|
21
|
+
// 施設のhasPOSを全て連携する
|
|
22
|
+
const movieTheaters = yield repos.place.searchMovieTheaters({
|
|
23
|
+
limit: 1,
|
|
24
|
+
page: 1,
|
|
25
|
+
project: { id: { $eq: params.project.id } },
|
|
26
|
+
id: { $eq: params.ids[0] }
|
|
27
|
+
}, ['hasPOS'], []);
|
|
28
|
+
const movieTheater = movieTheaters.shift();
|
|
29
|
+
if (movieTheater === undefined) {
|
|
30
|
+
throw new factory.errors.NotFound(factory.placeType.MovieTheater);
|
|
31
|
+
}
|
|
32
|
+
const movieTheaters4inform = [{
|
|
33
|
+
hasPOS: (Array.isArray(movieTheater.hasPOS)) ? movieTheater.hasPOS : [],
|
|
34
|
+
id: movieTheater.id,
|
|
35
|
+
typeOf: factory.placeType.MovieTheater
|
|
36
|
+
}];
|
|
37
|
+
if (movieTheaters4inform.length > 0) {
|
|
38
|
+
const taskRunsAt = new Date();
|
|
39
|
+
const informTasks = [];
|
|
40
|
+
informResources === null || informResources === void 0 ? void 0 : informResources.forEach((informResource) => {
|
|
41
|
+
var _a;
|
|
42
|
+
const informUrl = String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.url);
|
|
43
|
+
movieTheaters4inform.forEach((movieTheater4inform) => {
|
|
44
|
+
var _a;
|
|
45
|
+
const informActionAttributes = {
|
|
46
|
+
agent: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
47
|
+
object: movieTheater4inform,
|
|
48
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
49
|
+
recipient: {
|
|
50
|
+
id: '',
|
|
51
|
+
name: String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.name),
|
|
52
|
+
typeOf: factory.creativeWorkType.WebApplication,
|
|
53
|
+
url: informUrl
|
|
54
|
+
},
|
|
55
|
+
typeOf: factory.actionType.InformAction
|
|
56
|
+
};
|
|
57
|
+
informTasks.push({
|
|
58
|
+
project: { id: params.project.id, typeOf: factory.organizationType.Project },
|
|
59
|
+
name: factory.taskName.TriggerWebhook,
|
|
60
|
+
status: factory.taskStatus.Ready,
|
|
61
|
+
runsAt: taskRunsAt,
|
|
62
|
+
remainingNumberOfTries: 10,
|
|
63
|
+
numberOfTried: 0,
|
|
64
|
+
executionResults: [],
|
|
65
|
+
data: informActionAttributes
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
if (informTasks.length > 0) {
|
|
70
|
+
yield repos.task.saveMany(informTasks, { emitImmediately: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
exports.createInformHasPOSTasks = createInformHasPOSTasks;
|
|
@@ -11,11 +11,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.onResourceDeleted = void 0;
|
|
13
13
|
const factory = require("../../../factory");
|
|
14
|
+
const onHasPOSUpdated_1 = require("./onHasPOSUpdated");
|
|
14
15
|
const syncOfferCatalog_1 = require("./syncOfferCatalog");
|
|
16
|
+
// tslint:disable-next-line:max-func-body-length
|
|
15
17
|
function onResourceDeleted(params) {
|
|
16
18
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
17
19
|
const isDeleted = params.isDeleted === true;
|
|
18
20
|
if (isDeleted) {
|
|
21
|
+
if (params.useInform === true) {
|
|
22
|
+
switch (params.typeOf) {
|
|
23
|
+
case 'POS':
|
|
24
|
+
yield (0, onHasPOSUpdated_1.createInformHasPOSTasks)({
|
|
25
|
+
project: { id: params.project.id },
|
|
26
|
+
ids: [params.operator.id],
|
|
27
|
+
typeOf: factory.placeType.MovieTheater
|
|
28
|
+
})(repos);
|
|
29
|
+
break;
|
|
30
|
+
default:
|
|
31
|
+
// no op
|
|
32
|
+
}
|
|
33
|
+
}
|
|
19
34
|
switch (params.typeOf) {
|
|
20
35
|
case factory.eventType.ScreeningEventSeries:
|
|
21
36
|
yield deleteResourcesByScreeningEventSeries({
|
|
@@ -26,6 +26,7 @@ const place_1 = require("../../repo/place");
|
|
|
26
26
|
const product_1 = require("../../repo/product");
|
|
27
27
|
const productOffer_1 = require("../../repo/productOffer");
|
|
28
28
|
const task_1 = require("../../repo/task");
|
|
29
|
+
const onHasPOSUpdated_1 = require("./onResourceUpdated/onHasPOSUpdated");
|
|
29
30
|
const onOfferCatalogUpdated_1 = require("./onResourceUpdated/onOfferCatalogUpdated");
|
|
30
31
|
const onResourceDeleted_1 = require("./onResourceUpdated/onResourceDeleted");
|
|
31
32
|
const settings_1 = require("../../settings");
|
|
@@ -55,6 +56,7 @@ function call(data) {
|
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
exports.call = call;
|
|
59
|
+
// tslint:disable-next-line:max-func-body-length
|
|
58
60
|
function onResourceUpdated(params) {
|
|
59
61
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
60
62
|
const isDeleted = params.isDeleted === true;
|
|
@@ -99,6 +101,13 @@ function onResourceUpdated(params) {
|
|
|
99
101
|
typeOf: params.typeOf
|
|
100
102
|
})(repos);
|
|
101
103
|
break;
|
|
104
|
+
case 'POS':
|
|
105
|
+
yield (0, onHasPOSUpdated_1.createInformHasPOSTasks)({
|
|
106
|
+
project: { id: params.project.id },
|
|
107
|
+
ids: [params.operator.id],
|
|
108
|
+
typeOf: factory.placeType.MovieTheater
|
|
109
|
+
})(repos);
|
|
110
|
+
break;
|
|
102
111
|
default:
|
|
103
112
|
// no op
|
|
104
113
|
}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
12
|
+
"@chevre/factory": "4.334.0",
|
|
13
13
|
"@cinerino/sdk": "3.170.0",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
@@ -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.11.0
|
|
120
|
+
"version": "21.11.0"
|
|
121
121
|
}
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
// const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
-
|
|
10
|
-
// tslint:disable-next-line:max-func-body-length
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
-
|
|
14
|
-
const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = placeRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
// 'project.id': { $eq: project.id },
|
|
19
|
-
// 'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
20
|
-
typeOf: {
|
|
21
|
-
$in: [
|
|
22
|
-
chevre.factory.placeType.ScreeningRoom
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
// organizer: { $exists: false }
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
containsPlace: 0
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
console.log('places found');
|
|
32
|
-
|
|
33
|
-
let i = 0;
|
|
34
|
-
let updateCount = 0;
|
|
35
|
-
await cursor.eachAsync(async (doc) => {
|
|
36
|
-
i += 1;
|
|
37
|
-
const screeningRoom: chevre.factory.place.screeningRoom.IPlace = doc.toObject();
|
|
38
|
-
console.log(screeningRoom);
|
|
39
|
-
|
|
40
|
-
const organizerId = screeningRoom.parentOrganization?.id;
|
|
41
|
-
const alreadyMigrated = typeof organizerId === 'string';
|
|
42
|
-
|
|
43
|
-
if (alreadyMigrated) {
|
|
44
|
-
console.log('already exist...', screeningRoom.project.id, screeningRoom.branchCode, organizerId, i);
|
|
45
|
-
} else {
|
|
46
|
-
const movieTheaterId = screeningRoom.containedInPlace?.id;
|
|
47
|
-
if (typeof movieTheaterId !== 'string') {
|
|
48
|
-
throw new Error('containedInPlace?.id undefined');
|
|
49
|
-
}
|
|
50
|
-
const movieTheaters = <Pick<chevre.factory.place.movieTheater.IPlaceWithoutScreeningRoom, 'parentOrganization'>[]>
|
|
51
|
-
await placeRepo.searchMovieTheaters(
|
|
52
|
-
{
|
|
53
|
-
limit: 1,
|
|
54
|
-
page: 1,
|
|
55
|
-
project: { id: { $eq: screeningRoom.project.id } },
|
|
56
|
-
id: { $eq: movieTheaterId }
|
|
57
|
-
},
|
|
58
|
-
['parentOrganization'],
|
|
59
|
-
[]
|
|
60
|
-
);
|
|
61
|
-
const movieTheater = movieTheaters.shift();
|
|
62
|
-
const sellerId = movieTheater?.parentOrganization?.id;
|
|
63
|
-
console.log('movieTheater found', screeningRoom.project.id, screeningRoom.branchCode, 'sellerId:', sellerId, i);
|
|
64
|
-
// if (typeof sellerId !== 'string') {
|
|
65
|
-
// throw new Error('movieTheater not found');
|
|
66
|
-
// }
|
|
67
|
-
if (typeof sellerId === 'string') {
|
|
68
|
-
const newParentOrganization: chevre.factory.place.screeningRoom.IParentOrganization = {
|
|
69
|
-
id: sellerId,
|
|
70
|
-
typeOf: chevre.factory.organizationType.Corporation
|
|
71
|
-
};
|
|
72
|
-
console.log('updating room...', screeningRoom.project.id, screeningRoom.branchCode, i);
|
|
73
|
-
await placeRepo.addParentOrganization2ScreeningRoom({
|
|
74
|
-
project: screeningRoom.project,
|
|
75
|
-
branchCode: screeningRoom.branchCode,
|
|
76
|
-
containedInPlace: { branchCode: String(screeningRoom.containedInPlace?.branchCode) },
|
|
77
|
-
parentOrganization: newParentOrganization
|
|
78
|
-
});
|
|
79
|
-
updateCount += 1;
|
|
80
|
-
console.log('updated.', screeningRoom.project.id, screeningRoom.branchCode, i);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
console.log(i, 'rooms checked');
|
|
86
|
-
console.log(updateCount, 'rooms updated');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
main()
|
|
90
|
-
.then()
|
|
91
|
-
.catch(console.error);
|