From 05ec244107cf2a6493263d77cf60d582b9a35dae Mon Sep 17 00:00:00 2001 From: chop Date: Wed, 3 Dec 2025 22:22:26 +0100 Subject: [PATCH] feat: update createContractHandler to return the newly created contract with its ID --- src/app/api/contracts/route.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/api/contracts/route.js b/src/app/api/contracts/route.js index 17b7579..117f864 100644 --- a/src/app/api/contracts/route.js +++ b/src/app/api/contracts/route.js @@ -25,7 +25,7 @@ async function getContractsHandler() { async function createContractHandler(req) { const data = await req.json(); - db.prepare( + const result = db.prepare( ` INSERT INTO contracts ( contract_number, @@ -46,7 +46,10 @@ async function createContractHandler(req) { data.date_signed, data.finish_date ); - return NextResponse.json({ success: true }); + + // Return the newly created contract with its ID + const contract = db.prepare("SELECT * FROM contracts WHERE contract_id = ?").get(result.lastInsertRowid); + return NextResponse.json(contract); } // Protected routes - require authentication