Partial order insertion lacks atomicity
Review this Node.js order-placement handler.
```js async function placeOrder(pool, userId, items, total) { const { rows } = await pool.query( 'INSERT INTO orders (user_id, total) VALUES ($1, $2) RETURNING id', [userId, total] ); const orderId = rows[0].id; for (const it of items) { await pool.query( 'INSERT INTO order_items (order_id, sku, qty) VALUES ($1, $2, $3)', [orderId, it.sku, it.qty] ); } await pool.query( 'UPDATE inventory SET stock = stock - $1 WHERE sku = $2', [items[0].qty, items[0].sku] ); return orderId; }
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 22 min
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.