feat: update createContractHandler to return the newly created contract with its ID

This commit is contained in:
2025-12-03 22:22:26 +01:00
parent 77f4c80a79
commit 05ec244107

View File

@@ -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