feat: refined search

This commit is contained in:
Cory Dransfeldt 2024-10-19 22:02:51 -07:00
parent a141dd5ce0
commit 4893256340
No known key found for this signature in database
5 changed files with 20 additions and 10 deletions

View file

@ -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 });
}
},
};
};