Fix jwt-token
This commit is contained in:
@@ -30,64 +30,36 @@ droneTracker.on('movement_alert', (alertData) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Unified schema that accepts both heartbeat and detection payloads
|
// Simplified unified schema - validate based on payload type
|
||||||
const detectorSchema = Joi.object({
|
const detectorSchema = Joi.alternatives().try(
|
||||||
// Heartbeat fields
|
// Heartbeat schema
|
||||||
type: Joi.string().valid('heartbeat').when('device_id', {
|
Joi.object({
|
||||||
not: Joi.exist(),
|
type: Joi.string().valid('heartbeat').required(),
|
||||||
then: Joi.required()
|
key: Joi.string().required(),
|
||||||
|
// Optional heartbeat fields
|
||||||
|
device_id: Joi.number().integer().optional(),
|
||||||
|
signal_strength: Joi.number().integer().optional(),
|
||||||
|
battery_level: Joi.number().integer().min(0).max(100).optional(),
|
||||||
|
temperature: Joi.number().optional(),
|
||||||
|
uptime: Joi.number().integer().min(0).optional(),
|
||||||
|
memory_usage: Joi.number().integer().min(0).max(100).optional(),
|
||||||
|
firmware_version: Joi.string().optional()
|
||||||
}),
|
}),
|
||||||
key: Joi.string().when('type', {
|
// Detection schema
|
||||||
is: 'heartbeat',
|
Joi.object({
|
||||||
then: Joi.required()
|
device_id: Joi.number().integer().required(),
|
||||||
}),
|
geo_lat: Joi.number().min(-90).max(90).required(),
|
||||||
|
geo_lon: Joi.number().min(-180).max(180).required(),
|
||||||
// Optional heartbeat fields (from original heartbeat route)
|
device_timestamp: Joi.number().integer().min(0).required(),
|
||||||
signal_strength: Joi.number().integer().optional(),
|
drone_type: Joi.number().integer().min(0).required(),
|
||||||
battery_level: Joi.number().integer().min(0).max(100).optional(),
|
rssi: Joi.number().required(),
|
||||||
temperature: Joi.number().optional(),
|
freq: Joi.number().required(),
|
||||||
uptime: Joi.number().integer().min(0).optional(),
|
drone_id: Joi.number().integer().required(),
|
||||||
memory_usage: Joi.number().integer().min(0).max(100).optional(),
|
// Optional detection fields
|
||||||
firmware_version: Joi.string().optional(),
|
confidence_level: Joi.number().min(0).max(1).optional(),
|
||||||
|
signal_duration: Joi.number().integer().min(0).optional()
|
||||||
// Detection fields
|
})
|
||||||
device_id: Joi.number().integer().when('type', {
|
);
|
||||||
not: 'heartbeat',
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
geo_lat: Joi.number().min(-90).max(90).when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
geo_lon: Joi.number().min(-180).max(180).when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
device_timestamp: Joi.number().integer().min(0).when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
drone_type: Joi.number().integer().min(0).when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
rssi: Joi.number().when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
freq: Joi.number().when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
drone_id: Joi.number().integer().when('device_id', {
|
|
||||||
is: Joi.exist(),
|
|
||||||
then: Joi.required()
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Optional detection fields
|
|
||||||
confidence_level: Joi.number().min(0).max(1).optional(),
|
|
||||||
signal_duration: Joi.number().integer().min(0).optional()
|
|
||||||
}).or('type', 'device_id'); // Must have either type (heartbeat) or device_id (detection)
|
|
||||||
|
|
||||||
// POST /api/detectors - Unified endpoint for heartbeats and detections
|
// POST /api/detectors - Unified endpoint for heartbeats and detections
|
||||||
router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user