Fix jwt-token

This commit is contained in:
2025-08-28 08:26:49 +02:00
parent 7a6a2edd56
commit a68e664403
2 changed files with 9 additions and 8 deletions

View File

@@ -3,9 +3,10 @@ const router = express.Router();
const { DroneDetection, Device, Heartbeat } = require('../models'); const { DroneDetection, Device, Heartbeat } = require('../models');
const { Op } = require('sequelize'); const { Op } = require('sequelize');
const { sequelize } = require('../models'); const { sequelize } = require('../models');
const { authenticateToken } = require('../middleware/auth');
// GET /api/dashboard/overview - Get dashboard overview statistics // GET /api/dashboard/overview - Get dashboard overview statistics
router.get('/overview', async (req, res) => { router.get('/overview', authenticateToken, async (req, res) => {
try { try {
const { hours = 24 } = req.query; const { hours = 24 } = req.query;
const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000); const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000);
@@ -98,7 +99,7 @@ router.get('/overview', async (req, res) => {
}); });
// GET /api/dashboard/activity - Get recent activity feed // GET /api/dashboard/activity - Get recent activity feed
router.get('/activity', async (req, res) => { router.get('/activity', authenticateToken, async (req, res) => {
try { try {
const { limit = 50, hours = 24 } = req.query; const { limit = 50, hours = 24 } = req.query;
const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000); const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000);
@@ -176,7 +177,7 @@ router.get('/activity', async (req, res) => {
}); });
// GET /api/dashboard/charts/detections - Get detection chart data // GET /api/dashboard/charts/detections - Get detection chart data
router.get('/charts/detections', async (req, res) => { router.get('/charts/detections', authenticateToken, async (req, res) => {
try { try {
const { hours = 24, interval = 'hour' } = req.query; const { hours = 24, interval = 'hour' } = req.query;
const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000); const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000);
@@ -226,7 +227,7 @@ router.get('/charts/detections', async (req, res) => {
}); });
// GET /api/dashboard/charts/devices - Get device activity chart data // GET /api/dashboard/charts/devices - Get device activity chart data
router.get('/charts/devices', async (req, res) => { router.get('/charts/devices', authenticateToken, async (req, res) => {
try { try {
const { hours = 24 } = req.query; const { hours = 24 } = req.query;
const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000); const timeWindow = new Date(Date.now() - hours * 60 * 60 * 1000);

View File

@@ -32,7 +32,7 @@ const updateDeviceSchema = Joi.object({
}); });
// GET /api/devices - Get all devices // GET /api/devices - Get all devices
router.get('/', async (req, res) => { router.get('/', authenticateToken, async (req, res) => {
try { try {
const { const {
include_stats = false, include_stats = false,
@@ -122,7 +122,7 @@ router.get('/', async (req, res) => {
}); });
// GET /api/devices/map - Get devices with location data for map display // GET /api/devices/map - Get devices with location data for map display
router.get('/map', async (req, res) => { router.get('/map', authenticateToken, async (req, res) => {
try { try {
const devices = await Device.findAll({ const devices = await Device.findAll({
where: { where: {
@@ -182,7 +182,7 @@ router.get('/map', async (req, res) => {
}); });
// GET /api/devices/:id - Get specific device // GET /api/devices/:id - Get specific device
router.get('/:id', async (req, res) => { router.get('/:id', authenticateToken, async (req, res) => {
try { try {
const device = await Device.findByPk(req.params.id, { const device = await Device.findByPk(req.params.id, {
include: [ include: [
@@ -321,7 +321,7 @@ router.delete('/:id', authenticateToken, async (req, res) => {
}); });
// GET /api/devices/pending - List devices pending approval // GET /api/devices/pending - List devices pending approval
router.get('/pending', async (req, res) => { router.get('/pending', authenticateToken, async (req, res) => {
try { try {
const pendingDevices = await Device.findAll({ const pendingDevices = await Device.findAll({
where: { is_approved: false }, where: { is_approved: false },