diff --git a/site/api.py b/site/api.py index 01c6b02..2b6384d 100644 --- a/site/api.py +++ b/site/api.py @@ -36,14 +36,25 @@ def create_contract(): if not number: return jsonify({"error": "number is required"}), 400 - rowcount, err = db.execute( - "INSERT INTO contracts (number, client, date_signed) VALUES (%s, %s, %s)", - (number, client, date_signed), - ) + # INSERT с RETURNING id + conn, err = db.connect() if err: return jsonify({"error": err}), 500 - - return jsonify({"status": "created", "rowcount": rowcount}), 201 + try: + cur = conn.cursor() + cur.execute( + "INSERT INTO contracts (number, client, date_signed) VALUES (%s, %s, %s) RETURNING id", + (number, client, date_signed), + ) + contract_id = cur.fetchone()[0] + conn.commit() + cur.close() + conn.close() + return jsonify({"status": "created", "id": str(contract_id)}), 201 + except Exception as e: + conn.rollback() + conn.close() + return jsonify({"error": str(e)}), 500 @api_bp.route("/api/contracts", methods=["GET"]) diff --git a/site/static/nubes-logo.svg b/site/static/nubes-logo.svg index 1a7aed4..4ccedbe 100644 --- a/site/static/nubes-logo.svg +++ b/site/static/nubes-logo.svg @@ -1,2 +1,3 @@ -Forbidden -Transaction ID: bdd7fbca-219a-4dbf-95ca-a27cc8bdecd9 + + nubes + diff --git a/site/templates/upload.html b/site/templates/upload.html index 04fb4f1..595020e 100644 --- a/site/templates/upload.html +++ b/site/templates/upload.html @@ -107,10 +107,7 @@
- - +
Нет добавленных файлов
@@ -197,8 +194,9 @@ method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({number: 'б/н ' + new Date().toISOString().slice(0,10)}), }); - const listResp = await fetch('/api/contracts'); - contractId = (await listResp.json()).contracts[0].id; + const data = await resp.json(); + if (!resp.ok || !data.id) throw new Error(data.error || 'no id'); + contractId = data.id; } catch (e) { resultsBody.innerHTML = '
❌ ' + e.message + '
'; resetBtn(); return;