This commit is contained in:
lejay
2026-02-13 00:21:53 +01:00
parent 81d2412835
commit 6923c319a1
85 changed files with 17836 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import pool, { run } from '../db/index.js';
export async function getOrders(req, res) {
try {
const { rows } = await pool.query(
'SELECT id, config, total_chf, email, name, phone, notes, created_at FROM orders ORDER BY created_at DESC'
);
res.json(rows);
} catch (err) {
res.status(500).json({ error: err.message });
}
}
export async function postOrder(req, res) {
try {
const { config, totalChf, email, name, phone, notes } = req.body || {};
await run(
`INSERT INTO orders (config, total_chf, email, name, phone, notes)
VALUES ($1, $2, $3, $4, $5, $6)`,
[JSON.stringify(config || {}), totalChf ?? null, email ?? null, name ?? null, phone ?? null, notes ?? null]
);
const { rows } = await pool.query('SELECT id, created_at FROM orders ORDER BY id DESC LIMIT 1');
res.status(201).json(rows[0]);
} catch (err) {
res.status(500).json({ error: err.message });
}
}