Fix jwt-token
This commit is contained in:
@@ -1,8 +1,15 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
const models = global.__TEST_MODELS__ || require('../models');
|
|
||||||
console.log('🔧 DEBUG: detections route using models:', global.__TEST_MODELS__ ? 'global test models' : 'regular models');
|
// Dynamic model injection for testing
|
||||||
const { DroneDetection, Device, Tenant } = models;
|
function getModels() {
|
||||||
|
if (global.__TEST_MODELS__) {
|
||||||
|
console.log('🔧 DEBUG: Using global test models in detections route');
|
||||||
|
return global.__TEST_MODELS__;
|
||||||
|
}
|
||||||
|
return require('../models');
|
||||||
|
}
|
||||||
|
|
||||||
const { authenticateToken } = require('../middleware/auth');
|
const { authenticateToken } = require('../middleware/auth');
|
||||||
const { getDroneTypeInfo } = require('../utils/droneTypes');
|
const { getDroneTypeInfo } = require('../utils/droneTypes');
|
||||||
const MultiTenantAuth = require('../middleware/multi-tenant-auth');
|
const MultiTenantAuth = require('../middleware/multi-tenant-auth');
|
||||||
@@ -17,6 +24,9 @@ const multiAuth = new MultiTenantAuth();
|
|||||||
*/
|
*/
|
||||||
router.get('/', authenticateToken, async (req, res) => {
|
router.get('/', authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const models = getModels();
|
||||||
|
const { DroneDetection, Device, Tenant } = models;
|
||||||
|
|
||||||
// Get tenant from authenticated user context
|
// Get tenant from authenticated user context
|
||||||
const tenantId = req.tenantId;
|
const tenantId = req.tenantId;
|
||||||
console.log('🔍 Looking for tenant with slug:', tenantId);
|
console.log('🔍 Looking for tenant with slug:', tenantId);
|
||||||
@@ -168,6 +178,9 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
router.get('/debug', authenticateToken, async (req, res) => {
|
router.get('/debug', authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const models = getModels();
|
||||||
|
const { DroneDetection, Device } = models;
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
if (req.user.role !== 'admin') {
|
if (req.user.role !== 'admin') {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
@@ -270,6 +283,9 @@ router.get('/debug', authenticateToken, async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
router.get('/:id', authenticateToken, async (req, res) => {
|
router.get('/:id', authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const models = getModels();
|
||||||
|
const { DroneDetection, Device, Tenant } = models;
|
||||||
|
|
||||||
// Get tenant from authenticated user context
|
// Get tenant from authenticated user context
|
||||||
const tenantId = req.tenantId;
|
const tenantId = req.tenantId;
|
||||||
if (!tenantId) {
|
if (!tenantId) {
|
||||||
@@ -340,6 +356,9 @@ router.get('/:id', authenticateToken, async (req, res) => {
|
|||||||
*/
|
*/
|
||||||
router.delete('/:id', authenticateToken, async (req, res) => {
|
router.delete('/:id', authenticateToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
|
const models = getModels();
|
||||||
|
const { DroneDetection, Device, Tenant } = models;
|
||||||
|
|
||||||
// Check if user is admin
|
// Check if user is admin
|
||||||
if (req.user.role !== 'admin') {
|
if (req.user.role !== 'admin') {
|
||||||
return res.status(403).json({
|
return res.status(403).json({
|
||||||
|
|||||||
Reference in New Issue
Block a user