app.post("/transfer", async (req, res) => { const { fromId, toId, amount } = req.body; if (!fromId || !toId || !amount) { const err = new Error("Missing required fields: fromId, toId, amount"); err.status = 400; throw err; } if (amount <= 0) { const err = new Error("Transfer amount must be positive"); err.status = 400; throw err; } const accounts = await getAccounts(); const sender = accounts.find((a) => a.id === fromId); if (!sender) { const err = new Error("Sender account not found"); err.status = 404; throw err; } const recipient = accounts.find((a) => a.id === toId); if (!recipient) { const err = new Error("Recipient account not found"); err.status = 404; throw err; } if (sender.balance < amount) { const err = new Error("Insufficient funds"); err.status = 409; throw err; } sender.balance -= amount; recipient.balance += amount; await saveAccounts(accounts); res.json({ message: "Transfer successful", senderName: sender.owner, recipientName: recipient.owner, amountTransferred: amount, senderNewBalance: sender.balance, recipientNewBalance: recipient.balance, }); });