added sorvor admin page
Some checks failed
backend-admin-action / build-image (push) Failing after 8s
backend-action / build-image (push) Failing after 1m40s

This commit is contained in:
2024-05-20 16:48:06 +07:00
parent 98a65043c9
commit 23f37df217
14 changed files with 137 additions and 28 deletions

View File

@@ -6,17 +6,17 @@ import { z } from "zod";
export const adminRoute = router({
totalUser: publicProcedure.query(async () => {
let rs = await db
const rs = await db
.select({ zone: user.zone, value: count(user.id) })
.from(user)
.groupBy(user.zone)
.execute();
let zones = await db.query.zone
const zones = await db.query.zone
.findMany({ with: { province: true } })
.execute();
zones.sort((a, b) => a.province.id - b.province.id);
let summary = zones.map((z) => {
let num = rs.find((user) => user.zone == z.id)?.value ?? 0;
const summary = zones.map((z) => {
const num = rs.find((user) => user.zone == z.id)?.value ?? 0;
return {
count: num,
zone: z.name,
@@ -32,17 +32,17 @@ export const adminRoute = router({
if (input.key !== "3RJjV7Hseo2xiJoVta/x2AJIGw5EK+a5nAwtnAjw37U=") {
return "Invalid Key";
}
let thisUser = await db.query.user
const thisUser = await db.query.user
.findFirst({ where: eq(user.cid, input.cid) })
.execute();
if (thisUser === undefined) {
return "User not found";
}
let uoresult = await db
const 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();
const rs = await db.delete(user).where(eq(user.cid, input.cid)).execute();
return { useropinion: uoresult, rs };
}),
});