Skip to content

Commit

Permalink
Merge pull request #95 from manipalutsav/feature-volunteer-entry-temp
Browse files Browse the repository at this point in the history
  • Loading branch information
abhikpai authored Mar 1, 2024
2 parents f36742a + e92105d commit 274358f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 40 deletions.
35 changes: 15 additions & 20 deletions src/controllers/coreVolunteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ exports.addVolunteer = async (req, res) => {
throw response(403, `User does not have permission to add volunteers, required [1,4,8] provided: ${req.user.type}`);
}

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
// throw response(403, "User cannot add volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
throw response(403, "User cannot add volunteer of another college.");
}

let checkVolunteer = await CoreVolunteerModel.findOne({ registerNumber });
if (checkVolunteer) {
Expand Down Expand Up @@ -70,10 +69,9 @@ exports.updateVolunteer = async (req, res) => {
throw Error("User does not have permission to update volunteers");
}

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
// throw Error("User cannot update volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
throw Error("User cannot update volunteer of another college.");
}

volunteer.name = name;
volunteer.registerNumber = registerNumber;
Expand Down Expand Up @@ -109,10 +107,9 @@ exports.deleteVolunteer = async (req, res) => {
throw Error("User does not have permission to delete volunteers");
}

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != volunteer.collegeId) {
// throw Error("User cannot remove volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != volunteer.collegeId) {
throw Error("User cannot remove volunteer of another college.");
}

let deleted = await Deleted.create({
schema: "CoreVolunteer",
Expand Down Expand Up @@ -147,10 +144,9 @@ exports.getVolunteer = async (req, res) => {

let filterOptions = { _id: id };

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type)) {
// filterOptions = { ...filterOptions, collegeId: req.user.college };
// }
if ([4, 8].includes(req.user.type)) {
filterOptions = { ...filterOptions, collegeId: req.user.college };
}

let volunteer = await CoreVolunteerModel.findOne(filterOptions);
if (!volunteer) {
Expand All @@ -173,10 +169,9 @@ exports.getVolunteers = async (req, res) => {

let filterOptions = {};

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type)) {
// filterOptions = { collegeId: req.user.college };
// }
if ([4, 8].includes(req.user.type)) {
filterOptions = { collegeId: req.user.college };
}

let volunteers = await CoreVolunteerModel.find(filterOptions);

Expand Down
35 changes: 15 additions & 20 deletions src/controllers/volunteers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ exports.addVolunteer = async (req, res) => {
throw response(403, `User does not have permission to add volunteers, required [1,4,8] provided: ${req.user.type}`);
}

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
// throw response(403, "User cannot add volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
throw response(403, "User cannot add volunteer of another college.");
}

let checkVolunteer = await VolunteerModel.findOne({ registerNumber, type });
if (checkVolunteer) {
Expand Down Expand Up @@ -78,10 +77,9 @@ exports.updateVolunteer = async (req, res) => {
throw Error("User does not have permission to update volunteers");
}

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
// throw Error("User cannot update volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != collegeId) {
throw Error("User cannot update volunteer of another college.");
}

volunteer.name = name;
volunteer.registerNumber = registerNumber;
Expand Down Expand Up @@ -117,10 +115,9 @@ exports.deleteVolunteer = async (req, res) => {
if (![1, 4, 8].includes(req.user.type)) {
throw Error("User does not have permission to delete volunteers");
}
// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type) && req.user.college != volunteer.collegeId) {
// throw Error("User cannot remove volunteer of another college.");
// }
if ([4, 8].includes(req.user.type) && req.user.college != volunteer.collegeId) {
throw Error("User cannot remove volunteer of another college.");
}

let deleted = await Deleted.create({
schema: "CoreVolunteer",
Expand Down Expand Up @@ -155,10 +152,9 @@ exports.getVolunteer = async (req, res) => {

let filterOptions = { _id: id };

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type)) {
// filterOptions = { ...filterOptions, collegeId: req.user.college };
// }
if ([4, 8].includes(req.user.type)) {
filterOptions = { ...filterOptions, collegeId: req.user.college };
}

let volunteer = await VolunteerModel.findOne(filterOptions);
if (!volunteer) {
Expand All @@ -185,10 +181,9 @@ exports.getVolunteers = async (req, res) => {

let filterOptions = { type };

// TODO: Re-enable it later
// if ([4, 8].includes(req.user.type)) {
// filterOptions = { ...filterOptions, collegeId: req.user.college };
// }
if ([4, 8].includes(req.user.type)) {
filterOptions = { ...filterOptions, collegeId: req.user.college };
}

let volunteers = await VolunteerModel.find(filterOptions);

Expand Down

0 comments on commit 274358f

Please sign in to comment.