Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Algusto-RC committed Dec 14, 2023
2 parents 354325e + 3a04678 commit 2870b80
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 34 deletions.
16 changes: 9 additions & 7 deletions backend/controllers/SuperuserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ exports.openRegistrationPeriod = async (req, res) => {
});
}


exports.getRecentRegistrationPeriod = async (req, res) => {
exports.getRegistrationPeriod = async (req, res) => {
try {
const recentPeriod = await Registration.findOne({
order: [['start', 'DESC']], // Ordena por data de início em ordem decrescente
});
const currentPeriod = await Registration.findOne({
attributes: [
[sequelize.fn('max', sequelize.col('createdAt')), 'maxCreatedAt']
]
});

res.json(recentPeriod);
res.json(currentPeriod);
} catch (error) {
res.status(500).json({ error: 'Erro ao buscar o período de matrícula mais recente.' });
console.error('Error fetching current registration period:', error);
res.status(500).json({ error: 'Erro ao buscar o período de matrícula atual.' });
}
};
2 changes: 1 addition & 1 deletion backend/views/routes/RegistrationPeriod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const router = express.Router();
const RegistrationPeriodController = require('../../controllers/SuperuserController');

router.post("/create", RegistrationPeriodController.openRegistrationPeriod);
router.get("/current", RegistrationPeriodController.getRecentRegistrationPeriod);
router.get("/current", RegistrationPeriodController.getRegistrationPeriod);


module.exports = router;
22 changes: 11 additions & 11 deletions frontend/src/pages/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ const Home = () => {
</Center>

{currentRegistrationPeriod && (
<Center>
<Text fontSize="lg" color="#243A69" marginTop="2vh">
Período de Matrícula Atual:{" "}
{`${new Date(currentRegistrationPeriod.start).toLocaleDateString()} às ${new Date(
currentRegistrationPeriod.start
).toLocaleTimeString()} - ${new Date(currentRegistrationPeriod.end).toLocaleDateString()} às ${new Date(
currentRegistrationPeriod.end
).toLocaleTimeString()}`}
</Text>
</Center>
)}
<Center>
<Text fontSize="lg" color="#243A69" marginTop="2vh">
Período de Matrícula Atual:{" "}
{`${new Date(currentRegistrationPeriod.start).toLocaleDateString()} às ${new Date(
currentRegistrationPeriod.start
).toLocaleTimeString()} - ${new Date(currentRegistrationPeriod.end).toLocaleDateString()} às ${new Date(
currentRegistrationPeriod.end
).toLocaleTimeString()}`}
</Text>
</Center>
)}
</Container>
<Footer />
</Flex>
Expand Down
47 changes: 32 additions & 15 deletions frontend/src/pages/RegistrationPeriod/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,38 @@ const RegistrationPeriod = () => {
},
validationSchema: yup.object({
startDate: yup
.date()
.required("A data de ínicio é obrigatória")
.min(new Date(new Date().setDate(new Date().getDate()-1)), "A data de início deve ser a partir de hoje")
.max(tenYearsFromNow, "A data de início não pode ser mais do que 10 anos a partir de hoje"),
startTime: yup
.string()
.required("A hora de ínicio é obrigatória")
.test('isAfterOrEqualCurrentTime', 'A hora de ínicio deve ser posterior à hora atual', function (startTime) {
const currentDateTime = new Date();
const selectedTime = new Date(currentDateTime);
const [hours, minutes] = startTime.split(':');
selectedTime.setHours(hours, minutes, 0);

return selectedTime >= currentDateTime;
}),
.date()
.required("A data de início é obrigatória")
.min(new Date(new Date().setDate(new Date().getDate() - 1)), "A data de início deve ser a partir de hoje")
.max(tenYearsFromNow, "A data de início não pode ser mais do que 10 anos a partir de hoje"),
startTime: yup
.string()
.test('isStartTimeValid', 'A hora de ínicio deve ser posterior à hora atual', function (startTime, { parent }) {
const selectedDate = new Date(parent.startDate);
const currentDate = new Date();

if (
selectedDate.getDate() === currentDate.getDate() &&
selectedDate.getMonth() === currentDate.getMonth() &&
selectedDate.getFullYear() === currentDate.getFullYear()
) {
if (!startTime) {
return this.createError({
message: "A hora de ínicio é obrigatória",
path: 'startTime',
});
}

const currentDateTime = new Date();
const selectedTime = new Date(currentDateTime);
const [hours, minutes] = startTime.split(':');
selectedTime.setHours(hours, minutes, 0);

return selectedTime >= currentDateTime;
}

return true;
}),
endDate: yup
.date()
.required("A data de término é obrigatória")
Expand Down

1 comment on commit 2870b80

@vercel
Copy link

@vercel vercel bot commented on 2870b80 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

matriculai – ./frontend

matriculai-matriculai.vercel.app
matriculai-git-main-matriculai.vercel.app
matriculai.vercel.app

Please sign in to comment.