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 {
if (device) {
// Update existing device - exclude read-only fields
// Update existing device - exclude read-only fields and filter out empty strings
const updateData = {
name: formData.name,
location_description: formData.location_description,
notes: formData.notes
location_description: formData.location_description || null,
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);
} else {
// Create new device - include all fields
await api.post('/devices', formData);
// Create new device - include all fields, convert empty strings to null
const createData = { ...formData };
Object.keys(createData).forEach(key => {
if (createData[key] === '') {
createData[key] = null;
}
});
await api.post('/devices', createData);
}
onSave();
} catch (error) {

View File

@@ -9,26 +9,26 @@ const { Op } = require('sequelize');
// Validation schema for device
const deviceSchema = Joi.object({
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_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(),
firmware_version: Joi.string().optional(),
firmware_version: Joi.string().allow('').optional(),
installation_date: Joi.date().optional(),
notes: Joi.string().optional()
notes: Joi.string().allow('').optional()
});
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_lon: Joi.number().min(-180).max(180).optional(),
location_description: Joi.string().optional(),
location_description: Joi.string().allow('').optional(),
is_active: Joi.boolean().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(),
notes: Joi.string().optional()
notes: Joi.string().allow('').optional()
});
// GET /api/devices - Get all devices