feat(image): Supprimer la nécessité de l'ID du projet lors du téléchargement d'une image, en utilisant le projet actif
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 10s
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 10s
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user