From b2900f0bc7d35dcf8b5821b49cea0605bfbb1445 Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Fri, 3 Mar 2023 12:42:00 +0800 Subject: [PATCH] chore(website): refine search api --- packages/website/api/search.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/website/api/search.ts b/packages/website/api/search.ts index 22465c1a8..d6a8053ad 100644 --- a/packages/website/api/search.ts +++ b/packages/website/api/search.ts @@ -1,14 +1,17 @@ -export async function searchArticles(str: string): Promise { +// TODO: Add return types +export const searchArticles = async (query: string): Promise => { try { - const url = `/api/public/search?value=${str}`; - const res = await fetch(url); - const { data } = await res.json(); + const { data } = await fetch(`/api/public/search?value=${query}`).then( + (res) => res.json() + ); + return data.data; } catch (err) { console.log(err); throw err; } -} +}; + export async function searchWithApiRoute(str: string) { try { const url = `/api/search?value=${str}`;