Skip to content

Commit

Permalink
[FIX]: período de matrícula atual
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaryoshida committed Dec 14, 2023
1 parent 757b65e commit b1682a7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 12 deletions.
44 changes: 43 additions & 1 deletion backend/controllers/LearningPathsEnrolmentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,46 @@ exports.Students = async(req, res) => {
res.status(400).json({ error: err.message });
}

}
}

exports.isOpenEnrolment = async () => {
let registrationsPeriod = await Registration.findAll();

for (let res of registrationsPeriod) {
let startDate = new Date(res.start);
let endDate = new Date(res.end);
const now = new Date();

if (startDate < now && endDate >= now) {
// O período de matrícula está aberto
await Registration.update(
{ isOpen: true },
{ where: { id: res.id } }
);
} else {
// O período de matrícula está fechado
await Registration.update(
{ isOpen: false },
{ where: { id: res.id } }
);

if (endDate < now) {
// O período de matrícula está encerrado, gerar lista aleatória de alunos matriculados
const studentsByLP = await LearningPathsEnrolment.findAll({ where: { learning_path_id: res.learning_path_id } });
const shuffledStudents = shuffleArray(studentsByLP);

// Faça o que você precisa com a lista aleatória de alunos, por exemplo, salvar no banco de dados ou retornar na resposta da API
console.log('Lista aleatória de alunos matriculados:', shuffledStudents);
}
}
}
}

function shuffleArray(array) {
// Função para embaralhar um array aleatoriamente
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
20 changes: 10 additions & 10 deletions backend/controllers/SuperuserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ exports.openRegistrationPeriod = async (req, res) => {
}


exports.getRegistrationperiod = async (req, res) => {
exports.getRecentRegistrationPeriod = async (req, res) => {
try {
const currentPeriod = await Registration.findOne({
start: { $lte: new Date() },
end: { $gte: new Date() },
});
res.json(currentPeriod);
} catch (error) {
res.status(500).json({ error: 'Erro ao buscar o período de matrícula atual.' });
}
}
const recentPeriod = await Registration.findOne({
order: [['start', 'DESC']], // Ordena por data de início em ordem decrescente
});

res.json(recentPeriod);
} catch (error) {
res.status(500).json({ error: 'Erro ao buscar o período de matrícula mais recente.' });
}
};
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.getRegistrationperiod);
router.get("/current", RegistrationPeriodController.getRecentRegistrationPeriod);


module.exports = router;

1 comment on commit b1682a7

@vercel
Copy link

@vercel vercel bot commented on b1682a7 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.