add owner devices to org on create org

This commit is contained in:
miloschwartz
2025-12-03 14:19:10 -05:00
parent 4af10c8108
commit 0032634004

View File

@@ -26,6 +26,7 @@ import { createCustomer } from "#dynamic/lib/billing";
import { usageService } from "@server/lib/billing/usageService";
import { FeatureId } from "@server/lib/billing";
import { build } from "@server/build";
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
const createOrgSchema = z.strictObject({
orgId: z.string(),
@@ -194,6 +195,7 @@ export async function createOrg(
);
}
let ownerUserId: string | null = null;
if (req.user) {
await trx.insert(userOrgs).values({
userId: req.user!.userId,
@@ -201,6 +203,7 @@ export async function createOrg(
roleId: roleId,
isOwner: true
});
ownerUserId = req.user!.userId;
} else {
// if org created by root api key, set the server admin as the owner
const [serverAdmin] = await trx
@@ -220,6 +223,7 @@ export async function createOrg(
roleId: roleId,
isOwner: true
});
ownerUserId = serverAdmin.userId;
}
const memberRole = await trx
@@ -238,6 +242,8 @@ export async function createOrg(
orgId
}))
);
await calculateUserClientsForOrgs(ownerUserId, trx);
});
if (!org) {