From f503f224a6f25094a6b706bd381eabd9a50d69b4 Mon Sep 17 00:00:00 2001 From: Kerboul Date: Tue, 14 Jan 2025 17:47:07 +0100 Subject: [PATCH] =?UTF-8?q?Refactor=20la=20route=20GET=20/projects=20pour?= =?UTF-8?q?=20utiliser=20async/await=20et=20am=C3=A9liorer=20la=20gestion?= =?UTF-8?q?=20des=20erreurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routes/api.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/routes/api.js b/routes/api.js index 27f1451..220b1d3 100644 --- a/routes/api.js +++ b/routes/api.js @@ -18,7 +18,15 @@ const fileUtils = require('../fileUtils'); * 500: * description: Internal server error */ -router.get('/projects', projectController.getAllProjects); +router.get('/projects', async (req, res) => { + try { + const projects = await db.query('SELECT * FROM public.projects'); + res.json(projects.rows); + } catch (error) { + console.error('Error fetching projects:', error); + res.status(500).json({ error: 'Internal server error' }); + } +}); /** * @swagger