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
|
||||
const detectorSchema = Joi.object({
|
||||
// Heartbeat fields
|
||||
type: Joi.string().valid('heartbeat').when('device_id', {
|
||||
not: Joi.exist(),
|
||||
then: Joi.required()
|
||||
// Simplified unified schema - validate based on payload type
|
||||
const detectorSchema = Joi.alternatives().try(
|
||||
// Heartbeat schema
|
||||
Joi.object({
|
||||
type: Joi.string().valid('heartbeat').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', {
|
||||
is: 'heartbeat',
|
||||
then: Joi.required()
|
||||
}),
|
||||
|
||||
// Optional heartbeat fields (from original heartbeat route)
|
||||
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(),
|
||||
|
||||
// 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)
|
||||
// Detection schema
|
||||
Joi.object({
|
||||
device_id: Joi.number().integer().required(),
|
||||
geo_lat: Joi.number().min(-90).max(90).required(),
|
||||
geo_lon: Joi.number().min(-180).max(180).required(),
|
||||
device_timestamp: Joi.number().integer().min(0).required(),
|
||||
drone_type: Joi.number().integer().min(0).required(),
|
||||
rssi: Joi.number().required(),
|
||||
freq: Joi.number().required(),
|
||||
drone_id: Joi.number().integer().required(),
|
||||
// Optional detection fields
|
||||
confidence_level: Joi.number().min(0).max(1).optional(),
|
||||
signal_duration: Joi.number().integer().min(0).optional()
|
||||
})
|
||||
);
|
||||
|
||||
// POST /api/detectors - Unified endpoint for heartbeats and detections
|
||||
router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user