feat: delete ticker from database when removed from portfolio

- Add DELETE support to /api/stocks endpoint via _method parameter
- Modify removeStock to delete db- prefixed entries from database
- Add confirmation dialog on delete button click
- Add test for stock deletion
This commit is contained in:
2026-05-14 10:29:27 +02:00
parent 3340fd11ca
commit 043c3d5afe
4 changed files with 62 additions and 23 deletions
+8
View File
@@ -10,11 +10,19 @@ export async function loader() {
export async function action({ request }: { request: Request }) {
const formData = await request.formData();
const ticker = formData.get("ticker")?.toString().toUpperCase();
const method = formData.get("_method")?.toString() || "POST";
if (!ticker) {
return Response.json({ error: "Ticker is required" }, { status: 400 });
}
if (method === "DELETE") {
await db.stock.deleteMany({
where: { ticker },
});
return Response.json({ success: true });
}
const stock = await db.stock.create({
data: { ticker },
});