added totalUserDeep
This commit is contained in:
@@ -25,6 +25,38 @@ export const adminRoute = router({
|
||||
});
|
||||
return summary;
|
||||
}),
|
||||
totalUserDeep: publicProcedure.query(async () => {
|
||||
const users = await db
|
||||
.select({
|
||||
zone: user.zone,
|
||||
cid: user.cid,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
})
|
||||
.from(user)
|
||||
.execute();
|
||||
const zones = await db.query.zone
|
||||
.findMany({ with: { province: true } })
|
||||
.execute();
|
||||
zones.sort((a, b) => a.province.id - b.province.id);
|
||||
let rs = [];
|
||||
for (const zone of zones) {
|
||||
const zoneUser = users.filter((u) => u.zone == zone.id);
|
||||
if (zoneUser.length == 0) continue;
|
||||
const total = zoneUser.length;
|
||||
const userDescription = zoneUser.reduce(
|
||||
(acc, n) => acc + `${n.firstName} ${n.lastName}: ${n.cid}\n`,
|
||||
"",
|
||||
);
|
||||
rs.push({
|
||||
province: zone.province.name,
|
||||
zone: zone.name,
|
||||
total,
|
||||
users: userDescription,
|
||||
});
|
||||
}
|
||||
return rs;
|
||||
}),
|
||||
|
||||
removeUser: publicProcedure
|
||||
.input(z.object({ cid: z.string(), key: z.string() }))
|
||||
|
||||
Reference in New Issue
Block a user