added info route

This commit is contained in:
2024-04-19 18:18:20 +07:00
parent 6e58e17be1
commit 28f053e91b
2 changed files with 32 additions and 0 deletions

30
src/infoRoute.ts Normal file
View File

@@ -0,0 +1,30 @@
import { router, publicProcedure } from "./trpc";
import { db } from "./db";
import { z } from "zod";
export const infoRoute = router({
getAllProvinces: publicProcedure.query(getProvinces),
getAllGroups: publicProcedure.query(getGroups),
getAllZones: publicProcedure
.input(z.object({ provice_id: z.number().optional() }))
.query(async ({ input }) => await getZone(input.provice_id)),
});
async function getProvinces() {
return await db.query.province.findMany();
}
async function getZone(province?: number) {
return await db.query.zone.findMany({
where: (zone, { and, eq }) => {
if (province === undefined) {
return and();
}
return eq(zone.province, province);
},
});
}
async function getGroups() {
return await db.query.group.findMany();
}