Skip to content

Commit 7efcfe3

Browse files
authored
Merge pull request #67 from buildingu/feat-add-reviewer-functionality
Update: app functionality
2 parents 87b3133 + 945633b commit 7efcfe3

File tree

17 files changed

+111
-195
lines changed

17 files changed

+111
-195
lines changed

Controllers/feedbackController.js

Lines changed: 50 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -73,37 +73,17 @@ const submitFeedBack = async (req, res) => {
7373
/*This retrieves every single feedback (only requests that are not marked as complete requests made by the interns
7474
*/
7575
const getAllFeedBackRequestsForms = async (req, res) => {
76-
const { authToken } = req.cookies;
77-
const { id, username } = jwt.verify(authToken, process.env.JWT_SECRET);
7876
try {
79-
const isMentor = await User.findOne({
80-
where: {
81-
id: id,
82-
mentor: true,
83-
},
84-
});
85-
if (isMentor) {
86-
const feedBackrequests = await FeedbackRequest.findAll({
87-
where: {
88-
status: {
89-
[Op.not]: true,
90-
},
91-
},
92-
});
93-
res.status(200).json({ data: feedBackrequests });
94-
}
95-
//Not sure why this was added. Might not be useful. Will revisit to make sure it's needed.
96-
if (!isMentor) {
77+
9778
const feedBackrequests = await FeedbackRequest.findAll({
9879
where: {
99-
studentName: username,
10080
status: {
10181
[Op.not]: true,
10282
},
10383
},
10484
});
10585
res.status(200).json({ data: feedBackrequests });
106-
}
86+
10787
} catch (err) {
10888
res.status(500).json({ error: "Internal Server Error" });
10989
logger.error(`Server Error`, {error: JSON.stringify(err)})
@@ -184,13 +164,49 @@ const flockNotification = async (req, res) => {
184164
}
185165
};
186166

187-
//////////////////////////////////////////
188-
/* Code below here are basically controller functions
189-
for the Code leads or mentor endpoints
190-
*/
191-
///////////////////////////////////////////////
192167

193-
/*This controller allows the Code leads to add feedbacks to the feedback requests made by the interns */
168+
/*This controller allows users to assign feedback requests to themselves
169+
for
170+
*/
171+
const assignFeedBack = async (req, res) => {
172+
try {
173+
const { feedbackrequestId } = req.params;
174+
const { authToken } = req.cookies;
175+
const { id, username } = jwt.verify(authToken, process.env.JWT_SECRET);
176+
177+
178+
// Grab the user information based on the id for updates of the request form.
179+
const userDetail = await User.findOne({
180+
where: username,
181+
where: {id: id}
182+
})
183+
184+
// Find the specific feedback request record based on feedbackrequestId
185+
const feedbackRecord = await FeedbackRequest.findOne({
186+
where: { id: feedbackrequestId },
187+
});
188+
189+
if (!feedbackRecord) {
190+
logger.error(`Feedback record not found`, {log: JSON.stringify(feedbackRecord)})
191+
return res.status(404).json({ msg: "Feedback record not found" });
192+
}
193+
194+
feedbackRecord.isAssigned = true;
195+
feedbackRecord.whoisAssigned = userDetail.fName;
196+
await feedbackRecord.save();
197+
198+
logger.info(`Feedback assigned to mentor`, {log: JSON.stringify(feedbackRecord)})
199+
res.json({ msg: "Feedback assigned to mentor", data: feedbackRecord });
200+
} catch (err) {
201+
logger.error(`An error occurred while updating feedback`, {log: JSON.stringify(err)})
202+
res
203+
.status(500)
204+
.json({ error: "An error occurred while updating feedback" });
205+
}
206+
};
207+
208+
209+
/*This controller allows users to add feedbacks to the feedback requests in the queue */
194210
const addFeedBack = async (req, res) => {
195211
try {
196212
const { feedback } = req.body;
@@ -204,18 +220,6 @@ const addFeedBack = async (req, res) => {
204220
return res.status(400).json(errors);
205221
}
206222

207-
// Check if the user is a mentor
208-
const isMentor = await User.findOne({
209-
where: {
210-
id: id,
211-
mentor: true,
212-
},
213-
});
214-
215-
if (!isMentor) {
216-
logger.error(`Unauthorized user`, {log: JSON.stringify(isMentor)})
217-
return res.status(401).json({ msg: "Unauthorized user" });
218-
}
219223

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

255-
/*This controller allows the Code leads to assign feedback requests to themselves
256-
*/
257-
const assignFeedBackToMentor = async (req, res) => {
258-
try {
259-
const { feedbackrequestId } = req.params;
260-
const { authToken } = req.cookies;
261-
const { id } = jwt.verify(authToken, process.env.JWT_SECRET);
262-
263-
// Check if the user is a mentor
264-
const isMentor = await User.findOne({
265-
where: {
266-
id: id,
267-
mentor: true,
268-
},
269-
});
270-
271-
if (!isMentor) {
272-
logger.error(`Unauthorized user`, {log: JSON.stringify(isMentor)})
273-
return res.status(401).json({ msg: "Unauthorized user" });
274-
}
275-
276-
// Find the specific feedback request record based on feedbackrequestId
277-
const feedbackRecord = await FeedbackRequest.findOne({
278-
where: { id: feedbackrequestId },
279-
});
280-
281-
if (!feedbackRecord) {
282-
logger.error(`Feedback record not found`, {log: JSON.stringify(feedbackRecord)})
283-
return res.status(404).json({ msg: "Feedback record not found" });
284-
}
285-
286-
feedbackRecord.isAssigned = true;
287-
feedbackRecord.mentorId = isMentor.mentorId;
288-
feedbackRecord.whoisAssigned = isMentor.fName;
289-
await feedbackRecord.save();
290259

291-
logger.info(`Feedback assigned to mentor`, {log: JSON.stringify(feedbackRecord)})
292-
res.json({ msg: "Feedback assigned to mentor", data: feedbackRecord });
293-
} catch (err) {
294-
logger.error(`An error occurred while updating feedback`, {log: JSON.stringify(err)})
295-
res
296-
.status(500)
297-
.json({ error: "An error occurred while updating feedback" });
298-
}
299-
};
260+
//////////////////////////////////////////
261+
/* Code below here are basically controller functions
262+
for the Code leads or mentor endpoints
263+
*/
264+
///////////////////////////////////////////////
300265

301266
/*This controller retrieves all the assigned Feedback Requests
302267
of the code lead logged in.
@@ -422,7 +387,7 @@ module.exports = {
422387
submitFeedBack,
423388
getAllFeedBackRequestsForms,
424389
getUserFeedBackRequestForms,
425-
assignFeedBackToMentor,
390+
assignFeedBack,
426391
addFeedBack,
427392
getAssignedFeedBacks,
428393
getMentorFeedback,

Controllers/userController.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Users = db.User;
88
const ExerciseInfo = db.ExerciseInfo;
99
const FeedbackRequest = db.FeedbackRequest;
1010
const Feedbacks = db.Feedbacks;
11-
const Mentors = db.Mentors;
11+
const Mentors = require("../admin.json");
1212
const loginValidator = require("../utility/inputValidator/loginValidator");
1313
const registerValidator = require("../utility/inputValidator/registerValidator");
1414
const logger = require("../utility/logger/logger");
@@ -18,8 +18,9 @@ const registerUser = async (req, res) => {
1818
const { fName, userName, password } = req.body;
1919
const { errors, validationCheck } = registerValidator(req.body);
2020
const isUserExist = await Users.findOne({ where: { username: userName } });
21-
const isMentorEmail = await Mentors.findOne({ where: { email: userName } });
22-
const isUserMentor = !!isMentorEmail;
21+
22+
//Check if the user should be a mentor based on the email
23+
const isMentor = Mentors.Mentors.include(userName);
2324
const { v4: uuidv4 } = require("uuid");
2425

2526
// This checks that the inputs entered meet some criteria
@@ -48,8 +49,8 @@ const registerUser = async (req, res) => {
4849
fName: fName,
4950
username: userName,
5051
password: hashedPassword,
51-
mentor: isUserMentor,
52-
mentorId: isUserMentor ? uuidv4() : null,
52+
mentor: isMentor,
53+
mentorId: isMentor ? uuidv4() : null,
5354
};
5455

5556
await Users.create(userData);

Models/Mentors.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

Models/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const FeedbackRequest = require("./Feedbackrequest")(sequelize, DataTypes);
1212
const Feedbacks = require("./Feedbacks")(sequelize, DataTypes);
1313
const Otptoken = require("./Otptoken")(sequelize, DataTypes);
1414
const ExerciseInfo = require("./ExerciseInfo")(sequelize, DataTypes);
15-
const Mentors = require("./Mentors")(sequelize, DataTypes);
1615

1716

1817
//This was poorly desgined. Should spent more time fixing this
@@ -58,5 +57,4 @@ module.exports = {
5857
Feedbacks,
5958
Otptoken,
6059
ExerciseInfo,
61-
Mentors,
6260
};

Routes/Feedback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const feedbackController = require('../Controllers/feedbackController')
66

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

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

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

admin.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Mentors":[
3+
"tamara@building-u.com",
4+
"kjgarbos@gmail.com",
5+
"gbudjeakp@gmail.com",
6+
"andrewsh190@gmail.com",
7+
"siddhanth.subramanian99@gmail.com"
8+
]
9+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "building-u-feedback-api",
3-
"version": "v3.0.0",
3+
"version": "v4.0.0",
44
"description": "This is for the server api that serves the app",
55
"main": "index.js",
66
"scripts": {

views/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "building-u-feedback",
3-
"version": "v3.0.0",
3+
"version": "v4.0.0",
44
"homepage": "https://buildingu.github.io/Building-u-feedback",
55
"type": "module",
66
"scripts": {

views/src/Pages/CreatedRequests.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function CreatedRequests(props) {
1414
return (
1515
<div>
1616
<FeedbackCard
17+
notifyMentor={true}
1718
showViewFeedback={true}
1819
data={internFeedbackRequests}
1920
pageTitle="MY FEEDBACK REQUESTS"

views/src/Pages/FeedbackQueue.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function FeedbackQueue(props) {
1515
<div>
1616
<FeedbackCard
1717
isAssign={true}
18+
showAddFeedback={true}
1819
data={feedbackData}
1920
pageTitle="FEEDBACK QUEUE"
2021
user={props.user}

0 commit comments

Comments
 (0)