From e6fd5b3a87fedc56e96940567e5d0b7ec5f20073 Mon Sep 17 00:00:00 2001 From: Kerboul Date: Sun, 27 Apr 2025 15:06:54 +0200 Subject: [PATCH] =?UTF-8?q?feat(image):=20Supprimer=20la=20n=C3=A9cessit?= =?UTF-8?q?=C3=A9=20de=20l'ID=20du=20projet=20lors=20du=20t=C3=A9l=C3=A9ch?= =?UTF-8?q?argement=20d'une=20image,=20en=20utilisant=20le=20projet=20acti?= =?UTF-8?q?f?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/imageController.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 });