diff --git a/src/routes/application.ts b/src/routes/application.ts index c1997d9..7d47a5c 100644 --- a/src/routes/application.ts +++ b/src/routes/application.ts @@ -3,8 +3,8 @@ import { procedure, router } from '../trpc'; import { ApplicationZod } from '../types/zod'; import { addApplication, deleteApplicationById, getApplicationList, updateApplicationById } from '../service/application'; import { ApplicationCreateZod, ApplicationUpdateZod } from '../types/zodExt/Application'; -import { getDefaultFailResponse, getDefaultPageResponse, getDefaultResponse } from '../utils'; -import { ApiPageResponseZod, ApiResponseZod, PageInfoQueryZod } from '../types'; +import { PageInfoQueryZod, PageInfoZod } from '../types'; +import { TRPCError } from '@trpc/server'; export const applicationRouter = router({ /** 新增应用 */ @@ -15,8 +15,10 @@ export const applicationRouter = router({ .input(ApplicationCreateZod) .mutation(async ({ input }) => { const res = await addApplication(input); - if (res?.id) return getDefaultResponse(); - return getDefaultFailResponse(); + if (!res?.id) throw new TRPCError({ + code: 'CONFLICT', + message: '错误提示', + }) }), /** 根据id删除应用 */ deleteRecodeById: procedure @@ -26,18 +28,20 @@ export const applicationRouter = router({ .input(ApplicationZod.pick({ id: true })) .mutation(async ({ input }) => { const res = await deleteApplicationById(input.id); - if (res.id === input.id) return getDefaultResponse(); - return getDefaultFailResponse(); + if (res.id !== input.id) throw new TRPCError({ + code: 'CONFLICT', + message: '错误提示', + }) }), /** 获取全部应用列表 */ getList: procedure .meta({ description: "获取全部应用列表" }) - .output(ApiResponseZod(z.array(ApplicationZod))) + .output(z.array(ApplicationZod)) .query(async () => { const list = await getApplicationList(); - return getDefaultResponse(list); + return list; }), /** 分页获取应用列表 */ getListByPage: procedure @@ -45,10 +49,14 @@ export const applicationRouter = router({ description: "分页获取应用列表" }) .input(PageInfoQueryZod) - .output(ApiPageResponseZod(ApplicationZod)) + .output(PageInfoZod(ApplicationZod)) .query(async ({ input }) => { const list = await getApplicationList(); - return getDefaultPageResponse(input, list, 1000); + return { + ...input, + list, + totalCount: 1000 + }; }), /** 更新应用信息 */ updateRecord: procedure @@ -56,10 +64,11 @@ export const applicationRouter = router({ description: '更新应用信息' }) .input(ApplicationUpdateZod) - .output(ApiResponseZod()) .mutation(async ({ input }) => { const res = await updateApplicationById(input); - if (res.id == input.id) return getDefaultResponse(); - return getDefaultFailResponse(); + if (res.id !== input.id) throw new TRPCError({ + code: 'CONFLICT', + message: '错误提示', + }) }), }); diff --git a/src/routes/index.ts b/src/routes/index.ts index f372b6e..a2eaca2 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -9,7 +9,7 @@ export const appRouter = router({ /** 应用 */ application: applicationRouter, /** 应用环境 */ - appEnv: appEnvRouter, + // appEnv: appEnvRouter, }) export type AppRouter = typeof appRouter; \ No newline at end of file