diff --git a/src/controllers/imageController.js b/src/controllers/imageController.js index a211a90..14d88af 100644 --- a/src/controllers/imageController.js +++ b/src/controllers/imageController.js @@ -120,23 +120,30 @@ class ImageController { /** * Télécharge une nouvelle image avec des données de mesure + * Ne nécessite plus l'ID du projet, utilise automatiquement le projet actif */ static uploadImage = asyncHandler(async (req, res) => { - const { projectId, timestamp, temperature, humidity } = req.body; + const { timestamp, temperature, humidity } = req.body; const image = req.file; - if (!image || !projectId || !timestamp || !temperature || !humidity) { + if (!image || !timestamp || !temperature || !humidity) { return sendError('Tous les champs sont requis', res, null, 400); } try { + // Récupération du projet actif (en cours de capture) + const Project = require('../models/Project'); + const activeProject = await Project.findCurrentRenderingProject(); + + if (!activeProject) { + return sendError('Aucun projet actif en cours de capture', res, null, 400); + } + + const projectId = activeProject.id; + // Obtention du prochain ordre ID const nextOrderId = await Measurement.getNextOrderId(projectId); - if (nextOrderId === null) { - return sendError('Projet non trouvé', res, null, 404); - } - // Enregistrement de l'image const imagePath = await StorageService.measurement.uploadMeasurementImage( image, projectId, nextOrderId @@ -149,6 +156,7 @@ class ImageController { res.json({ message: 'Mesure téléchargée avec succès', + project_id: projectId, path: imagePath, id: measurement.id });