mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-06 10:46:38 +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 { usageService } from "@server/lib/billing/usageService";
|
||||||
import { FeatureId } from "@server/lib/billing";
|
import { FeatureId } from "@server/lib/billing";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import { calculateUserClientsForOrgs } from "@server/lib/calculateUserClientsForOrgs";
|
||||||
|
|
||||||
const createOrgSchema = z.strictObject({
|
const createOrgSchema = z.strictObject({
|
||||||
orgId: z.string(),
|
orgId: z.string(),
|
||||||
@@ -194,6 +195,7 @@ export async function createOrg(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ownerUserId: string | null = null;
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
await trx.insert(userOrgs).values({
|
await trx.insert(userOrgs).values({
|
||||||
userId: req.user!.userId,
|
userId: req.user!.userId,
|
||||||
@@ -201,6 +203,7 @@ export async function createOrg(
|
|||||||
roleId: roleId,
|
roleId: roleId,
|
||||||
isOwner: true
|
isOwner: true
|
||||||
});
|
});
|
||||||
|
ownerUserId = req.user!.userId;
|
||||||
} else {
|
} else {
|
||||||
// if org created by root api key, set the server admin as the owner
|
// if org created by root api key, set the server admin as the owner
|
||||||
const [serverAdmin] = await trx
|
const [serverAdmin] = await trx
|
||||||
@@ -220,6 +223,7 @@ export async function createOrg(
|
|||||||
roleId: roleId,
|
roleId: roleId,
|
||||||
isOwner: true
|
isOwner: true
|
||||||
});
|
});
|
||||||
|
ownerUserId = serverAdmin.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberRole = await trx
|
const memberRole = await trx
|
||||||
@@ -238,6 +242,8 @@ export async function createOrg(
|
|||||||
orgId
|
orgId
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await calculateUserClientsForOrgs(ownerUserId, trx);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!org) {
|
if (!org) {
|
||||||
|
|||||||
Reference in New Issue
Block a user