added sorvor admin page
This commit is contained in:
@@ -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 };
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user