@chevre/domain 23.0.0-alpha.22 → 23.0.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/event/checkEventAdditionalPropertyUniqueness.ts +108 -0
- package/example/src/chevre/event/migrateEventAdditionalProperty2identifier.ts +112 -0
- package/lib/chevre/repo/event.d.ts +11 -0
- package/lib/chevre/repo/event.js +16 -0
- package/lib/chevre/repo/issuer.js +9 -5
- package/lib/chevre/service/offer/onEventChanged.js +26 -30
- package/package.json +2 -2
- package/example/src/chevre/event/migrateEventIdentifier4ttts.ts +0 -96
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
2
|
+
import { webcrypto } from 'crypto';
|
|
3
|
+
import * as moment from 'moment';
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
import { chevre } from '../../../../lib/index';
|
|
7
|
+
|
|
8
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
9
|
+
const PROPERTY_NAME = 'createId';
|
|
10
|
+
|
|
11
|
+
async function additionalProperty2identifier(raw: string) {
|
|
12
|
+
const data = new TextEncoder().encode(raw);
|
|
13
|
+
const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
|
|
14
|
+
const bytes = Array.from(new Uint8Array(hashBuffer));
|
|
15
|
+
|
|
16
|
+
// 0-9 + a-z の36文字セット
|
|
17
|
+
const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
18
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
19
|
+
const id = bytes.map((b) => chars[b % 36])
|
|
20
|
+
.join('');
|
|
21
|
+
|
|
22
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
23
|
+
return id.slice(0, 16);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const identifierMustMatch = /^[0-9a-zA-Z]+$/;
|
|
27
|
+
function validateIdentifier(identifier: string) {
|
|
28
|
+
if (!identifierMustMatch.test(identifier)) {
|
|
29
|
+
throw new Error(`not matched ${identifier}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (identifier.length < 8 || identifier.length > 32) {
|
|
33
|
+
throw new Error(`invalid length ${identifier}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// tslint:disable-next-line:max-func-body-length
|
|
38
|
+
async function main() {
|
|
39
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
40
|
+
|
|
41
|
+
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
42
|
+
|
|
43
|
+
const cursor = eventRepo.getCursor(
|
|
44
|
+
{
|
|
45
|
+
// _id: { $eq: '68f5d32176b5f6b689ff24a6' },
|
|
46
|
+
// 'project.id': { $eq: project.id },
|
|
47
|
+
'additionalProperty.name': { $exists: true, $eq: PROPERTY_NAME },
|
|
48
|
+
startDate: {
|
|
49
|
+
$gte: moment()
|
|
50
|
+
.add(-1, 'days')
|
|
51
|
+
.toDate()
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
_id: 1,
|
|
56
|
+
startDate: 1,
|
|
57
|
+
project: 1,
|
|
58
|
+
identifier: 1,
|
|
59
|
+
additionalProperty: 1,
|
|
60
|
+
typeOf: 1
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
console.log('events found');
|
|
64
|
+
|
|
65
|
+
let i = 0;
|
|
66
|
+
await cursor.eachAsync(async (doc) => {
|
|
67
|
+
i += 1;
|
|
68
|
+
const event: Pick<
|
|
69
|
+
chevre.factory.event.screeningEvent.IEvent,
|
|
70
|
+
'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
|
|
71
|
+
> = doc.toObject();
|
|
72
|
+
|
|
73
|
+
console.log(
|
|
74
|
+
'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
|
|
75
|
+
const eventIdentifier = event.identifier;
|
|
76
|
+
const additionalPropertyValue = event.additionalProperty?.find(({ name }) => name === PROPERTY_NAME)?.value;
|
|
77
|
+
if (typeof additionalPropertyValue !== 'string') {
|
|
78
|
+
throw new Error('additionalPropertyValue not found');
|
|
79
|
+
}
|
|
80
|
+
const identifierMustBe = await additionalProperty2identifier(additionalPropertyValue);
|
|
81
|
+
validateIdentifier(identifierMustBe);
|
|
82
|
+
|
|
83
|
+
// const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier.length > 0;
|
|
84
|
+
// const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === identifierMustBe;
|
|
85
|
+
|
|
86
|
+
console.log(
|
|
87
|
+
'checking...',
|
|
88
|
+
identifierMustBe, event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
|
|
89
|
+
const existingEvents = await eventRepo.findByAdditionalProperty(
|
|
90
|
+
{
|
|
91
|
+
// limit: 2,
|
|
92
|
+
// page: 1,
|
|
93
|
+
project: { id: event.project.id },
|
|
94
|
+
additionalProperty: { name: PROPERTY_NAME, value: additionalPropertyValue }
|
|
95
|
+
}
|
|
96
|
+
);
|
|
97
|
+
console.log('existingEvents found.', existingEvents.length, existingEvents);
|
|
98
|
+
if (existingEvents.length !== 1 || existingEvents[0]._id !== event.id) {
|
|
99
|
+
throw new Error(`not unique! ${event.id} ${additionalPropertyValue}`);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
console.log(i, 'events checked');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
main()
|
|
107
|
+
.then()
|
|
108
|
+
.catch(console.error);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
2
|
+
import { webcrypto } from 'crypto';
|
|
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 PROPERTY_NAME = 'createId';
|
|
9
|
+
|
|
10
|
+
async function additionalProperty2identifier(raw: string) {
|
|
11
|
+
const data = new TextEncoder().encode(raw);
|
|
12
|
+
const hashBuffer = await webcrypto.subtle.digest('SHA-256', data);
|
|
13
|
+
const bytes = Array.from(new Uint8Array(hashBuffer));
|
|
14
|
+
|
|
15
|
+
// 0-9 + a-z の36文字セット
|
|
16
|
+
const chars = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
17
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
18
|
+
const id = bytes.map((b) => chars[b % 36])
|
|
19
|
+
.join('');
|
|
20
|
+
|
|
21
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
22
|
+
return id.slice(0, 16);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const identifierMustMatch = /^[0-9a-zA-Z]+$/;
|
|
26
|
+
function validateIdentifier(identifier: string) {
|
|
27
|
+
if (!identifierMustMatch.test(identifier)) {
|
|
28
|
+
throw new Error(`not matched ${identifier}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (identifier.length < 8 || identifier.length > 32) {
|
|
32
|
+
throw new Error(`invalid length ${identifier}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// tslint:disable-next-line:max-func-body-length
|
|
37
|
+
async function main() {
|
|
38
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
39
|
+
|
|
40
|
+
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
41
|
+
|
|
42
|
+
const cursor = eventRepo.getCursor(
|
|
43
|
+
{
|
|
44
|
+
// _id: { $eq: '68f5d32176b5f6b689ff24a6' },
|
|
45
|
+
'project.id': { $eq: project.id },
|
|
46
|
+
'additionalProperty.name': { $exists: true, $eq: PROPERTY_NAME }
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
_id: 1,
|
|
50
|
+
startDate: 1,
|
|
51
|
+
project: 1,
|
|
52
|
+
identifier: 1,
|
|
53
|
+
additionalProperty: 1,
|
|
54
|
+
typeOf: 1
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
console.log('events found');
|
|
58
|
+
|
|
59
|
+
let i = 0;
|
|
60
|
+
let updateCount = 0;
|
|
61
|
+
await cursor.eachAsync(async (doc) => {
|
|
62
|
+
i += 1;
|
|
63
|
+
const event: Pick<
|
|
64
|
+
chevre.factory.event.screeningEvent.IEvent,
|
|
65
|
+
'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
|
|
66
|
+
> = doc.toObject();
|
|
67
|
+
|
|
68
|
+
console.log(
|
|
69
|
+
'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
|
|
70
|
+
const eventIdentifier = event.identifier;
|
|
71
|
+
const additionalPropertyValue = event.additionalProperty?.find(({ name }) => name === PROPERTY_NAME)?.value;
|
|
72
|
+
if (typeof additionalPropertyValue !== 'string') {
|
|
73
|
+
throw new Error('additionalPropertyValue not found');
|
|
74
|
+
}
|
|
75
|
+
const identifierMustBe = await additionalProperty2identifier(additionalPropertyValue);
|
|
76
|
+
validateIdentifier(identifierMustBe);
|
|
77
|
+
|
|
78
|
+
const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier.length > 0;
|
|
79
|
+
// const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === identifierMustBe;
|
|
80
|
+
|
|
81
|
+
if (alreadyMigrated) {
|
|
82
|
+
validateIdentifier(eventIdentifier);
|
|
83
|
+
console.log(
|
|
84
|
+
'already migrated.', event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
|
|
85
|
+
} else {
|
|
86
|
+
console.log(
|
|
87
|
+
'updating...',
|
|
88
|
+
identifierMustBe, event.project.id, eventIdentifier, additionalPropertyValue, event.id, event.startDate, i);
|
|
89
|
+
await eventRepo.updatePartiallyById({
|
|
90
|
+
project: { id: event.project.id },
|
|
91
|
+
id: event.id,
|
|
92
|
+
attributes: {
|
|
93
|
+
typeOf: event.typeOf,
|
|
94
|
+
...{
|
|
95
|
+
identifier: identifierMustBe
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
updateCount += 1;
|
|
100
|
+
console.log(
|
|
101
|
+
'updated.',
|
|
102
|
+
event.project.id, eventIdentifier, event.id, event.startDate, i);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
console.log(i, 'events checked');
|
|
107
|
+
console.log(updateCount, 'events updated');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
main()
|
|
111
|
+
.then()
|
|
112
|
+
.catch(console.error);
|
|
@@ -173,6 +173,17 @@ export declare class EventRepo {
|
|
|
173
173
|
* イベントを検索する(inclusion projection)
|
|
174
174
|
*/
|
|
175
175
|
projectEventFields(params: ISearchConditions, inclusion: IKeyOfProjection[]): Promise<Omit<factory.event.screeningEvent.IEvent, 'aggregateOffer'>[]>;
|
|
176
|
+
findByAdditionalProperty(params: {
|
|
177
|
+
project: {
|
|
178
|
+
id: string;
|
|
179
|
+
};
|
|
180
|
+
additionalProperty: factory.propertyValue.IPropertyValue<string>;
|
|
181
|
+
}): Promise<(import("mongoose").FlattenMaps<import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
182
|
+
_id: string;
|
|
183
|
+
aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
|
|
184
|
+
}> & Required<{
|
|
185
|
+
_id: string;
|
|
186
|
+
}>)[]>;
|
|
176
187
|
/**
|
|
177
188
|
* apiで公開属性を検索する(2024-10-13~)
|
|
178
189
|
*/
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -655,6 +655,22 @@ class EventRepo {
|
|
|
655
655
|
.exec();
|
|
656
656
|
});
|
|
657
657
|
}
|
|
658
|
+
findByAdditionalProperty(params) {
|
|
659
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
660
|
+
const query = this.eventModel.find({
|
|
661
|
+
'project.id': { $eq: params.project.id },
|
|
662
|
+
additionalProperty: { $eq: params.additionalProperty }
|
|
663
|
+
}, { _id: 1 });
|
|
664
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
665
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
666
|
+
// query.limit(params.limit)
|
|
667
|
+
// .skip(params.limit * (page - 1));
|
|
668
|
+
// }
|
|
669
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
670
|
+
.lean()
|
|
671
|
+
.exec();
|
|
672
|
+
});
|
|
673
|
+
}
|
|
658
674
|
/**
|
|
659
675
|
* apiで公開属性を検索する(2024-10-13~)
|
|
660
676
|
*/
|
|
@@ -32,17 +32,21 @@ class IssuerRepo {
|
|
|
32
32
|
this.issuerModel = connection.model(issuer_1.modelName, (0, issuer_1.createSchema)());
|
|
33
33
|
}
|
|
34
34
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
35
|
-
var _a, _b, _c, _d;
|
|
35
|
+
var _a, _b, _c, _d, _e;
|
|
36
36
|
const andConditions = [];
|
|
37
37
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
38
38
|
if (typeof projectIdEq === 'string') {
|
|
39
39
|
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
40
40
|
}
|
|
41
|
-
const
|
|
42
|
-
if (typeof
|
|
43
|
-
andConditions.push({ identifier: { $eq:
|
|
41
|
+
const identifierEq = (_c = params.identifier) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
42
|
+
if (typeof identifierEq === 'string') {
|
|
43
|
+
andConditions.push({ identifier: { $eq: identifierEq } });
|
|
44
44
|
}
|
|
45
|
-
const
|
|
45
|
+
const identifierIn = (_d = params.identifier) === null || _d === void 0 ? void 0 : _d.$in;
|
|
46
|
+
if (Array.isArray(identifierIn)) {
|
|
47
|
+
andConditions.push({ identifier: { $in: identifierIn } });
|
|
48
|
+
}
|
|
49
|
+
const idEq = (_e = params.id) === null || _e === void 0 ? void 0 : _e.$eq;
|
|
46
50
|
if (typeof idEq === 'string') {
|
|
47
51
|
andConditions.push({ _id: { $eq: idEq } });
|
|
48
52
|
}
|
|
@@ -111,41 +111,37 @@ function createInformTasks(params, setting) {
|
|
|
111
111
|
typeOf: params.typeOf
|
|
112
112
|
}, [
|
|
113
113
|
'project', 'organizer', 'typeOf', 'name', 'doorTime', 'endDate',
|
|
114
|
-
'eventStatus', 'location', 'startDate', 'superEvent', 'offers', 'additionalProperty'
|
|
114
|
+
'eventStatus', 'location', 'startDate', 'superEvent', 'offers', 'additionalProperty', 'identifier'
|
|
115
115
|
] // inclusion(2024-07-30~)
|
|
116
116
|
);
|
|
117
117
|
// 最適化(2024-03-22~)
|
|
118
|
-
events4inform = screeningEvents4inform.map(({ project, organizer, typeOf, name, doorTime, endDate, eventStatus, location, startDate, superEvent, offers, id, additionalProperty }) => {
|
|
118
|
+
events4inform = screeningEvents4inform.map(({ project, organizer, typeOf, name, doorTime, endDate, eventStatus, location, startDate, superEvent, offers, id, additionalProperty, identifier }) => {
|
|
119
119
|
var _a;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
const eventOfferAsNotification = (((_a = offers.offeredThrough) === null || _a === void 0 ? void 0 : _a.identifier) === factory.service.webAPI.Identifier.COA)
|
|
121
|
+
? {
|
|
122
|
+
typeOf: offers.typeOf,
|
|
123
|
+
itemOffered: offers.itemOffered
|
|
124
|
+
}
|
|
125
|
+
: {
|
|
126
|
+
typeOf: offers.typeOf,
|
|
127
|
+
itemOffered: offers.itemOffered,
|
|
128
|
+
seller: {
|
|
129
|
+
id: offers.seller.id,
|
|
130
|
+
typeOf: offers.seller.typeOf,
|
|
131
|
+
// makesOfferを追加(2024-03-26~)
|
|
132
|
+
makesOffer: (Array.isArray(offers.seller.makesOffer))
|
|
133
|
+
? offers.seller.makesOffer.map((eventSellerMakesOffer) => {
|
|
134
|
+
return Object.assign({ availabilityEnds: eventSellerMakesOffer.availabilityEnds, availabilityStarts: eventSellerMakesOffer.availabilityStarts, validFrom: eventSellerMakesOffer.validFrom, validThrough: eventSellerMakesOffer.validThrough, availableAtOrFrom: [eventSellerMakesOffer.availableAtOrFrom] }, (typeof eventSellerMakesOffer.identifier === 'string')
|
|
135
|
+
? { identifier: eventSellerMakesOffer.identifier }
|
|
136
|
+
: undefined // support notify identifier(2025-11-01~)
|
|
137
|
+
);
|
|
138
|
+
})
|
|
139
|
+
: []
|
|
127
140
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
id: offers.seller.id,
|
|
133
|
-
typeOf: offers.seller.typeOf,
|
|
134
|
-
// makesOfferを追加(2024-03-26~)
|
|
135
|
-
makesOffer: (Array.isArray(offers.seller.makesOffer))
|
|
136
|
-
? offers.seller.makesOffer.map(({ availabilityEnds, availabilityStarts, availableAtOrFrom, validFrom, validThrough }) => {
|
|
137
|
-
// support availableAtOrFrom as non-array(2024-10-13~)
|
|
138
|
-
const availableAtOrFrom4inform = (Array.isArray(availableAtOrFrom))
|
|
139
|
-
? availableAtOrFrom
|
|
140
|
-
: (typeof (availableAtOrFrom === null || availableAtOrFrom === void 0 ? void 0 : availableAtOrFrom.id) === 'string') ? [availableAtOrFrom] : undefined;
|
|
141
|
-
return Object.assign({ availabilityEnds, availabilityStarts, validFrom, validThrough }, (Array.isArray(availableAtOrFrom4inform))
|
|
142
|
-
? { availableAtOrFrom: availableAtOrFrom4inform }
|
|
143
|
-
: undefined);
|
|
144
|
-
})
|
|
145
|
-
: []
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
141
|
+
};
|
|
142
|
+
return Object.assign({ project, organizer, typeOf, name, doorTime, endDate,
|
|
143
|
+
eventStatus, location, startDate, superEvent, id, additionalProperty, offers: eventOfferAsNotification }, (typeof identifier === 'string') ? { identifier } : undefined // support notify identifier(2025-11-01~)
|
|
144
|
+
);
|
|
149
145
|
});
|
|
150
146
|
}
|
|
151
147
|
else {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "5.2.0-alpha.
|
|
14
|
+
"@chevre/factory": "5.2.0-alpha.2",
|
|
15
15
|
"@cinerino/sdk": "12.6.0-alpha.5",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.4.0-alpha.1",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "23.0.0-alpha.
|
|
118
|
+
"version": "23.0.0-alpha.24"
|
|
119
119
|
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console no-magic-numbers
|
|
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
|
-
// tslint:disable-next-line:max-func-body-length
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const cursor = eventRepo.getCursor(
|
|
15
|
-
{
|
|
16
|
-
// _id: { $eq: 'blwz44d0k' },
|
|
17
|
-
'project.id': { $eq: project.id }
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
_id: 1,
|
|
21
|
-
startDate: 1,
|
|
22
|
-
project: 1,
|
|
23
|
-
identifier: 1,
|
|
24
|
-
additionalProperty: 1,
|
|
25
|
-
typeOf: 1
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
console.log('events found');
|
|
29
|
-
|
|
30
|
-
let i = 0;
|
|
31
|
-
let updateCount = 0;
|
|
32
|
-
await cursor.eachAsync(async (doc) => {
|
|
33
|
-
i += 1;
|
|
34
|
-
const event: Pick<
|
|
35
|
-
chevre.factory.event.screeningEvent.IEvent,
|
|
36
|
-
'id' | 'identifier' | 'startDate' | 'project' | 'additionalProperty' | 'typeOf'
|
|
37
|
-
> = doc.toObject();
|
|
38
|
-
|
|
39
|
-
console.log(
|
|
40
|
-
'alreadyMigrated?', event.project.id, event.id, event.startDate, i);
|
|
41
|
-
const isValidProject = event.project.id.substring(0, 5) === 'ttts-';
|
|
42
|
-
if (!isValidProject) {
|
|
43
|
-
throw new Error(`${event.project.id} ${event.id} invalid project.`);
|
|
44
|
-
}
|
|
45
|
-
const eventIdentifier = event.identifier;
|
|
46
|
-
const oldEventId = event.additionalProperty?.find(({ name }) => name === 'oldEventId')?.value;
|
|
47
|
-
const tourNumber = event.additionalProperty?.find(({ name }) => name === 'tourNumber')?.value;
|
|
48
|
-
if (typeof oldEventId !== 'string' || oldEventId === '') {
|
|
49
|
-
throw new Error(`${event.project.id} ${event.id} oldEventId required: ${oldEventId}`);
|
|
50
|
-
}
|
|
51
|
-
if (typeof tourNumber !== 'string' || tourNumber === '') {
|
|
52
|
-
throw new Error(`${event.project.id} ${event.id} tourNumber required: ${tourNumber}`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const alreadyMigrated = typeof eventIdentifier === 'string' && eventIdentifier === oldEventId;
|
|
56
|
-
|
|
57
|
-
if (alreadyMigrated) {
|
|
58
|
-
console.log(
|
|
59
|
-
'already migrated.', event.project.id, event.id, event.startDate, i);
|
|
60
|
-
} else {
|
|
61
|
-
console.log(
|
|
62
|
-
'updating... oldEventId:',
|
|
63
|
-
oldEventId, event.project.id, event.id, event.startDate, i);
|
|
64
|
-
await eventRepo.updatePartiallyById({
|
|
65
|
-
project: { id: event.project.id },
|
|
66
|
-
id: event.id,
|
|
67
|
-
attributes: {
|
|
68
|
-
typeOf: event.typeOf,
|
|
69
|
-
...{
|
|
70
|
-
identifier: oldEventId
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
updateCount += 1;
|
|
75
|
-
console.log(
|
|
76
|
-
'updated.',
|
|
77
|
-
event.project.id, event.id, event.startDate, i);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
console.log(i, 'events checked');
|
|
82
|
-
console.log(updateCount, 'events updated');
|
|
83
|
-
|
|
84
|
-
// await eventRepo.projectEventFields<chevre.factory.eventType.ScreeningEvent>(
|
|
85
|
-
// {
|
|
86
|
-
// project: { id: { $eq: project.id } },
|
|
87
|
-
// typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
88
|
-
// // id
|
|
89
|
-
// },
|
|
90
|
-
// ['identifier']
|
|
91
|
-
// );
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
main()
|
|
95
|
-
.then()
|
|
96
|
-
.catch(console.error);
|