mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-05 10:16:41 +00:00
remove userResources and userSites when removing user from org
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { Request, Response, NextFunction } from "express";
|
import { Request, Response, NextFunction } from "express";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { db } from "@server/db";
|
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 { and, eq } from "drizzle-orm";
|
||||||
import response from "@server/utils/response";
|
import response from "@server/utils/response";
|
||||||
import HttpCode from "@server/types/HttpCode";
|
import HttpCode from "@server/types/HttpCode";
|
||||||
@@ -51,10 +51,19 @@ export async function removeUserOrg(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the user from the userOrgs table
|
await db.transaction(async (trx) => {
|
||||||
await db
|
await trx
|
||||||
.delete(userOrgs)
|
.delete(userOrgs)
|
||||||
.where(and(eq(userOrgs.userId, userId), eq(userOrgs.orgId, orgId)));
|
.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, {
|
return response(res, {
|
||||||
data: null,
|
data: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user