mirror of
https://github.com/fosrl/pangolin.git
synced 2025-07-07 12:34:52 +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 { 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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue