feat: refactor API response schemas for improve consistency

This commit is contained in:
Ardeman
2025-03-07 09:04:11 +08:00
parent 7163266100
commit d765d92df7
11 changed files with 40 additions and 50 deletions
+3 -3
View File
@@ -2,7 +2,7 @@ import { z } from 'zod'
import { HttpServer, type THttpServer } from '~/libs/http-server'
const userSchema = z.object({
const userResponseSchema = z.object({
data: z.object({
id: z.string(),
email: z.string(),
@@ -23,12 +23,12 @@ const userSchema = z.object({
}),
})
export type TUser = z.infer<typeof userSchema>
export type TUserResponse = z.infer<typeof userResponseSchema>
export const getUser = async (parameters: THttpServer) => {
try {
const { data } = await HttpServer(parameters).get(`/api/user/profile`)
return userSchema.parse(data)
return userResponseSchema.parse(data)
} catch (error) {
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
return Promise.reject(error)