From 4ef48122f7815daa4d5717ff45a3a52ed14e2a33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Yoshida?= <juliayosh@gmail.com> Date: Wed, 13 Dec 2023 23:57:44 -0300 Subject: [PATCH] [FIX] find registration period --- backend/controllers/SuperuserController.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/controllers/SuperuserController.js b/backend/controllers/SuperuserController.js index eb067ce..5438664 100644 --- a/backend/controllers/SuperuserController.js +++ b/backend/controllers/SuperuserController.js @@ -18,14 +18,15 @@ exports.openRegistrationPeriod = async (req, res) => { exports.getRegistrationPeriod = async (req, res) => { try { const currentPeriod = await Registration.findOne({ - attributes: [ - [sequelize.fn('max', sequelize.col('createdAt')), 'maxCreatedAt'] - ] - }); - - res.json(currentPeriod); + where: { id: 1 } + }); + if (!currentPeriod) { + res.status(404).json({ error: 'Período de matrícula não encontrado.' }); + return; + } + res.json(currentPeriod); } catch (error) { - console.error('Error fetching current registration period:', error); - res.status(500).json({ error: 'Erro ao buscar o período de matrícula atual.' }); + console.error('Erro ao buscar o período de matrícula atual:', error); + res.status(500).json({ error: 'Erro ao buscar o período de matrícula atual.' }); } - }; \ No newline at end of file +}; \ No newline at end of file