mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
refactor: improve account validation in transaction updates and enhance test setup with mock API context
This commit is contained in:
@@ -40,13 +40,14 @@ export const PUT: APIRoute = async ({ request, params }) => {
|
||||
// If account is changing, validate new account exists
|
||||
let newAccount = oldAccount;
|
||||
if (updates.accountId && updates.accountId !== oldTransaction.accountId) {
|
||||
newAccount = accounts.find((a) => a.id === updates.accountId);
|
||||
if (!newAccount) {
|
||||
const foundAccount = accounts.find((a) => a.id === updates.accountId);
|
||||
if (!foundAccount) {
|
||||
return new Response(JSON.stringify({ error: "Account not found" }), {
|
||||
status: 404,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
newAccount = foundAccount;
|
||||
}
|
||||
|
||||
// First, remove the old transaction's effect on the old account
|
||||
|
||||
Reference in New Issue
Block a user