@loomcore/api 0.2.38 → 0.2.39
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.
|
@@ -216,14 +216,15 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
216
216
|
const result = await db
|
|
217
217
|
.collection("organizations")
|
|
218
218
|
.insertOne(metaOrgDoc);
|
|
219
|
+
const metaOrgObjectId = result.insertedId;
|
|
219
220
|
const metaOrg = {
|
|
220
221
|
...metaOrgDoc,
|
|
221
|
-
_id:
|
|
222
|
+
_id: metaOrgObjectId.toString(),
|
|
222
223
|
};
|
|
223
224
|
const metaOrgDomains = dbConfig.multiTenant.metaOrgDomains ?? [];
|
|
224
225
|
if (metaOrgDomains.length > 0) {
|
|
225
226
|
await db.collection("organizationDomains").insertMany(metaOrgDomains.map((domain) => ({
|
|
226
|
-
organizationId:
|
|
227
|
+
organizationId: metaOrgObjectId,
|
|
227
228
|
domain,
|
|
228
229
|
_created: new Date(),
|
|
229
230
|
_createdBy: "system",
|
|
@@ -253,7 +254,7 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
253
254
|
}
|
|
254
255
|
const systemUserContext = getSystemUserContext();
|
|
255
256
|
const orgDoc = isMultiTenant && systemUserContext.organization?._id
|
|
256
|
-
? { _orgId: systemUserContext.organization._id }
|
|
257
|
+
? { _orgId: String(systemUserContext.organization._id) }
|
|
257
258
|
: {};
|
|
258
259
|
const hashedPassword = await passwordUtils.hashPassword(dbConfig.adminUser.password);
|
|
259
260
|
const email = dbConfig.adminUser.email.toLowerCase();
|
|
@@ -294,7 +295,9 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
294
295
|
if (!adminUser) {
|
|
295
296
|
throw new Error("Admin user not found. Ensure admin-user migration ran successfully.");
|
|
296
297
|
}
|
|
297
|
-
const orgDoc = isMultiTenant && metaOrg
|
|
298
|
+
const orgDoc = isMultiTenant && metaOrg?._id
|
|
299
|
+
? { _orgId: String(metaOrg._id) }
|
|
300
|
+
: {};
|
|
298
301
|
const roleResult = await db.collection("roles").insertOne({
|
|
299
302
|
...orgDoc,
|
|
300
303
|
name: "admin",
|
|
@@ -337,7 +340,9 @@ export const getMongoInitialSchema = (dbConfig) => {
|
|
|
337
340
|
: undefined;
|
|
338
341
|
if (isMultiTenant && !metaOrg)
|
|
339
342
|
return;
|
|
340
|
-
const orgFilter = isMultiTenant && metaOrg
|
|
343
|
+
const orgFilter = isMultiTenant && metaOrg?._id
|
|
344
|
+
? { _orgId: String(metaOrg._id) }
|
|
345
|
+
: {};
|
|
341
346
|
const adminRole = await db
|
|
342
347
|
.collection("roles")
|
|
343
348
|
.findOne({ ...orgFilter, name: "admin" });
|