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