@chevre/domain 20.1.0-alpha.22 → 20.1.0-alpha.24
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/migrateCreativeWorkAdditionalProperties.ts +91 -0
- package/lib/chevre/repo/creativeWork.js +10 -1
- package/lib/chevre/repo/mongoose/model/creativeWork.js +6 -0
- package/lib/chevre/repo/mongoose/model/place.js +6 -0
- package/lib/chevre/repo/place.js +10 -1
- package/package.json +4 -4
|
@@ -0,0 +1,91 @@
|
|
|
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);
|
|
13
|
+
|
|
14
|
+
const creativeWorkRepo = new chevre.repository.CreativeWork(mongoose.connection);
|
|
15
|
+
// const placeRepo = new chevre.repository.Place(mongoose.connection);
|
|
16
|
+
// const additionalPropertyRepo = new chevre.repository.AdditionalProperty(mongoose.connection);
|
|
17
|
+
|
|
18
|
+
const cursor = creativeWorkRepo.getCursor(
|
|
19
|
+
// const cursor = placeRepo.getCursor(
|
|
20
|
+
{
|
|
21
|
+
// 'project.id': { $eq: project.id },
|
|
22
|
+
'project.id': { $ne: EXCLUDED_PROJECT_ID }
|
|
23
|
+
// _id: { $eq: 'al6aff83w' }
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
// _id: 1,
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
console.log('creativeWorks found');
|
|
30
|
+
|
|
31
|
+
const additionalPropertyNames: string[] = [];
|
|
32
|
+
const projectIds: string[] = [];
|
|
33
|
+
|
|
34
|
+
let i = 0;
|
|
35
|
+
let updateCount = 0;
|
|
36
|
+
await cursor.eachAsync(async (doc) => {
|
|
37
|
+
i += 1;
|
|
38
|
+
const creativeWork: chevre.factory.creativeWork.movie.ICreativeWork = doc.toObject();
|
|
39
|
+
|
|
40
|
+
const additionalPropertyNamesOnEvent = creativeWork.additionalProperty?.map((p) => p.name);
|
|
41
|
+
if (Array.isArray(additionalPropertyNamesOnEvent) && additionalPropertyNamesOnEvent.length > 0) {
|
|
42
|
+
console.log(additionalPropertyNamesOnEvent.length, 'additionalPropertyNamesOnEvent found', creativeWork.project.id);
|
|
43
|
+
additionalPropertyNames.push(...additionalPropertyNamesOnEvent);
|
|
44
|
+
projectIds.push(creativeWork.project.id);
|
|
45
|
+
additionalPropertyNamesOnEvent.forEach((name) => {
|
|
46
|
+
if (!name.match(/^[a-zA-Z]*$/)) {
|
|
47
|
+
// throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
|
|
48
|
+
}
|
|
49
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
50
|
+
if (name.length < 5) {
|
|
51
|
+
// throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// for (const additionalPropertyNameOnEvent of additionalPropertyNamesOnEvent) {
|
|
56
|
+
// const existings = await additionalPropertyRepo.search({
|
|
57
|
+
// project: { id: { $eq: event.project.id } },
|
|
58
|
+
// limit: 1,
|
|
59
|
+
// page: 1,
|
|
60
|
+
// name: { $regex: `^${additionalPropertyNameOnEvent}$` }
|
|
61
|
+
// });
|
|
62
|
+
// if (existings.length > 0) {
|
|
63
|
+
// console.log('already existed', additionalPropertyNameOnEvent, event.id, event.project.id);
|
|
64
|
+
// } else {
|
|
65
|
+
// updateCount += 1;
|
|
66
|
+
// await additionalPropertyRepo.save({
|
|
67
|
+
// attributes: {
|
|
68
|
+
// project: event.project,
|
|
69
|
+
// typeOf: 'CategoryCode',
|
|
70
|
+
// codeValue: additionalPropertyNameOnEvent,
|
|
71
|
+
// inCodeSet: {
|
|
72
|
+
// typeOf: 'CategoryCodeSet',
|
|
73
|
+
// identifier: <any>event.typeOf
|
|
74
|
+
// },
|
|
75
|
+
// name: { ja: additionalPropertyNameOnEvent }
|
|
76
|
+
// }
|
|
77
|
+
// });
|
|
78
|
+
// console.log('created', additionalPropertyNameOnEvent, event.id, event.project.id);
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
console.log(i, 'events checked');
|
|
84
|
+
console.log(updateCount, 'events updated');
|
|
85
|
+
console.log([...new Set(additionalPropertyNames)]);
|
|
86
|
+
console.log([...new Set(projectIds)]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
main()
|
|
90
|
+
.then()
|
|
91
|
+
.catch(console.error);
|
|
@@ -33,7 +33,7 @@ class MongoRepository {
|
|
|
33
33
|
}
|
|
34
34
|
// tslint:disable-next-line:max-func-body-length
|
|
35
35
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
36
|
-
var _a, _b, _c, _d, _e;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f;
|
|
37
37
|
// MongoDB検索条件
|
|
38
38
|
const andConditions = [
|
|
39
39
|
{
|
|
@@ -155,6 +155,15 @@ class MongoRepository {
|
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
+
const additionalPropertyElemMatch = (_f = params.additionalProperty) === null || _f === void 0 ? void 0 : _f.$elemMatch;
|
|
159
|
+
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
160
|
+
andConditions.push({
|
|
161
|
+
additionalProperty: {
|
|
162
|
+
$exists: true,
|
|
163
|
+
$elemMatch: additionalPropertyElemMatch
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
158
167
|
return andConditions;
|
|
159
168
|
}
|
|
160
169
|
/**
|
|
@@ -111,6 +111,12 @@ schema.index({ 'distributor.codeValue': 1, identifier: 1 }, {
|
|
|
111
111
|
'distributor.codeValue': { $exists: true }
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
|
+
schema.index({ additionalProperty: 1, identifier: 1 }, {
|
|
115
|
+
name: 'searchByAdditionalProperty',
|
|
116
|
+
partialFilterExpression: {
|
|
117
|
+
additionalProperty: { $exists: true }
|
|
118
|
+
}
|
|
119
|
+
});
|
|
114
120
|
mongoose.model(modelName, schema)
|
|
115
121
|
.on('index',
|
|
116
122
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
@@ -107,6 +107,12 @@ schema.index({ 'containsPlace.containsPlace.containsPlace.branchCode': 1, branch
|
|
|
107
107
|
'containsPlace.containsPlace.containsPlace.branchCode': { $exists: true }
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
|
+
schema.index({ additionalProperty: 1, branchCode: 1 }, {
|
|
111
|
+
name: 'searchByAdditionalProperty',
|
|
112
|
+
partialFilterExpression: {
|
|
113
|
+
additionalProperty: { $exists: true }
|
|
114
|
+
}
|
|
115
|
+
});
|
|
110
116
|
mongoose.model(modelName, schema)
|
|
111
117
|
.on('index',
|
|
112
118
|
// tslint:disable-next-line:no-single-line-block-comment
|
package/lib/chevre/repo/place.js
CHANGED
|
@@ -33,7 +33,7 @@ class MongoRepository {
|
|
|
33
33
|
}
|
|
34
34
|
// tslint:disable-next-line:max-func-body-length
|
|
35
35
|
static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params) {
|
|
36
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
37
37
|
// MongoDB検索条件
|
|
38
38
|
const andConditions = [];
|
|
39
39
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
@@ -123,6 +123,15 @@ class MongoRepository {
|
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
const additionalPropertyElemMatch = (_j = params.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
|
|
127
|
+
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
128
|
+
andConditions.push({
|
|
129
|
+
additionalProperty: {
|
|
130
|
+
$exists: true,
|
|
131
|
+
$elemMatch: additionalPropertyElemMatch
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
126
135
|
return andConditions;
|
|
127
136
|
}
|
|
128
137
|
/**
|
package/package.json
CHANGED
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.279.0-alpha.
|
|
13
|
-
"@cinerino/sdk": "3.
|
|
12
|
+
"@chevre/factory": "4.279.0-alpha.3",
|
|
13
|
+
"@cinerino/sdk": "3.134.0-alpha.3",
|
|
14
14
|
"@motionpicture/coa-service": "9.2.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.2.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
17
|
-
"@surfrock/sdk": "1.
|
|
17
|
+
"@surfrock/sdk": "1.2.0-alpha.0",
|
|
18
18
|
"@waiter/domain": "5.1.0",
|
|
19
19
|
"JSONStream": "^1.3.5",
|
|
20
20
|
"aws-sdk": "^2.984.0",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"postversion": "git push origin --tags",
|
|
121
121
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
122
122
|
},
|
|
123
|
-
"version": "20.1.0-alpha.
|
|
123
|
+
"version": "20.1.0-alpha.24"
|
|
124
124
|
}
|