Ajout de la gestion des images avec scan, suppression et mise à jour des mesures dans la base de données
This commit is contained in:
@@ -11,21 +11,77 @@ async function uploadMeasureImage(image, projectId, orderId) {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
|
||||
async function getMeasureImage(projectId, orderId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const imagePath = `${projectPath}/${orderId}.jpg`;
|
||||
return storageManager.getFile(imagePath);
|
||||
}
|
||||
|
||||
async function addMeasureToProject(projectId, timestamp, imagePath, temperature, humidity, completed) {
|
||||
const query = 'INSERT INTO public.measurements (project_id, timestamp, image_path, temperature, humidity, completed) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *';
|
||||
const values = [projectId, timestamp, imagePath, temperature, humidity, completed];
|
||||
async function getNextOrderId(projectId) {
|
||||
const query = 'SELECT MAX(order_id) FROM public.measurements WHERE project_id = $1';
|
||||
const values = [projectId];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0].max + 1;
|
||||
}
|
||||
|
||||
async function addMeasureToProject(projectId, orderId, timestamp, path, temperature, humidity) {
|
||||
const query = 'INSERT INTO public.measurements (project_id, timestamp, path, temperature, humidity, order_id) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *';
|
||||
const values = [projectId, orderId, timestamp, path, temperature, humidity];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
async function getMeasurements(projectId) {
|
||||
const query = 'SELECT * FROM public.measurements WHERE project_id = $1';
|
||||
const values = [projectId];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows;
|
||||
}
|
||||
|
||||
async function getMeasurement(projectId, orderId) {
|
||||
const query = 'SELECT * FROM public.measurements WHERE project_id = $1 AND order_id = $2';
|
||||
const values = [projectId, orderId];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
async function getMeasurementById(id) {
|
||||
const query = 'SELECT * FROM public.measurements WHERE id = $1';
|
||||
const values = [id];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
async function updateMeasurement(projectId, orderId, timestamp, path, temperature, humidity) {
|
||||
const query = 'UPDATE public.measurements SET timestamp = $3, path = $4, temperature = $5, humidity = $6 WHERE project_id = $1 AND order_id = $2 RETURNING *';
|
||||
const values = [projectId, orderId, timestamp, path, temperature, humidity];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
async function updateMeasurementById(id, timestamp, path, temperature, humidity) {
|
||||
const query = 'UPDATE public.measurements SET timestamp = $2, path = $3, temperature = $4, humidity = $5 WHERE id = $1 RETURNING *';
|
||||
const values = [id, timestamp, path, temperature, humidity];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
async function deleteMeasurement(id) {
|
||||
const query = 'DELETE FROM public.measurements WHERE id = $1';
|
||||
const values = [id];
|
||||
const res = await db.query(query, values);
|
||||
return res.rows[0];
|
||||
}
|
||||
|
||||
export {
|
||||
uploadMeasureImage,
|
||||
addMeasureToProject
|
||||
}
|
||||
addMeasureToProject,
|
||||
getNextOrderId,
|
||||
getMeasurements,
|
||||
getMeasurement,
|
||||
updateMeasurement,
|
||||
deleteMeasurement,
|
||||
getMeasureImage,
|
||||
getMeasurementById,
|
||||
updateMeasurementById
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user