mirror of
https://github.com/fosrl/pangolin.git
synced 2026-01-28 22:00:51 +00:00
add owner devices to org on create org
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user