mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-02 09:05:49 +02:00
add org owner check to deleteOrg and removeUser endpoints
This commit is contained in:
parent
372e51c0a5
commit
458de04fcf
3 changed files with 94 additions and 1 deletions
|
@ -32,6 +32,25 @@ export async function removeUserOrg(
|
|||
|
||||
const { userId, orgId } = parsedParams.data;
|
||||
|
||||
// get the user first
|
||||
const user = await db
|
||||
.select()
|
||||
.from(userOrgs)
|
||||
.where(eq(userOrgs.userId, userId));
|
||||
|
||||
if (!user || user.length === 0) {
|
||||
return next(createHttpError(HttpCode.NOT_FOUND, "User not found"));
|
||||
}
|
||||
|
||||
if (user[0].isOwner) {
|
||||
return next(
|
||||
createHttpError(
|
||||
HttpCode.BAD_REQUEST,
|
||||
"Cannot remove owner from org"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// remove the user from the userOrgs table
|
||||
await db
|
||||
.delete(userOrgs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue