mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-06 20:15:03 +02:00
remove userResources and userSites when removing user from org
This commit is contained in:
parent
587bb758a2
commit
b4442a3bf7
1 changed files with 14 additions and 5 deletions
|
@ -1,7 +1,7 @@
|
|||
import { Request, Response, NextFunction } from "express";
|
||||
import { z } from "zod";
|
||||
import { db } from "@server/db";
|
||||
import { userOrgs, users } from "@server/db/schema";
|
||||
import { userOrgs, userResources, users, userSites } from "@server/db/schema";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import response from "@server/utils/response";
|
||||
import HttpCode from "@server/types/HttpCode";
|
||||
|
@ -51,10 +51,19 @@ export async function removeUserOrg(
|
|||
);
|
||||
}
|
||||
|
||||
// remove the user from the userOrgs table
|
||||
await db
|
||||
.delete(userOrgs)
|
||||
.where(and(eq(userOrgs.userId, userId), eq(userOrgs.orgId, orgId)));
|
||||
await db.transaction(async (trx) => {
|
||||
await trx
|
||||
.delete(userOrgs)
|
||||
.where(
|
||||
and(eq(userOrgs.userId, userId), eq(userOrgs.orgId, orgId))
|
||||
);
|
||||
|
||||
await trx
|
||||
.delete(userResources)
|
||||
.where(eq(userResources.userId, userId));
|
||||
|
||||
await trx.delete(userSites).where(eq(userSites.userId, userId));
|
||||
});
|
||||
|
||||
return response(res, {
|
||||
data: null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue