feat: implement news fetching API and integrate with dashboard contents

This commit is contained in:
Ardeman
2025-03-06 09:30:53 +08:00
parent d27c068f39
commit 703e347830
4 changed files with 81 additions and 17 deletions
+48
View File
@@ -0,0 +1,48 @@
import { z } from 'zod'
import { HttpServer, type THttpServer } from '~/libs/http-server'
const newsSchema = z.object({
data: z.array(
z.object({
id: z.string(),
title: z.string(),
content: z.string(),
categories: z.array(
z.object({
id: z.string(),
name: z.string(),
code: z.string(),
created_at: z.string(),
updated_at: z.string(),
}),
),
tags: z.array(
z.object({
id: z.string(),
name: z.string(),
code: z.string(),
created_at: z.string(),
updated_at: z.string(),
}),
),
is_premium: z.boolean(),
slug: z.string(),
featured_image: z.string(),
author_id: z.string(),
live_at: z.string(),
created_at: z.string(),
updated_at: z.string(),
}),
),
})
export const getNews = async (parameters: THttpServer) => {
try {
const { data } = await HttpServer(parameters).get(`/api/news`)
return newsSchema.parse(data)
} catch (error) {
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
return Promise.reject(error)
}
}