Fix jwt-token
This commit is contained in:
@@ -52,6 +52,10 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
order = 'desc'
|
order = 'desc'
|
||||||
} = req.query;
|
} = req.query;
|
||||||
|
|
||||||
|
// Validate and sanitize pagination parameters
|
||||||
|
const validatedPage = Math.max(1, parseInt(page) || 1);
|
||||||
|
const validatedLimit = Math.min(100, Math.max(1, parseInt(limit) || 50));
|
||||||
|
|
||||||
// Build where clause for filtering
|
// Build where clause for filtering
|
||||||
const whereClause = {};
|
const whereClause = {};
|
||||||
|
|
||||||
@@ -81,7 +85,7 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate offset for pagination
|
// Calculate offset for pagination
|
||||||
const offset = (parseInt(page) - 1) * parseInt(limit);
|
const offset = (validatedPage - 1) * validatedLimit;
|
||||||
|
|
||||||
// Query detections with device information (filtered by tenant)
|
// Query detections with device information (filtered by tenant)
|
||||||
const detections = await DroneDetection.findAll({
|
const detections = await DroneDetection.findAll({
|
||||||
@@ -93,7 +97,7 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description', 'is_approved']
|
attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description', 'is_approved']
|
||||||
}],
|
}],
|
||||||
order: [[sort, order.toUpperCase()]],
|
order: [[sort, order.toUpperCase()]],
|
||||||
limit: parseInt(limit),
|
limit: validatedLimit,
|
||||||
offset: offset
|
offset: offset
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,9 +112,9 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Calculate pagination info
|
// Calculate pagination info
|
||||||
const totalPages = Math.ceil(totalCount / parseInt(limit));
|
const totalPages = Math.ceil(totalCount / validatedLimit);
|
||||||
const hasNextPage = parseInt(page) < totalPages;
|
const hasNextPage = validatedPage < totalPages;
|
||||||
const hasPrevPage = parseInt(page) > 1;
|
const hasPrevPage = validatedPage > 1;
|
||||||
|
|
||||||
// Enhance detections with drone type information
|
// Enhance detections with drone type information
|
||||||
const enhancedDetections = detections.map(detection => {
|
const enhancedDetections = detections.map(detection => {
|
||||||
@@ -126,10 +130,10 @@ router.get('/', authenticateToken, async (req, res) => {
|
|||||||
data: {
|
data: {
|
||||||
detections: enhancedDetections,
|
detections: enhancedDetections,
|
||||||
pagination: {
|
pagination: {
|
||||||
currentPage: parseInt(page),
|
currentPage: validatedPage,
|
||||||
totalPages,
|
totalPages,
|
||||||
totalCount,
|
totalCount,
|
||||||
limit: parseInt(limit),
|
limit: validatedLimit,
|
||||||
hasNextPage,
|
hasNextPage,
|
||||||
hasPrevPage
|
hasPrevPage
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user