Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
backend.crud: add updating and deleting operations for members, fix #22
Browse files Browse the repository at this point in the history
  • Loading branch information
furkansimsekli committed Oct 27, 2022
1 parent 3a53441 commit dfbcf17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
38 changes: 25 additions & 13 deletions controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,24 @@ const enroll = async (req, res) => {
}
}

if (!oldMember) {
const newMember = {
firstName: req.body.firstName,
lastName: req.body.lastName,
studentID: req.body.studentID,
degree: req.body.degree,
email: req.body.email,
department: req.body.department,
mobileNumber: req.body.mobileNumber,
groupChat: req.body.groupChat
}
const newMember = {
firstName: req.body.firstName,
lastName: req.body.lastName,
studentID: req.body.studentID,
degree: req.body.degree,
email: req.body.email,
department: req.body.department,
mobileNumber: req.body.mobileNumber,
groupChat: req.body.groupChat
}

if (!oldMember) {
await Member.insertMany(newMember);
res.redirect('/welcome');
} else {
await Member.findOneAndUpdate({ studentID: req.body.studentID }, newMember, { runValidators: true, new: true })
res.render(boilerplate, { page: "../success" });
}

res.redirect('/welcome');
}

const contact = async (req, res) => {
Expand Down Expand Up @@ -216,6 +218,15 @@ const deleteFaq = async (req, res) => {
}
}

const deleteMember = async (req, res) => {
if (req.body.auth === process.env.AUTH_KEY) {
await Member.findOneAndDelete({ studentID: req.body.studentID });
res.sendStatus(200);
} else {
res.sendStatus(401);
}
}

const updateEvent = async (req, res) => {
if (req.body.auth === process.env.AUTH_KEY) {
const event = {
Expand Down Expand Up @@ -325,6 +336,7 @@ module.exports = {
deleteCourse,
deleteProject,
deleteFaq,
deleteMember,
updateEvent,
updateCourse,
updateProject,
Expand Down
1 change: 1 addition & 0 deletions routes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ router.delete('/event', controller.deleteEvent);
router.delete('/course', controller.deleteCourse);
router.delete('/arge', controller.deleteProject);
router.delete('/faq', controller.deleteFaq);
router.delete('/members', controller.deleteMember);

router.patch('/event', controller.updateEvent);
router.patch('/course', controller.updateCourse);
Expand Down

0 comments on commit dfbcf17

Please sign in to comment.