fix remove bug
All checks were successful
backend-action / build-image (push) Successful in 28s

This commit is contained in:
2024-05-20 14:11:50 +07:00
parent 64ea2e9524
commit 2a69ff0f3e
2 changed files with 13 additions and 36 deletions

View File

@@ -1,34 +1 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1713548458041,
"tag": "0000_right_nebula",
"breakpoints": true
},
{
"idx": 1,
"version": "5",
"when": 1713599233997,
"tag": "0001_chilly_bullseye",
"breakpoints": true
},
{
"idx": 2,
"version": "5",
"when": 1715319087385,
"tag": "0002_gigantic_sentry",
"breakpoints": true
},
{
"idx": 3,
"version": "5",
"when": 1715935487997,
"tag": "0003_overconfident_spencer_smythe",
"breakpoints": true
}
]
}
{"version":"5","dialect":"sqlite","entries":[{"idx":0,"version":"5","when":1713548458041,"tag":"0000_right_nebula","breakpoints":true},{"idx":1,"version":"5","when":1713599233997,"tag":"0001_chilly_bullseye","breakpoints":true},{"idx":2,"version":"5","when":1715319087385,"tag":"0002_gigantic_sentry","breakpoints":true},{"idx":3,"version":"5","when":1715935487997,"tag":"0003_overconfident_spencer_smythe","breakpoints":true}]}

View File

@@ -1,6 +1,6 @@
import { router, publicProcedure } from "./trpc";
import { db } from "./db";
import { user } from "./schema";
import { user, userOpinion } from "./schema";
import { count, eq } from "drizzle-orm";
import { z } from "zod";
@@ -29,7 +29,17 @@ export const adminRoute = router({
removeUser: publicProcedure
.input(z.object({ cid: z.string() }))
.mutation(async ({ input }) => {
let thisUser = await db.query.user
.findFirst({ where: eq(user.cid, input.cid) })
.execute();
if (thisUser === undefined) {
return "User not found";
}
let uoresult = await db
.delete(userOpinion)
.where(eq(userOpinion.userId, thisUser.id))
.execute();
let rs = await db.delete(user).where(eq(user.cid, input.cid)).execute();
return rs;
return { useropinion: uoresult, rs };
}),
});