Fix jwt-token
This commit is contained in:
@@ -18,12 +18,6 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
// Get tenant from authenticated user context
|
// Get tenant from authenticated user context
|
||||||
const tenantId = req.tenantId;
|
const tenantId = req.tenantId;
|
||||||
console.log('🔍 Detections - Tenant ID from request:', tenantId);
|
|
||||||
|
|
||||||
// Debug: Check what tenants exist
|
|
||||||
const allTenants = await Tenant.findAll({ attributes: ['id', 'slug'] });
|
|
||||||
console.log('🔍 Detections - All tenants in database:', allTenants.map(t => ({ id: t.id, slug: t.slug })));
|
|
||||||
|
|
||||||
if (!tenantId) {
|
if (!tenantId) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -32,7 +26,6 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const tenant = await Tenant.findOne({ where: { slug: tenantId } });
|
const tenant = await Tenant.findOne({ where: { slug: tenantId } });
|
||||||
console.log('🔍 Detections - Tenant lookup result:', tenant ? `Found: ${tenant.slug}` : 'Not found');
|
|
||||||
if (!tenant) {
|
if (!tenant) {
|
||||||
return res.status(404).json({
|
return res.status(404).json({
|
||||||
success: false,
|
success: false,
|
||||||
@@ -122,6 +115,8 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
success: true,
|
||||||
|
data: {
|
||||||
detections: enhancedDetections,
|
detections: enhancedDetections,
|
||||||
pagination: {
|
pagination: {
|
||||||
currentPage: parseInt(page),
|
currentPage: parseInt(page),
|
||||||
@@ -131,6 +126,7 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
hasNextPage,
|
hasNextPage,
|
||||||
hasPrevPage
|
hasPrevPage
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ describe('Detections Routes', () => {
|
|||||||
describe('GET /detections', () => {
|
describe('GET /detections', () => {
|
||||||
it('should return detections for user tenant', async () => {
|
it('should return detections for user tenant', async () => {
|
||||||
const tenant = await createTestTenant({ slug: 'test-tenant' });
|
const tenant = await createTestTenant({ slug: 'test-tenant' });
|
||||||
console.log('🔍 Test - Created tenant:', { id: tenant.id, slug: tenant.slug });
|
|
||||||
const user = await createTestUser({ tenant_id: tenant.id });
|
const user = await createTestUser({ tenant_id: tenant.id });
|
||||||
const device = await createTestDevice({ tenant_id: tenant.id });
|
const device = await createTestDevice({ tenant_id: tenant.id });
|
||||||
const detection = await createTestDetection({ device_id: device.id });
|
const detection = await createTestDetection({ device_id: device.id });
|
||||||
@@ -49,9 +48,6 @@ describe('Detections Routes', () => {
|
|||||||
.get('/detections')
|
.get('/detections')
|
||||||
.set('Authorization', `Bearer ${token}`);
|
.set('Authorization', `Bearer ${token}`);
|
||||||
|
|
||||||
console.log('🔍 Test - Response status:', response.status);
|
|
||||||
console.log('🔍 Test - Response body:', response.body);
|
|
||||||
|
|
||||||
expect(response.status).to.equal(200);
|
expect(response.status).to.equal(200);
|
||||||
expect(response.body.success).to.be.true;
|
expect(response.body.success).to.be.true;
|
||||||
expect(response.body.data.detections).to.be.an('array');
|
expect(response.body.data.detections).to.be.an('array');
|
||||||
|
|||||||
Reference in New Issue
Block a user