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 }); } }