Suppression du fichier Swagger pour le schéma de mesure et mise à jour des descriptions dans les routes d'images et de projets

This commit is contained in:
2025-02-11 18:30:32 +01:00
parent 08fa489f4c
commit 042ea5cc50
5 changed files with 310 additions and 247 deletions

View File

@@ -13,7 +13,7 @@ const serverError = require('../utils/serverError');
* summary: Retrieve a smile image
* responses:
* 200:
* description: Smile image retrieved successfully
* description: A smile image
* content:
* image/jpeg:
* schema:
@@ -23,67 +23,65 @@ const serverError = require('../utils/serverError');
* description: Image not found
*/
router.get('/smile', (req, res) => {
const imagePath = dbTester.getSmileImage();
fs.access(imagePath, fs.constants.F_OK, (err) => {
if (err) {
console.error('Image not found:', err);
return res.status(404).json({ error: 'Image not found' });
}
res.sendFile(imagePath);
});
const imagePath = dbTester.getSmileImage();
fs.access(imagePath, fs.constants.F_OK, (err) => {
if (err) {
console.error('Image not found:', err);
return res.status(404).json({ error: 'Image not found' });
}
res.sendFile(imagePath);
});
});
/**
* @swagger
* /images/{projectId}/{orderId}:
* get:
* summary: Retrieve an image by project ID and order ID
* summary: Retrieve an image by project and order ID
* parameters:
* - in: path
* name: projectId
* required: true
* schema:
* type: string
* description: The ID of the project
* description: The project ID
* - in: path
* name: orderId
* required: true
* schema:
* type: string
* description: The ID of the order
* description: The order ID
* responses:
* 200:
* description: Image retrieved successfully
* description: An image file
* content:
* image/jpeg:
* application/octet-stream:
* schema:
* type: string
* format: binary
* 404:
* description: Image not found
* 500:
* description: Internal server error
*/
router.get('/images/:projectId/:orderId', (req, res) => {
const projectId = req.params.projectId;
const orderId = req.params.orderId;
const query = 'SELECT path FROM public.measurements WHERE project_id = $1 AND order_id = $2';
db.query(query, [projectId, orderId], (err, results) => {
if (err) {
return serverError.sendError('Error getting image:', res, err);
}
if (results.rows.length === 0) {
return res.status(404).json({ error: 'Image not found' });
}
const imagePath = results.rows[0].path;
fs.access(imagePath, fs.constants.F_OK, (err) => {
const projectId = req.params.projectId;
const orderId = req.params.orderId;
const query = 'SELECT path FROM public.measurements WHERE project_id = $1 AND order_id = $2';
db.query(query, [projectId, orderId], (err, results) => {
if (err) {
console.error('Image not found:', err);
return res.status(404).json({ error: 'Image not found' });
return serverError.sendError('Error getting image:', res, err);
}
res.download(imagePath);
});
});
if (results.rows.length === 0) {
return res.status(404).json({ error: 'Image not found' });
}
const imagePath = results.rows[0].path;
fs.access(imagePath, fs.constants.F_OK, (err) => {
if (err) {
console.error('Image not found:', err);
return res.status(404).json({ error: 'Image not found' });
}
res.download(imagePath);
});
});
});
module.exports = router;