Fix jwt-token

This commit is contained in:
2025-08-28 08:28:02 +02:00
parent a68e664403
commit af8a5c5ffe
2 changed files with 27 additions and 13 deletions

View File

@@ -555,16 +555,30 @@ const DeviceModal = ({ device, onClose, onSave }) => {
try { try {
if (device) { if (device) {
// Update existing device - exclude read-only fields // Update existing device - exclude read-only fields and filter out empty strings
const updateData = { const updateData = {
name: formData.name, name: formData.name,
location_description: formData.location_description, location_description: formData.location_description || null,
notes: formData.notes notes: formData.notes || null
}; };
// Remove null values to avoid sending unnecessary data
Object.keys(updateData).forEach(key => {
if (updateData[key] === null || updateData[key] === '') {
delete updateData[key];
}
});
await api.put(`/devices/${device.id}`, updateData); await api.put(`/devices/${device.id}`, updateData);
} else { } else {
// Create new device - include all fields // Create new device - include all fields, convert empty strings to null
await api.post('/devices', formData); const createData = { ...formData };
Object.keys(createData).forEach(key => {
if (createData[key] === '') {
createData[key] = null;
}
});
await api.post('/devices', createData);
} }
onSave(); onSave();
} catch (error) { } catch (error) {

View File

@@ -9,26 +9,26 @@ const { Op } = require('sequelize');
// Validation schema for device // Validation schema for device
const deviceSchema = Joi.object({ const deviceSchema = Joi.object({
id: Joi.number().integer().required(), id: Joi.number().integer().required(),
name: Joi.string().max(255).optional(), name: Joi.string().max(255).allow('').optional(),
geo_lat: Joi.number().min(-90).max(90).optional(), geo_lat: Joi.number().min(-90).max(90).optional(),
geo_lon: Joi.number().min(-180).max(180).optional(), geo_lon: Joi.number().min(-180).max(180).optional(),
location_description: Joi.string().optional(), location_description: Joi.string().allow('').optional(),
heartbeat_interval: Joi.number().integer().min(60).max(3600).optional(), heartbeat_interval: Joi.number().integer().min(60).max(3600).optional(),
firmware_version: Joi.string().optional(), firmware_version: Joi.string().allow('').optional(),
installation_date: Joi.date().optional(), installation_date: Joi.date().optional(),
notes: Joi.string().optional() notes: Joi.string().allow('').optional()
}); });
const updateDeviceSchema = Joi.object({ const updateDeviceSchema = Joi.object({
name: Joi.string().max(255).optional(), name: Joi.string().max(255).allow('').optional(),
geo_lat: Joi.number().min(-90).max(90).optional(), geo_lat: Joi.number().min(-90).max(90).optional(),
geo_lon: Joi.number().min(-180).max(180).optional(), geo_lon: Joi.number().min(-180).max(180).optional(),
location_description: Joi.string().optional(), location_description: Joi.string().allow('').optional(),
is_active: Joi.boolean().optional(), is_active: Joi.boolean().optional(),
heartbeat_interval: Joi.number().integer().min(60).max(3600).optional(), heartbeat_interval: Joi.number().integer().min(60).max(3600).optional(),
firmware_version: Joi.string().optional(), firmware_version: Joi.string().allow('').optional(),
installation_date: Joi.date().optional(), installation_date: Joi.date().optional(),
notes: Joi.string().optional() notes: Joi.string().allow('').optional()
}); });
// GET /api/devices - Get all devices // GET /api/devices - Get all devices