@chevre/domain 22.13.0-alpha.10 → 22.13.0-alpha.12
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/migrateProjectSettings.ts +64 -0
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +2 -2
- package/lib/chevre/repo/event.js +17 -27
- package/lib/chevre/repo/project.d.ts +1 -1
- package/lib/chevre/repo/project.js +8 -5
- package/package.json +2 -2
- package/example/src/chevre/migrateProjectTokenIssuers.ts +0 -100
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// tslint:disable-next-line:max-func-body-length
|
|
7
|
+
async function main() {
|
|
8
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
+
|
|
10
|
+
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
11
|
+
|
|
12
|
+
const cursor = projectRepo.getCursor(
|
|
13
|
+
{
|
|
14
|
+
// _id: { $eq: 'cinerino' }
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
_id: 1,
|
|
18
|
+
settings: 1,
|
|
19
|
+
typeOf: 1
|
|
20
|
+
}
|
|
21
|
+
);
|
|
22
|
+
console.log('docs found');
|
|
23
|
+
|
|
24
|
+
let i = 0;
|
|
25
|
+
let updateCount = 0;
|
|
26
|
+
await cursor.eachAsync(async (doc) => {
|
|
27
|
+
i += 1;
|
|
28
|
+
const project: Pick<chevre.factory.project.IProject, 'id' | 'typeOf' | 'settings'> = doc.toObject();
|
|
29
|
+
|
|
30
|
+
console.log(
|
|
31
|
+
'alreadyMigrated?', project.id, i);
|
|
32
|
+
const includeCustomerAsFindByConfirmationNumberResult = project.settings?.includeCustomerAsFindByConfirmationNumberResult;
|
|
33
|
+
let alreadyMigrated = false;
|
|
34
|
+
if (typeof includeCustomerAsFindByConfirmationNumberResult === 'boolean') {
|
|
35
|
+
alreadyMigrated = true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (alreadyMigrated) {
|
|
39
|
+
console.log(
|
|
40
|
+
'already migrated.', project.id, i);
|
|
41
|
+
} else {
|
|
42
|
+
console.log(
|
|
43
|
+
'updating project...',
|
|
44
|
+
project.id, i);
|
|
45
|
+
await projectRepo.updateById({
|
|
46
|
+
id: project.id,
|
|
47
|
+
settings: {
|
|
48
|
+
includeCustomerAsFindByConfirmationNumberResult: true
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
updateCount += 1;
|
|
52
|
+
console.log(
|
|
53
|
+
'updated.',
|
|
54
|
+
project.id, i);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
console.log(i, 'docs checked');
|
|
59
|
+
console.log(updateCount, 'docs updated');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main()
|
|
63
|
+
.then()
|
|
64
|
+
.catch(console.error);
|
|
@@ -9,10 +9,10 @@ async function main() {
|
|
|
9
9
|
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
10
|
|
|
11
11
|
const roleNames = [
|
|
12
|
-
chevre.factory.role.organizationRole.RoleName.
|
|
12
|
+
chevre.factory.role.organizationRole.RoleName.AdminInventoryManager
|
|
13
13
|
];
|
|
14
14
|
const permissions = [
|
|
15
|
-
'
|
|
15
|
+
'admin.sellers.events.*'
|
|
16
16
|
];
|
|
17
17
|
for (const roleName of roleNames) {
|
|
18
18
|
for (const permission of permissions) {
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -43,7 +43,7 @@ class EventRepo {
|
|
|
43
43
|
}
|
|
44
44
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
45
45
|
static CREATE_MONGO_CONDITIONS(conditions) {
|
|
46
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27
|
|
46
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27;
|
|
47
47
|
const andConditions = [];
|
|
48
48
|
const typeOfEq = conditions.typeOf;
|
|
49
49
|
if (typeof typeOfEq === 'string') {
|
|
@@ -73,7 +73,7 @@ class EventRepo {
|
|
|
73
73
|
if (Array.isArray(idIn)) {
|
|
74
74
|
andConditions.push({ _id: { $in: idIn } });
|
|
75
75
|
}
|
|
76
|
-
const identifierIn =
|
|
76
|
+
const identifierIn = conditions.identifiers;
|
|
77
77
|
if (Array.isArray(identifierIn)) {
|
|
78
78
|
andConditions.push({ identifier: { $exists: true, $in: identifierIn } });
|
|
79
79
|
}
|
|
@@ -126,25 +126,15 @@ class EventRepo {
|
|
|
126
126
|
endDate: { $lte: conditions.endThrough }
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
const locationBranchCodeEq = (
|
|
129
|
+
const locationBranchCodeEq = (_h = (_g = conditions.location) === null || _g === void 0 ? void 0 : _g.branchCode) === null || _h === void 0 ? void 0 : _h.$eq;
|
|
130
130
|
if (typeof locationBranchCodeEq === 'string') {
|
|
131
131
|
andConditions.push({ 'location.branchCode': { $exists: true, $eq: locationBranchCodeEq } });
|
|
132
132
|
}
|
|
133
|
-
const locationBranchCodeIn = (
|
|
133
|
+
const locationBranchCodeIn = (_k = (_j = conditions.location) === null || _j === void 0 ? void 0 : _j.branchCode) === null || _k === void 0 ? void 0 : _k.$in;
|
|
134
134
|
if (Array.isArray(locationBranchCodeIn)) {
|
|
135
135
|
andConditions.push({ 'location.branchCode': { $exists: true, $in: locationBranchCodeIn } });
|
|
136
136
|
}
|
|
137
|
-
|
|
138
|
-
// const hasOfferCatalogIdEq = conditions.hasOfferCatalog?.id?.$eq;
|
|
139
|
-
// if (typeof hasOfferCatalogIdEq === 'string') {
|
|
140
|
-
// andConditions.push({
|
|
141
|
-
// 'hasOfferCatalog.id': {
|
|
142
|
-
// $exists: true,
|
|
143
|
-
// $eq: hasOfferCatalogIdEq
|
|
144
|
-
// }
|
|
145
|
-
// });
|
|
146
|
-
// }
|
|
147
|
-
const additionalPropertyElemMatch = (_m = conditions.additionalProperty) === null || _m === void 0 ? void 0 : _m.$elemMatch;
|
|
137
|
+
const additionalPropertyElemMatch = (_l = conditions.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
|
|
148
138
|
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
149
139
|
andConditions.push({
|
|
150
140
|
additionalProperty: {
|
|
@@ -160,7 +150,7 @@ class EventRepo {
|
|
|
160
150
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
161
151
|
/* istanbul ignore else */
|
|
162
152
|
if (params.offers !== undefined) {
|
|
163
|
-
const itemOfferedIdIn4event = (
|
|
153
|
+
const itemOfferedIdIn4event = (_o = (_m = params.offers.itemOffered) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$in;
|
|
164
154
|
if (Array.isArray(itemOfferedIdIn4event)) {
|
|
165
155
|
andConditions.push({
|
|
166
156
|
'offers.itemOffered.id': {
|
|
@@ -210,8 +200,8 @@ class EventRepo {
|
|
|
210
200
|
}
|
|
211
201
|
}
|
|
212
202
|
}
|
|
213
|
-
const sellerMakesOfferElemMatch4event = (
|
|
214
|
-
if (typeof ((
|
|
203
|
+
const sellerMakesOfferElemMatch4event = (_r = (_q = (_p = params.offers) === null || _p === void 0 ? void 0 : _p.seller) === null || _q === void 0 ? void 0 : _q.makesOffer) === null || _r === void 0 ? void 0 : _r.$elemMatch;
|
|
204
|
+
if (typeof ((_s = sellerMakesOfferElemMatch4event === null || sellerMakesOfferElemMatch4event === void 0 ? void 0 : sellerMakesOfferElemMatch4event['availableAtOrFrom.id']) === null || _s === void 0 ? void 0 : _s.$eq) === 'string') {
|
|
215
205
|
andConditions.push({
|
|
216
206
|
'offers.seller.makesOffer': {
|
|
217
207
|
$exists: true,
|
|
@@ -219,7 +209,7 @@ class EventRepo {
|
|
|
219
209
|
}
|
|
220
210
|
});
|
|
221
211
|
}
|
|
222
|
-
const reservationForIdentifierEq = (
|
|
212
|
+
const reservationForIdentifierEq = (_x = (_w = (_v = (_u = (_t = params.offers) === null || _t === void 0 ? void 0 : _t.itemOffered) === null || _u === void 0 ? void 0 : _u.serviceOutput) === null || _v === void 0 ? void 0 : _v.reservationFor) === null || _w === void 0 ? void 0 : _w.identifier) === null || _x === void 0 ? void 0 : _x.$eq;
|
|
223
213
|
if (typeof reservationForIdentifierEq === 'string') {
|
|
224
214
|
andConditions.push({
|
|
225
215
|
'offers.itemOffered.serviceOutput.reservationFor.identifier': {
|
|
@@ -228,7 +218,7 @@ class EventRepo {
|
|
|
228
218
|
}
|
|
229
219
|
});
|
|
230
220
|
}
|
|
231
|
-
const reservationForArrivalBusStopBranchCodeEq = (
|
|
221
|
+
const reservationForArrivalBusStopBranchCodeEq = (_3 = (_2 = (_1 = (_0 = (_z = (_y = params.offers) === null || _y === void 0 ? void 0 : _y.itemOffered) === null || _z === void 0 ? void 0 : _z.serviceOutput) === null || _0 === void 0 ? void 0 : _0.reservationFor) === null || _1 === void 0 ? void 0 : _1.arrivalBusStop) === null || _2 === void 0 ? void 0 : _2.branchCode) === null || _3 === void 0 ? void 0 : _3.$eq;
|
|
232
222
|
if (typeof reservationForArrivalBusStopBranchCodeEq === 'string') {
|
|
233
223
|
andConditions.push({
|
|
234
224
|
'offers.itemOffered.serviceOutput.reservationFor.arrivalBusStop.branchCode': {
|
|
@@ -237,7 +227,7 @@ class EventRepo {
|
|
|
237
227
|
}
|
|
238
228
|
});
|
|
239
229
|
}
|
|
240
|
-
const reservationForDepartureBusStopBranchCodeEq = (
|
|
230
|
+
const reservationForDepartureBusStopBranchCodeEq = (_9 = (_8 = (_7 = (_6 = (_5 = (_4 = params.offers) === null || _4 === void 0 ? void 0 : _4.itemOffered) === null || _5 === void 0 ? void 0 : _5.serviceOutput) === null || _6 === void 0 ? void 0 : _6.reservationFor) === null || _7 === void 0 ? void 0 : _7.departureBusStop) === null || _8 === void 0 ? void 0 : _8.branchCode) === null || _9 === void 0 ? void 0 : _9.$eq;
|
|
241
231
|
if (typeof reservationForDepartureBusStopBranchCodeEq === 'string') {
|
|
242
232
|
andConditions.push({
|
|
243
233
|
'offers.itemOffered.serviceOutput.reservationFor.departureBusStop.branchCode': {
|
|
@@ -271,7 +261,7 @@ class EventRepo {
|
|
|
271
261
|
}
|
|
272
262
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
273
263
|
/* istanbul ignore else */
|
|
274
|
-
const superEventLocationIdEq = (
|
|
264
|
+
const superEventLocationIdEq = (_12 = (_11 = (_10 = params.superEvent) === null || _10 === void 0 ? void 0 : _10.location) === null || _11 === void 0 ? void 0 : _11.id) === null || _12 === void 0 ? void 0 : _12.$eq;
|
|
275
265
|
if (typeof superEventLocationIdEq === 'string') {
|
|
276
266
|
andConditions.push({
|
|
277
267
|
'superEvent.location.id': {
|
|
@@ -314,7 +304,7 @@ class EventRepo {
|
|
|
314
304
|
});
|
|
315
305
|
}
|
|
316
306
|
}
|
|
317
|
-
const itemOfferedIdIn = (
|
|
307
|
+
const itemOfferedIdIn = (_15 = (_14 = (_13 = params.offers) === null || _13 === void 0 ? void 0 : _13.itemOffered) === null || _14 === void 0 ? void 0 : _14.id) === null || _15 === void 0 ? void 0 : _15.$in;
|
|
318
308
|
if (Array.isArray(itemOfferedIdIn)) {
|
|
319
309
|
andConditions.push({
|
|
320
310
|
'offers.itemOffered.id': {
|
|
@@ -323,7 +313,7 @@ class EventRepo {
|
|
|
323
313
|
}
|
|
324
314
|
});
|
|
325
315
|
}
|
|
326
|
-
const itemOfferedTicketedSeatTypeOfIn = (
|
|
316
|
+
const itemOfferedTicketedSeatTypeOfIn = (_20 = (_19 = (_18 = (_17 = (_16 = params.offers) === null || _16 === void 0 ? void 0 : _16.itemOffered) === null || _17 === void 0 ? void 0 : _17.serviceOutput) === null || _18 === void 0 ? void 0 : _18.reservedTicket) === null || _19 === void 0 ? void 0 : _19.ticketedSeat) === null || _20 === void 0 ? void 0 : _20.typeOfs;
|
|
327
317
|
if (Array.isArray(itemOfferedTicketedSeatTypeOfIn)) {
|
|
328
318
|
andConditions.push({
|
|
329
319
|
'offers.itemOffered.serviceOutput.reservedTicket.ticketedSeat.typeOf': {
|
|
@@ -332,7 +322,7 @@ class EventRepo {
|
|
|
332
322
|
}
|
|
333
323
|
});
|
|
334
324
|
}
|
|
335
|
-
const itemOfferedServiceTypeIdIn = (
|
|
325
|
+
const itemOfferedServiceTypeIdIn = (_23 = (_22 = (_21 = params.offers) === null || _21 === void 0 ? void 0 : _21.itemOffered) === null || _22 === void 0 ? void 0 : _22.serviceType) === null || _23 === void 0 ? void 0 : _23.ids;
|
|
336
326
|
if (Array.isArray(itemOfferedServiceTypeIdIn)) {
|
|
337
327
|
andConditions.push({
|
|
338
328
|
'offers.itemOffered.serviceType.id': {
|
|
@@ -341,8 +331,8 @@ class EventRepo {
|
|
|
341
331
|
}
|
|
342
332
|
});
|
|
343
333
|
}
|
|
344
|
-
const sellerMakesOfferElemMatch = (
|
|
345
|
-
if (typeof ((
|
|
334
|
+
const sellerMakesOfferElemMatch = (_26 = (_25 = (_24 = params.offers) === null || _24 === void 0 ? void 0 : _24.seller) === null || _25 === void 0 ? void 0 : _25.makesOffer) === null || _26 === void 0 ? void 0 : _26.$elemMatch;
|
|
335
|
+
if (typeof ((_27 = sellerMakesOfferElemMatch === null || sellerMakesOfferElemMatch === void 0 ? void 0 : sellerMakesOfferElemMatch['availableAtOrFrom.id']) === null || _27 === void 0 ? void 0 : _27.$eq) === 'string') {
|
|
346
336
|
andConditions.push({
|
|
347
337
|
'offers.seller.makesOffer': {
|
|
348
338
|
$exists: true,
|
|
@@ -27,7 +27,7 @@ export declare class ProjectRepo {
|
|
|
27
27
|
logo?: string;
|
|
28
28
|
hasMerchantReturnPolicy?: Pick<factory.project.IHasMerchantReturnPolicy, 'sameAs' | 'identifier'>;
|
|
29
29
|
name?: string;
|
|
30
|
-
settings?: {
|
|
30
|
+
settings?: Pick<factory.project.ISettings, 'includeCustomerAsFindByConfirmationNumberResult'> & {
|
|
31
31
|
sendEmailMessage?: factory.project.ISendEmailMessageSettings;
|
|
32
32
|
sendgridApiKey?: string;
|
|
33
33
|
};
|
|
@@ -134,23 +134,26 @@ class ProjectRepo {
|
|
|
134
134
|
}
|
|
135
135
|
updateById(params) {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
var _a, _b, _c, _d, _e, _f;
|
|
137
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
138
138
|
let hasMerchantReturnPolicy;
|
|
139
139
|
if (typeof ((_a = params.hasMerchantReturnPolicy) === null || _a === void 0 ? void 0 : _a.sameAs) === 'string') {
|
|
140
140
|
hasMerchantReturnPolicy = Object.assign({ sameAs: params.hasMerchantReturnPolicy.sameAs, typeOf: 'MerchantReturnPolicy' }, (typeof params.hasMerchantReturnPolicy.identifier === 'string')
|
|
141
141
|
? { identifier: params.hasMerchantReturnPolicy.identifier } : undefined);
|
|
142
142
|
}
|
|
143
|
-
|
|
143
|
+
const includeCustomerAsFindByConfirmationNumberResult = (_b = params.settings) === null || _b === void 0 ? void 0 : _b.includeCustomerAsFindByConfirmationNumberResult;
|
|
144
|
+
yield this.projectModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (typeof params.alternateName === 'string' && params.alternateName.length > 0)
|
|
144
145
|
? { alternateName: params.alternateName }
|
|
145
|
-
: undefined), (typeof params.name === 'string' && params.name.length > 0) ? { name: params.name } : undefined), (typeof params.logo === 'string' && params.logo.length > 0) ? { logo: params.logo } : undefined), (typeof ((
|
|
146
|
+
: undefined), (typeof params.name === 'string' && params.name.length > 0) ? { name: params.name } : undefined), (typeof params.logo === 'string' && params.logo.length > 0) ? { logo: params.logo } : undefined), (typeof ((_e = (_d = (_c = params.settings) === null || _c === void 0 ? void 0 : _c.sendEmailMessage) === null || _d === void 0 ? void 0 : _d.sender) === null || _e === void 0 ? void 0 : _e.email) === 'string')
|
|
146
147
|
? {
|
|
147
148
|
'settings.sendEmailMessage': {
|
|
148
149
|
sender: { email: params.settings.sendEmailMessage.sender.email }
|
|
149
150
|
}
|
|
150
151
|
}
|
|
151
|
-
: undefined), (typeof ((
|
|
152
|
+
: undefined), (typeof ((_f = params.settings) === null || _f === void 0 ? void 0 : _f.sendgridApiKey) === 'string')
|
|
152
153
|
? { 'settings.sendgridApiKey': params.settings.sendgridApiKey }
|
|
153
|
-
: undefined), (typeof
|
|
154
|
+
: undefined), (typeof includeCustomerAsFindByConfirmationNumberResult === 'boolean')
|
|
155
|
+
? { 'settings.includeCustomerAsFindByConfirmationNumberResult': includeCustomerAsFindByConfirmationNumberResult }
|
|
156
|
+
: undefined), (typeof ((_g = params.subscription) === null || _g === void 0 ? void 0 : _g.useEventServiceAsProduct) === 'boolean')
|
|
154
157
|
? { 'subscription.useEventServiceAsProduct': params.subscription.useEventServiceAsProduct }
|
|
155
158
|
: undefined), (hasMerchantReturnPolicy !== undefined) ? { hasMerchantReturnPolicy } : undefined), { $unset: {
|
|
156
159
|
'settings.cognito': 1 // 廃止(2023-11-10~)
|
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": "4.398.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.398.0-alpha.7",
|
|
15
15
|
"@cinerino/sdk": "12.2.0",
|
|
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": "22.13.0-alpha.
|
|
118
|
+
"version": "22.13.0-alpha.12"
|
|
119
119
|
}
|
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
// tslint:disable-next-line:max-func-body-length
|
|
10
|
-
async function main() {
|
|
11
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
-
|
|
13
|
-
const identityProviderRepo = await chevre.repository.IdentityProvider.createInstance(mongoose.connection);
|
|
14
|
-
const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = projectRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
// _id: { $eq: 'cinerino' }
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
_id: 1,
|
|
22
|
-
settings: 1,
|
|
23
|
-
typeOf: 1
|
|
24
|
-
}
|
|
25
|
-
);
|
|
26
|
-
console.log('docs found');
|
|
27
|
-
|
|
28
|
-
let i = 0;
|
|
29
|
-
let updateCount = 0;
|
|
30
|
-
await cursor.eachAsync(async (doc) => {
|
|
31
|
-
i += 1;
|
|
32
|
-
const project: Pick<chevre.factory.project.IProject, 'id' | 'typeOf' | 'settings'> = doc.toObject();
|
|
33
|
-
|
|
34
|
-
console.log(
|
|
35
|
-
'alreadyMigrated?', project.id, i);
|
|
36
|
-
const tokenIssuers: string[] | undefined = (<any>project.settings).tokenIssuers;
|
|
37
|
-
let alreadyMigrated = false;
|
|
38
|
-
if (Array.isArray(tokenIssuers)) {
|
|
39
|
-
let existingProvidersCount = 0;
|
|
40
|
-
for (const tokenIssuer of tokenIssuers) {
|
|
41
|
-
const existingProviders = await identityProviderRepo.projectFields(
|
|
42
|
-
{
|
|
43
|
-
limit: 1,
|
|
44
|
-
page: 1,
|
|
45
|
-
project: { id: { $eq: project.id } },
|
|
46
|
-
identifier: { $eq: tokenIssuer }
|
|
47
|
-
},
|
|
48
|
-
['identifier']
|
|
49
|
-
);
|
|
50
|
-
existingProvidersCount += existingProviders.length;
|
|
51
|
-
}
|
|
52
|
-
if (existingProvidersCount === tokenIssuers.length) {
|
|
53
|
-
alreadyMigrated = true;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
alreadyMigrated = true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (alreadyMigrated) {
|
|
60
|
-
console.log(
|
|
61
|
-
'already migrated.', project.id, i);
|
|
62
|
-
} else {
|
|
63
|
-
if (Array.isArray(tokenIssuers)) {
|
|
64
|
-
const newProviders = tokenIssuers.map((tokenIssuer) => {
|
|
65
|
-
return {
|
|
66
|
-
identifier: tokenIssuer,
|
|
67
|
-
project: {
|
|
68
|
-
id: project.id,
|
|
69
|
-
typeOf: <chevre.factory.organizationType.Project>chevre.factory.organizationType.Project
|
|
70
|
-
},
|
|
71
|
-
typeOf: <chevre.factory.organizationType.Organization>chevre.factory.organizationType.Organization,
|
|
72
|
-
verified: true
|
|
73
|
-
};
|
|
74
|
-
});
|
|
75
|
-
console.log(
|
|
76
|
-
'updating project...',
|
|
77
|
-
project.id, i, newProviders.length, 'newProviders');
|
|
78
|
-
for (const newProvider of newProviders) {
|
|
79
|
-
console.log(
|
|
80
|
-
'updating project...',
|
|
81
|
-
project.id, i, newProvider);
|
|
82
|
-
// await identityProviderRepo.save({
|
|
83
|
-
// attributes: newProvider
|
|
84
|
-
// });
|
|
85
|
-
}
|
|
86
|
-
updateCount += 1;
|
|
87
|
-
console.log(
|
|
88
|
-
'updated.',
|
|
89
|
-
project.id, i);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
console.log(i, 'docs checked');
|
|
95
|
-
console.log(updateCount, 'docs updated');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
main()
|
|
99
|
-
.then()
|
|
100
|
-
.catch(console.error);
|