diff --git a/backend/controllers/instructorTimeLogs.js b/backend/controllers/instructorTimeLogs.js index 314ccdb..6ed19d4 100644 --- a/backend/controllers/instructorTimeLogs.js +++ b/backend/controllers/instructorTimeLogs.js @@ -1,5 +1,5 @@ const instructorTimeLogsRouter = require('express').Router() -const { checkLogin } = require('../middleware') +const { checkInstructor } = require('../middleware') const db = require('../models/index') const { Sequelize } = require('sequelize') @@ -71,37 +71,10 @@ const fetchAllFromDb = async () => { } } -const fetchGroupIdsFromLatestConfiguration = async () => { +instructorTimeLogsRouter.get('/', checkInstructor, async (req, res) => { try { - const latestConfigurationId = await db.Configuration.findOne({ - order: [['created_at', 'DESC']], - attributes: ['id'] - }) - - const groups = await db.Group.findAll({ - where: { - configuration_id: latestConfigurationId.id - } - }) - return groups.map(group => group.id) - } catch (error) { - console.error('Error fetching groups:', error) - return false - } -} - -instructorTimeLogsRouter.get('/', checkLogin, async (req, res) => { - try { - if (req.user.admin ) { - const timeLogs = await fetchAllFromDb() - return res.status(200).json(timeLogs) - } else if (req.user.instructor) { - const timeLogs = await fetchAllFromDb() - const activeGroupIds = await fetchGroupIdsFromLatestConfiguration() - const filteredTimeLogs = timeLogs.filter(log => activeGroupIds.includes(log.groupId)) - return res.status(200).json(filteredTimeLogs) - } - return res.status(302).json({ error: 'Not authorized.' }) + const timeLogs = await fetchAllFromDb() + return res.status(200).json(timeLogs) } catch (error) { return res.status(500).json({ error: 'Error fetching time logs.' }) }