diff --git a/src/server/api/routers/license.ts b/src/server/api/routers/license.ts index 4beeece..0e612eb 100644 --- a/src/server/api/routers/license.ts +++ b/src/server/api/routers/license.ts @@ -1,6 +1,5 @@ import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc"; import { z } from "zod"; -import { TRPCError } from "@trpc/server"; import licenseService from "~/server/services/license/license.service"; export const licenseRouter = createTRPCRouter({ @@ -14,26 +13,13 @@ export const licenseRouter = createTRPCRouter({ find: protectedProcedure .input( z.object({ - page: z.string(), - limit: z.string(), + page: z.coerce.number(), + limit: z.coerce.number().min(1).max(50), sort: z.string().or(z.array(z.string())).optional(), filter: z.record(z.string(), z.string()).optional(), }), ) .query(async ({ input }) => { - const { page, limit, sort, filter } = input; - if (isNaN(Number(page)) || isNaN(Number(limit)) || Number(limit) > 50) { - throw new TRPCError({ - code: "BAD_REQUEST", - message: "Invalid page or limit", - }); - } - - return licenseService.find({ - page: Number(page), - limit: Number(limit), - sort, - filter, - }); + return licenseService.find(input); }), }); diff --git a/src/server/api/routers/user.ts b/src/server/api/routers/user.ts index 7a0a6d5..99fce15 100644 --- a/src/server/api/routers/user.ts +++ b/src/server/api/routers/user.ts @@ -1,7 +1,6 @@ import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc"; import userService from "~/server/services/user/user.service"; import { z } from "zod"; -import { TRPCError } from "@trpc/server"; export const userRouter = createTRPCRouter({ findById: protectedProcedure @@ -14,26 +13,13 @@ export const userRouter = createTRPCRouter({ find: protectedProcedure .input( z.object({ - page: z.string(), - limit: z.string(), + page: z.coerce.number(), + limit: z.coerce.number().min(1).max(50), sort: z.string().or(z.array(z.string())).optional(), filter: z.record(z.string(), z.string()).optional(), }), ) .query(async ({ input }) => { - const { page, limit, sort, filter } = input; - if (isNaN(Number(page)) || isNaN(Number(limit)) || Number(limit) > 50) { - throw new TRPCError({ - code: "BAD_REQUEST", - message: "Invalid page or limit", - }); - } - - return userService.find({ - page: Number(page), - limit: Number(limit), - sort, - filter, - }); + return userService.find(input); }), });