Fix jwt-token
This commit is contained in:
@@ -2,9 +2,12 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const Joi = require('joi');
|
const Joi = require('joi');
|
||||||
const { DroneDetection, Device } = require('../models');
|
const { DroneDetection, Device } = require('../models');
|
||||||
const { processAlert } = require('../services/alertService');
|
const AlertService = require('../services/alertService');
|
||||||
const { validateRequest } = require('../middleware/validation');
|
const { validateRequest } = require('../middleware/validation');
|
||||||
|
|
||||||
|
// Initialize AlertService instance
|
||||||
|
const alertService = new AlertService();
|
||||||
|
|
||||||
// Validation schema for drone detection
|
// Validation schema for drone detection
|
||||||
const droneDetectionSchema = Joi.object({
|
const droneDetectionSchema = Joi.object({
|
||||||
device_id: Joi.number().integer().required(),
|
device_id: Joi.number().integer().required(),
|
||||||
@@ -61,7 +64,7 @@ router.post('/', validateRequest(droneDetectionSchema), async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Process alerts asynchronously
|
// Process alerts asynchronously
|
||||||
processAlert(detection).catch(error => {
|
alertService.processAlert(detection).catch(error => {
|
||||||
console.error('Alert processing error:', error);
|
console.error('Alert processing error:', error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -555,10 +555,5 @@ class AlertService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export singleton instance
|
// Export the class directly (not a singleton instance)
|
||||||
const alertService = new AlertService();
|
module.exports = AlertService;
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
processAlert: (detection) => alertService.processAlert(detection),
|
|
||||||
AlertService
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user