refactor backend and persist stock campaign queue
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m32s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m32s
This commit is contained in:
26
backend/routes/stockRoutes.js
Normal file
26
backend/routes/stockRoutes.js
Normal file
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user