Fix jwt-token

This commit is contained in:
2025-09-16 22:20:34 +02:00
parent c2c18821dd
commit 394252af10

View File

@@ -317,6 +317,8 @@ router.get('/:id', authenticateToken, async (req, res) => {
// POST /api/devices - Create new device (admin only) // POST /api/devices - Create new device (admin only)
router.post('/', authenticateToken, validateRequest(deviceSchema), async (req, res) => { router.post('/', authenticateToken, validateRequest(deviceSchema), async (req, res) => {
try { try {
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
// Determine tenant from request // Determine tenant from request
const tenantId = await multiAuth.determineTenant(req); const tenantId = await multiAuth.determineTenant(req);
if (!tenantId) { if (!tenantId) {
@@ -388,6 +390,8 @@ router.post('/', authenticateToken, validateRequest(deviceSchema), async (req, r
// PUT /api/devices/:id - Update device // PUT /api/devices/:id - Update device
router.put('/:id', authenticateToken, validateRequest(updateDeviceSchema), async (req, res) => { router.put('/:id', authenticateToken, validateRequest(updateDeviceSchema), async (req, res) => {
try { try {
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
const device = await Device.findByPk(req.params.id); const device = await Device.findByPk(req.params.id);
if (!device) { if (!device) {
@@ -426,6 +430,8 @@ router.put('/:id', authenticateToken, validateRequest(updateDeviceSchema), async
// DELETE /api/devices/:id - Delete device (admin only) // DELETE /api/devices/:id - Delete device (admin only)
router.delete('/:id', authenticateToken, async (req, res) => { router.delete('/:id', authenticateToken, async (req, res) => {
try { try {
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
const device = await Device.findByPk(req.params.id); const device = await Device.findByPk(req.params.id);
if (!device) { if (!device) {
@@ -456,6 +462,8 @@ 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', authenticateToken, async (req, res) => { router.get('/pending', authenticateToken, async (req, res) => {
try { try {
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
const pendingDevices = await Device.findAll({ const pendingDevices = await Device.findAll({
where: { is_approved: false }, where: { is_approved: false },
attributes: [ attributes: [
@@ -483,6 +491,8 @@ router.get('/pending', authenticateToken, async (req, res) => {
// POST /api/devices/:id/approve - Approve or reject a device // POST /api/devices/:id/approve - Approve or reject a device
router.post('/:id/approve', async (req, res) => { router.post('/:id/approve', async (req, res) => {
try { try {
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
const deviceId = parseInt(req.params.id); const deviceId = parseInt(req.params.id);
const { approved } = req.body; const { approved } = req.body;