Skip to content

Commit

Permalink
Merge pull request #67 from buildingu/feat-add-reviewer-functionality
Browse files Browse the repository at this point in the history
Update: app functionality
  • Loading branch information
gbudjeakp authored Aug 27, 2024
2 parents 87b3133 + 945633b commit 7efcfe3
Show file tree
Hide file tree
Showing 17 changed files with 111 additions and 195 deletions.
135 changes: 50 additions & 85 deletions Controllers/feedbackController.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,37 +73,17 @@ const submitFeedBack = async (req, res) => {
/*This retrieves every single feedback (only requests that are not marked as complete requests made by the interns
*/
const getAllFeedBackRequestsForms = async (req, res) => {
const { authToken } = req.cookies;
const { id, username } = jwt.verify(authToken, process.env.JWT_SECRET);
try {
const isMentor = await User.findOne({
where: {
id: id,
mentor: true,
},
});
if (isMentor) {
const feedBackrequests = await FeedbackRequest.findAll({
where: {
status: {
[Op.not]: true,
},
},
});
res.status(200).json({ data: feedBackrequests });
}
//Not sure why this was added. Might not be useful. Will revisit to make sure it's needed.
if (!isMentor) {

const feedBackrequests = await FeedbackRequest.findAll({
where: {
studentName: username,
status: {
[Op.not]: true,
},
},
});
res.status(200).json({ data: feedBackrequests });
}

} catch (err) {
res.status(500).json({ error: "Internal Server Error" });
logger.error(`Server Error`, {error: JSON.stringify(err)})
Expand Down Expand Up @@ -184,13 +164,49 @@ const flockNotification = async (req, res) => {
}
};

//////////////////////////////////////////
/* Code below here are basically controller functions
for the Code leads or mentor endpoints
*/
///////////////////////////////////////////////

/*This controller allows the Code leads to add feedbacks to the feedback requests made by the interns */
/*This controller allows users to assign feedback requests to themselves
for
*/
const assignFeedBack = async (req, res) => {
try {
const { feedbackrequestId } = req.params;
const { authToken } = req.cookies;
const { id, username } = jwt.verify(authToken, process.env.JWT_SECRET);


// Grab the user information based on the id for updates of the request form.
const userDetail = await User.findOne({
where: username,
where: {id: id}
})

// Find the specific feedback request record based on feedbackrequestId
const feedbackRecord = await FeedbackRequest.findOne({
where: { id: feedbackrequestId },
});

if (!feedbackRecord) {
logger.error(`Feedback record not found`, {log: JSON.stringify(feedbackRecord)})
return res.status(404).json({ msg: "Feedback record not found" });
}

feedbackRecord.isAssigned = true;
feedbackRecord.whoisAssigned = userDetail.fName;
await feedbackRecord.save();

logger.info(`Feedback assigned to mentor`, {log: JSON.stringify(feedbackRecord)})
res.json({ msg: "Feedback assigned to mentor", data: feedbackRecord });
} catch (err) {
logger.error(`An error occurred while updating feedback`, {log: JSON.stringify(err)})
res
.status(500)
.json({ error: "An error occurred while updating feedback" });
}
};


/*This controller allows users to add feedbacks to the feedback requests in the queue */
const addFeedBack = async (req, res) => {
try {
const { feedback } = req.body;
Expand All @@ -204,18 +220,6 @@ const addFeedBack = async (req, res) => {
return res.status(400).json(errors);
}

// Check if the user is a mentor
const isMentor = await User.findOne({
where: {
id: id,
mentor: true,
},
});

if (!isMentor) {
logger.error(`Unauthorized user`, {log: JSON.stringify(isMentor)})
return res.status(401).json({ msg: "Unauthorized user" });
}

// Find the specific feedback request record based on feedbackrequestId
const feedbackRequest = await FeedbackRequest.findOne({
Expand Down Expand Up @@ -252,51 +256,12 @@ const addFeedBack = async (req, res) => {
}
};

/*This controller allows the Code leads to assign feedback requests to themselves
*/
const assignFeedBackToMentor = async (req, res) => {
try {
const { feedbackrequestId } = req.params;
const { authToken } = req.cookies;
const { id } = jwt.verify(authToken, process.env.JWT_SECRET);

// Check if the user is a mentor
const isMentor = await User.findOne({
where: {
id: id,
mentor: true,
},
});

if (!isMentor) {
logger.error(`Unauthorized user`, {log: JSON.stringify(isMentor)})
return res.status(401).json({ msg: "Unauthorized user" });
}

// Find the specific feedback request record based on feedbackrequestId
const feedbackRecord = await FeedbackRequest.findOne({
where: { id: feedbackrequestId },
});

if (!feedbackRecord) {
logger.error(`Feedback record not found`, {log: JSON.stringify(feedbackRecord)})
return res.status(404).json({ msg: "Feedback record not found" });
}

feedbackRecord.isAssigned = true;
feedbackRecord.mentorId = isMentor.mentorId;
feedbackRecord.whoisAssigned = isMentor.fName;
await feedbackRecord.save();

logger.info(`Feedback assigned to mentor`, {log: JSON.stringify(feedbackRecord)})
res.json({ msg: "Feedback assigned to mentor", data: feedbackRecord });
} catch (err) {
logger.error(`An error occurred while updating feedback`, {log: JSON.stringify(err)})
res
.status(500)
.json({ error: "An error occurred while updating feedback" });
}
};
//////////////////////////////////////////
/* Code below here are basically controller functions
for the Code leads or mentor endpoints
*/
///////////////////////////////////////////////

/*This controller retrieves all the assigned Feedback Requests
of the code lead logged in.
Expand Down Expand Up @@ -422,7 +387,7 @@ module.exports = {
submitFeedBack,
getAllFeedBackRequestsForms,
getUserFeedBackRequestForms,
assignFeedBackToMentor,
assignFeedBack,
addFeedBack,
getAssignedFeedBacks,
getMentorFeedback,
Expand Down
11 changes: 6 additions & 5 deletions Controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Users = db.User;
const ExerciseInfo = db.ExerciseInfo;
const FeedbackRequest = db.FeedbackRequest;
const Feedbacks = db.Feedbacks;
const Mentors = db.Mentors;
const Mentors = require("../admin.json");
const loginValidator = require("../utility/inputValidator/loginValidator");
const registerValidator = require("../utility/inputValidator/registerValidator");
const logger = require("../utility/logger/logger");
Expand All @@ -18,8 +18,9 @@ const registerUser = async (req, res) => {
const { fName, userName, password } = req.body;
const { errors, validationCheck } = registerValidator(req.body);
const isUserExist = await Users.findOne({ where: { username: userName } });
const isMentorEmail = await Mentors.findOne({ where: { email: userName } });
const isUserMentor = !!isMentorEmail;

//Check if the user should be a mentor based on the email
const isMentor = Mentors.Mentors.include(userName);
const { v4: uuidv4 } = require("uuid");

// This checks that the inputs entered meet some criteria
Expand Down Expand Up @@ -48,8 +49,8 @@ const registerUser = async (req, res) => {
fName: fName,
username: userName,
password: hashedPassword,
mentor: isUserMentor,
mentorId: isUserMentor ? uuidv4() : null,
mentor: isMentor,
mentorId: isMentor ? uuidv4() : null,
};

await Users.create(userData);
Expand Down
15 changes: 0 additions & 15 deletions Models/Mentors.js

This file was deleted.

2 changes: 0 additions & 2 deletions Models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const FeedbackRequest = require("./Feedbackrequest")(sequelize, DataTypes);
const Feedbacks = require("./Feedbacks")(sequelize, DataTypes);
const Otptoken = require("./Otptoken")(sequelize, DataTypes);
const ExerciseInfo = require("./ExerciseInfo")(sequelize, DataTypes);
const Mentors = require("./Mentors")(sequelize, DataTypes);


//This was poorly desgined. Should spent more time fixing this
Expand Down Expand Up @@ -58,5 +57,4 @@ module.exports = {
Feedbacks,
Otptoken,
ExerciseInfo,
Mentors,
};
2 changes: 1 addition & 1 deletion Routes/Feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const feedbackController = require('../Controllers/feedbackController')

router.post("/submitfeedback", auth, rateLimiter, feedbackController.submitFeedBack);

router.post("/assignFeedBackToMentor/:feedbackrequestId", auth, rateLimiter,feedbackController.assignFeedBackToMentor);
router.post("/assignFeedBack/:feedbackrequestId", auth, rateLimiter,feedbackController.assignFeedBack);

router.post("/addFeedBack/:feedbackrequestId", auth, rateLimiter, feedbackController.addFeedBack);

Expand Down
9 changes: 9 additions & 0 deletions admin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Mentors":[
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "building-u-feedback-api",
"version": "v3.0.0",
"version": "v4.0.0",
"description": "This is for the server api that serves the app",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion views/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "building-u-feedback",
"version": "v3.0.0",
"version": "v4.0.0",
"homepage": "https://buildingu.github.io/Building-u-feedback",
"type": "module",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions views/src/Pages/CreatedRequests.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function CreatedRequests(props) {
return (
<div>
<FeedbackCard
notifyMentor={true}
showViewFeedback={true}
data={internFeedbackRequests}
pageTitle="MY FEEDBACK REQUESTS"
Expand Down
1 change: 1 addition & 0 deletions views/src/Pages/FeedbackQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function FeedbackQueue(props) {
<div>
<FeedbackCard
isAssign={true}
showAddFeedback={true}
data={feedbackData}
pageTitle="FEEDBACK QUEUE"
user={props.user}
Expand Down
34 changes: 20 additions & 14 deletions views/src/Pages/Interndashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
import React from 'react'
import React from 'react';
import Sidebar from '../components/Sidebar';
import { Routes, Route, useLocation } from 'react-router-dom';
import { IconFilePlus, IconClipboardText, IconUser } from '@tabler/icons-react';

import FeedbackRequestForm from "../Pages/FeedbackrequestForm"
import { Stack, rem, Tooltip } from "@mantine/core";
import { IconFilePlus, IconClipboardText, IconUser, IconListDetails, IconLogout } from '@tabler/icons-react';
import FeedbackRequestForm from "../Pages/FeedbackrequestForm";
import FeedbackRequestQueue from '../Pages/FeedbackQueue';
import CreatedRequests from '../Pages/CreatedRequests';
import Account from '../Pages/Account/';
import TopBar from '../components/TopBar';

function Interndashboard(props) {
const navItems = [
{ icon: IconFilePlus, label: 'Create Feedback request', to: 'requestform' },
{ icon: IconListDetails, label: 'Feedback Queue', to: 'feedbackqueue' },
{ icon: IconClipboardText, label: 'Feedback Requests', to: 'myrequests' },
{ icon: IconUser, label: 'Account', to: 'account' },
{ icon: IconLogout, label: 'Logout', to: 'logout' }
];

const location = useLocation();

return (
<div style={{ display: 'flex', flexDirection: 'column-reverse' }}>
<TopBar user={props.user} />
<div style={{ display: 'flex'}}>
<Sidebar navItems={navItems} />
<Routes location={location}>
<Route path="/requestform" element={<FeedbackRequestForm active={0} user={props.user}/>} />
<Route path="/myrequests" element={<CreatedRequests active={1} user={props.user}/>} />
<Route path="/account" element={<Account active={2} user={props.user} />} />
</Routes>
</div>
)
<div style={{ flex: 1, marginLeft: rem(1) }}>
<TopBar user={props.user} />
<Routes location={location}>
<Route path="/feedbackqueue" element={<FeedbackRequestQueue active={0} user={props.user} />} />
<Route path="/requestform" element={<FeedbackRequestForm active={0} user={props.user}/>} />
<Route path="/myrequests" element={<CreatedRequests active={1} user={props.user}/>} />
<Route path="/account" element={<Account active={2} user={props.user} />} />
</Routes>
</div>
</div>
);
}

export default Interndashboard
export default Interndashboard;
13 changes: 5 additions & 8 deletions views/src/Pages/Mentordashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Sidebar from '../components/Sidebar';
import { Routes, Route, useLocation } from 'react-router-dom';
import { IconListDetails, IconCheckupList, IconUser } from '@tabler/icons-react';
import { IconListDetails, IconCheckupList, IconUser, IconLogout } from '@tabler/icons-react';
import FeedbackRequestQueue from '../Pages/FeedbackQueue';
import AssignedFeedback from '../Pages/AssignedFeedback';
import Account from '../Pages/Account';
Expand All @@ -12,6 +12,7 @@ function Mentordashboard(props) {
{ icon: IconListDetails, label: 'Feedback Queue', to: 'feedbackqueue' },
{ icon: IconCheckupList, label: 'Assigned Feedback', to: 'assigned' },
{ icon: IconUser, label: 'Account', to: 'account' },
{ icon: IconLogout, label: 'Logout', to: 'logout' }
];

const location = useLocation();
Expand All @@ -21,13 +22,9 @@ function Mentordashboard(props) {
<TopBar user={props.user} />
<Sidebar navItems={navItems} />
<Routes location={location}>
<Route
path="/feedbackqueue"
element={<FeedbackRequestQueue active={0} user={props.user} />}
/>
<Route path="assigned" element={<AssignedFeedback active={1} user={props.user} />} />

<Route path="account" element={<Account active={2} user={props.user} />} />
<Route path="/feedbackqueue" element={<FeedbackRequestQueue active={0} user={props.user} />}/>
<Route path="assigned" element={<AssignedFeedback active={1} user={props.user} />} />
<Route path="account" element={<Account active={2} user={props.user} />} />
</Routes>
</div>
);
Expand Down
Loading

0 comments on commit 7efcfe3

Please sign in to comment.