26 lines
713 B
TypeScript
Raw Normal View History

import { z } from 'zod'
import { HttpServer, type THttpServer } from '~/libs/http-server'
export const categorySchema = z.object({
id: z.string(),
name: z.string(),
code: z.string(),
})
const categoriesSchema = z.object({
data: z.array(categorySchema),
})
export type TCategorySchema = z.infer<typeof categorySchema>
export type TCategoriesSchema = z.infer<typeof categoriesSchema>
export const getCategories = async (parameters?: THttpServer) => {
try {
const { data } = await HttpServer(parameters).get(`/api/category`)
return categoriesSchema.parse(data)
} catch (error) {
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
return Promise.reject(error)
}
}