Girl Scout Cookie tracking app with Express/SQLite API and React/Vite client. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const { getDb } = require('../db');
|
|
|
|
router.get('/', (req, res) => {
|
|
try {
|
|
const db = getDb();
|
|
const lowStock = db.prepare(`
|
|
SELECT * FROM products
|
|
WHERE low_stock_threshold > 0 AND quantity_on_hand <= low_stock_threshold
|
|
ORDER BY quantity_on_hand ASC
|
|
`).all();
|
|
const recentOrders = db.prepare(`
|
|
SELECT o.*, c.name as customer_name
|
|
FROM orders o
|
|
LEFT JOIN customers c ON c.id = o.customer_id
|
|
ORDER BY o.created_at DESC
|
|
LIMIT 10
|
|
`).all();
|
|
const productCount = db.prepare('SELECT COUNT(*) as count FROM products').get().count;
|
|
const customerCount = db.prepare('SELECT COUNT(*) as count FROM customers').get().count;
|
|
const orderCount = db.prepare('SELECT COUNT(*) as count FROM orders').get().count;
|
|
res.json({
|
|
lowStock,
|
|
recentOrders,
|
|
productCount,
|
|
customerCount,
|
|
orderCount,
|
|
});
|
|
} catch (err) {
|
|
res.status(500).json({ error: err.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|