feat: refined search
This commit is contained in:
parent
a141dd5ce0
commit
4893256340
5 changed files with 20 additions and 10 deletions
|
@ -25,10 +25,15 @@ export default {
|
|||
|
||||
if (error) {
|
||||
console.error("Error fetching search data:", error);
|
||||
return new Response(JSON.stringify({ results: [] }), { status: 500 });
|
||||
return new Response(JSON.stringify({ results: [], total: 0 }), {
|
||||
status: 500,
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ results: data }), {
|
||||
const total = data.length > 0 ? data[0].total_count : 0;
|
||||
const results = data.map(({ total_count, ...item }) => item);
|
||||
|
||||
return new Response(JSON.stringify({ results, total, page, pageSize }), {
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
} catch (error) {
|
||||
|
@ -36,4 +41,4 @@ export default {
|
|||
return new Response("Internal Server Error", { status: 500 });
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
Reference in a new issue