const express = require('express'); const { verifyToken } = require('../auth'); const { createProductionOrders, listProductionOrders, updateProductionOrderStatus } = require('../services/productionOrderService'); const router = express.Router(); router.get('/production-orders', verifyToken, async (req, res) => { try { res.json(await listProductionOrders(req.query || {})); } catch (error) { console.error('Error fetching production orders:', error); res.status(500).json({ error: 'Internal Server Error' }); } }); router.post('/production-orders', verifyToken, async (req, res) => { try { const orders = Array.isArray(req.body?.orders) ? req.body.orders : []; res.status(201).json(await createProductionOrders(orders)); } catch (error) { console.error('Error creating production orders:', error); res.status(error.statusCode || 500).json({ error: error.message || 'Internal Server Error' }); } }); router.patch('/production-orders/:id/status', verifyToken, async (req, res) => { try { res.json(await updateProductionOrderStatus(req.params.id, req.body?.status)); } catch (error) { console.error('Error updating production order status:', error); res.status(error.statusCode || 500).json({ error: error.message || 'Internal Server Error' }); } }); module.exports = router;