feat: add API endpoints for fetching news by ID and slug, and update routing accordingly
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
import { newsResponseSchema } from '~/apis/common/get-news'
|
||||
import { HttpServer, type THttpServer } from '~/libs/http-server'
|
||||
|
||||
const dataResponseSchema = z.object({
|
||||
data: z.object(newsResponseSchema.shape),
|
||||
})
|
||||
|
||||
type TParameters = {
|
||||
slug: string
|
||||
} & THttpServer
|
||||
|
||||
export const getNewsBySlug = async (parameters: TParameters) => {
|
||||
const { slug, ...restParameters } = parameters
|
||||
try {
|
||||
const { data } = await HttpServer(restParameters).get(
|
||||
`/api/news/${encodeURIComponent(slug)}`,
|
||||
)
|
||||
return dataResponseSchema.parse(data)
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
||||
return Promise.reject(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user