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
|
* 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) => {
|
static uploadImage = asyncHandler(async (req, res) => {
|
||||||
const { projectId, timestamp, temperature, humidity } = req.body;
|
const { timestamp, temperature, humidity } = req.body;
|
||||||
const image = req.file;
|
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);
|
return sendError('Tous les champs sont requis', res, null, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
// Obtention du prochain ordre ID
|
||||||
const nextOrderId = await Measurement.getNextOrderId(projectId);
|
const nextOrderId = await Measurement.getNextOrderId(projectId);
|
||||||
|
|
||||||
if (nextOrderId === null) {
|
|
||||||
return sendError('Projet non trouvé', res, null, 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enregistrement de l'image
|
// Enregistrement de l'image
|
||||||
const imagePath = await StorageService.measurement.uploadMeasurementImage(
|
const imagePath = await StorageService.measurement.uploadMeasurementImage(
|
||||||
image, projectId, nextOrderId
|
image, projectId, nextOrderId
|
||||||
@@ -149,6 +156,7 @@ class ImageController {
|
|||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
message: 'Mesure téléchargée avec succès',
|
message: 'Mesure téléchargée avec succès',
|
||||||
|
project_id: projectId,
|
||||||
path: imagePath,
|
path: imagePath,
|
||||||
id: measurement.id
|
id: measurement.id
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user