From 5339245c5712034138f0ecc143df158d0a1e3edb Mon Sep 17 00:00:00 2001 From: Regularmute <93884347+Regularmute@users.noreply.github.com> Date: Fri, 3 May 2024 14:30:53 +0300 Subject: [PATCH 1/2] Fetch all time logs for instructors Temporarily fetch all time logs for instructors. --- backend/controllers/instructorTimeLogs.js | 37 +++-------------------- 1 file changed, 5 insertions(+), 32 deletions(-) diff --git a/backend/controllers/instructorTimeLogs.js b/backend/controllers/instructorTimeLogs.js index 314ccdb..f31f414 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 { checkLogin, checkInstructor } = require('../middleware') const db = require('../models/index') const { Sequelize } = require('sequelize') @@ -71,37 +71,10 @@ const fetchAllFromDb = async () => { } } -const fetchGroupIdsFromLatestConfiguration = async () => { - 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.' }) +instructorTimeLogsRouter.get('/', checkInstructor, async (req, res) => { + try { + const timeLogs = await fetchAllFromDb() + return res.status(200).json(timeLogs) } catch (error) { return res.status(500).json({ error: 'Error fetching time logs.' }) } From 027afc0bbdce22c6b3bd6c864fe9a70ab3efc94e Mon Sep 17 00:00:00 2001 From: Regularmute <93884347+Regularmute@users.noreply.github.com> Date: Fri, 3 May 2024 14:35:20 +0300 Subject: [PATCH 2/2] fix linting errors --- backend/controllers/instructorTimeLogs.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/controllers/instructorTimeLogs.js b/backend/controllers/instructorTimeLogs.js index f31f414..6ed19d4 100644 --- a/backend/controllers/instructorTimeLogs.js +++ b/backend/controllers/instructorTimeLogs.js @@ -1,5 +1,5 @@ const instructorTimeLogsRouter = require('express').Router() -const { checkLogin, checkInstructor } = require('../middleware') +const { checkInstructor } = require('../middleware') const db = require('../models/index') const { Sequelize } = require('sequelize') @@ -72,7 +72,7 @@ const fetchAllFromDb = async () => { } instructorTimeLogsRouter.get('/', checkInstructor, async (req, res) => { - try { + try { const timeLogs = await fetchAllFromDb() return res.status(200).json(timeLogs) } catch (error) {