Fix jwt-token
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const Joi = require('joi');
|
||||
const { Device, DroneDetection, Heartbeat, Tenant } = require('../models');
|
||||
const { validateRequest } = require('../middleware/validation');
|
||||
const { authenticateToken } = require('../middleware/auth');
|
||||
const MultiTenantAuth = require('../middleware/multi-tenant-auth');
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
// Dynamic model injection for testing
|
||||
function getModels() {
|
||||
if (global.__TEST_MODELS__) {
|
||||
console.log('🔧 DEBUG: Using global test models from models/index.js');
|
||||
return global.__TEST_MODELS__;
|
||||
}
|
||||
return require('../models');
|
||||
}
|
||||
|
||||
// Initialize multi-tenant auth
|
||||
const multiAuth = new MultiTenantAuth();
|
||||
|
||||
@@ -38,6 +46,8 @@ const updateDeviceSchema = Joi.object({
|
||||
// GET /api/devices - Get all devices
|
||||
router.get('/', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
|
||||
|
||||
// Determine tenant from request
|
||||
const tenantId = await multiAuth.determineTenant(req);
|
||||
if (!tenantId) {
|
||||
@@ -159,6 +169,8 @@ router.get('/', authenticateToken, async (req, res) => {
|
||||
// GET /api/devices/map - Get devices with location data for map display
|
||||
router.get('/map', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
|
||||
|
||||
// Determine tenant from request
|
||||
const tenantId = await multiAuth.determineTenant(req);
|
||||
if (!tenantId) {
|
||||
@@ -240,6 +252,8 @@ router.get('/map', authenticateToken, async (req, res) => {
|
||||
// GET /api/devices/:id - Get specific device
|
||||
router.get('/:id', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { Device, DroneDetection, Heartbeat, Tenant } = getModels();
|
||||
|
||||
// Determine tenant from request
|
||||
const tenantId = await multiAuth.determineTenant(req);
|
||||
if (!tenantId) {
|
||||
|
||||
Reference in New Issue
Block a user