All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m32s
27 lines
841 B
JavaScript
27 lines
841 B
JavaScript
const express = require('express');
|
|
const { authenticateAPIKey, verifyToken } = require('../auth');
|
|
const { listStock, upsertStockItems } = require('../services/stockService');
|
|
|
|
const router = express.Router();
|
|
|
|
router.get('/stock', verifyToken, async (req, res) => {
|
|
try {
|
|
res.json(await listStock());
|
|
} catch (error) {
|
|
console.error('Error fetching stock:', error);
|
|
res.status(500).json({ error: 'Internal Server Error' });
|
|
}
|
|
});
|
|
|
|
router.post('/stock', authenticateAPIKey, async (req, res) => {
|
|
res.status(201).json({ message: 'Stock data received, processing in background' });
|
|
|
|
const payload = Array.isArray(req.body) ? req.body : [req.body];
|
|
|
|
upsertStockItems(payload).catch((error) => {
|
|
console.error('Database stock insert error:', error);
|
|
});
|
|
});
|
|
|
|
module.exports = router;
|