added info route
This commit is contained in:
@@ -3,9 +3,11 @@ import { createHTTPServer } from "@trpc/server/adapters/standalone";
|
||||
import { userRoute } from "./userRoute";
|
||||
import { runPlayground } from "./playgroud";
|
||||
import cors from "cors";
|
||||
import { infoRoute } from "./infoRoute";
|
||||
|
||||
export const appRouter = router({
|
||||
user: userRoute,
|
||||
info: infoRoute,
|
||||
});
|
||||
export type AppRouter = typeof appRouter;
|
||||
|
||||
|
||||
30
src/infoRoute.ts
Normal file
30
src/infoRoute.ts
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user