@chevre/domain 21.2.0-alpha.114 → 21.2.0-alpha.115
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,79 @@
|
|
|
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 = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = eventRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'project.id': {
|
|
19
|
+
// $eq: project.id,
|
|
20
|
+
$ne: EXCLUDED_PROJECT_ID
|
|
21
|
+
},
|
|
22
|
+
typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries },
|
|
23
|
+
'workPerformed.version': { $exists: false }
|
|
24
|
+
// _id: { $eq: 'bl7ed6sq9' }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
_id: 1,
|
|
28
|
+
workPerformed: 1,
|
|
29
|
+
project: 1,
|
|
30
|
+
location: 1,
|
|
31
|
+
startDate: 1,
|
|
32
|
+
typeOf: 1
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
console.log('events found');
|
|
36
|
+
|
|
37
|
+
let i = 0;
|
|
38
|
+
let updateCount = 0;
|
|
39
|
+
await cursor.eachAsync(async (doc) => {
|
|
40
|
+
i += 1;
|
|
41
|
+
const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
|
|
42
|
+
const version = event.workPerformed.version;
|
|
43
|
+
|
|
44
|
+
const alreadyMigrated = typeof version === 'string' && version.length > 0;
|
|
45
|
+
|
|
46
|
+
if (alreadyMigrated) {
|
|
47
|
+
console.log('alreadyMigrated.', event.project.id, event.id, event.startDate, version, i);
|
|
48
|
+
} else {
|
|
49
|
+
// 既存施設コンテンツバージョンを検索
|
|
50
|
+
const { maxVersion } = await eventRepo.aggregateScreeningEventMaxVersion({
|
|
51
|
+
project: { id: { $eq: event.project.id } },
|
|
52
|
+
workPerformed: { identifier: { $eq: event.workPerformed.identifier } },
|
|
53
|
+
location: { branchCode: { $in: [event.location.branchCode] } }
|
|
54
|
+
});
|
|
55
|
+
console.log('maxVersion:', maxVersion);
|
|
56
|
+
|
|
57
|
+
const newVersion: string = `${Number(maxVersion) + 1}`;
|
|
58
|
+
console.log('updating event...', event.project.id, event.id, event.startDate, newVersion, i);
|
|
59
|
+
await eventRepo.updatePartiallyById({
|
|
60
|
+
id: event.id,
|
|
61
|
+
attributes: <any>{
|
|
62
|
+
typeOf: event.typeOf,
|
|
63
|
+
'workPerformed.version': newVersion
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
updateCount += 1;
|
|
67
|
+
console.log('updated.', event.project.id, event.id, event.startDate, newVersion, i);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
console.log(i, 'events checked');
|
|
72
|
+
console.log(updateCount, 'events updated');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
main()
|
|
76
|
+
.then(() => {
|
|
77
|
+
console.log('success!');
|
|
78
|
+
})
|
|
79
|
+
.catch(console.error);
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -850,19 +850,20 @@ class MongoRepository {
|
|
|
850
850
|
},
|
|
851
851
|
{
|
|
852
852
|
$project: {
|
|
853
|
-
workPerformed: '$workPerformed'
|
|
853
|
+
workPerformed: '$workPerformed',
|
|
854
|
+
version: { $toInt: '$workPerformed.version' }
|
|
854
855
|
}
|
|
855
856
|
},
|
|
856
857
|
{
|
|
857
858
|
$group: {
|
|
858
859
|
_id: '$typeOf',
|
|
859
|
-
maxVersion: { $max: '$
|
|
860
|
+
maxVersion: { $max: '$version' }
|
|
860
861
|
}
|
|
861
862
|
}
|
|
862
863
|
])
|
|
863
864
|
.exec();
|
|
864
865
|
const maxVersion = (aggregations.length > 0)
|
|
865
|
-
? (_a = aggregations.shift()) === null || _a === void 0 ? void 0 : _a.maxVersion
|
|
866
|
+
? String((_a = aggregations.shift()) === null || _a === void 0 ? void 0 : _a.maxVersion)
|
|
866
867
|
: '0';
|
|
867
868
|
return { maxVersion };
|
|
868
869
|
});
|
package/package.json
CHANGED
|
@@ -1,27 +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 = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const aggregation = await eventRepo.aggregateScreeningEventMaxVersion({
|
|
15
|
-
project: { id: { $eq: project.id } },
|
|
16
|
-
workPerformed: { identifier: { $eq: '00001' } },
|
|
17
|
-
location: { branchCode: { $in: ['118', '203'] } }
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
console.log('result:', aggregation);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
main()
|
|
24
|
-
.then(() => {
|
|
25
|
-
console.log('success!');
|
|
26
|
-
})
|
|
27
|
-
.catch(console.error);
|