Skip to content

Commit

Permalink
#120 super admin - allow post questionnaire response to go through
Browse files Browse the repository at this point in the history
  • Loading branch information
mtw812 committed Jul 28, 2021
1 parent 4c8fa3a commit facd827
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions backend/routes/questionnaireResponses.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ const ObjectID = require('mongodb').ObjectID;
const emailContents = require('../routes/sendEmail/emailContent.js');
const senderEmail = process.env.SENDER_EMAIL;

//TODO: revisit access control
router.route('/add').post((req, res) => {
const title = req.body.title;
const language = req.body.language;
const questionnaireResponse = req.body.questionnaireResponse;
const newQuestionnaireResponse = new QuestionnaireResponse({
title,
language,
questionnaireResponse,
});

newQuestionnaireResponse
.save()
.then(() => {
res.json('QuestionnaireResponse response added');
})
.catch((err) => console.log(err));
});

const auth = require('../middleware/auth');
router.use(auth); //all apis AFTER this line will require authentication as implemented in auth.js

const getAllResponses = () => {
return QuestionnaireResponse.find({
$or: [
Expand All @@ -24,9 +46,6 @@ const getResponsesForAdmin = (admin) => {
]});
};

const auth = require('../middleware/auth');
router.use(auth); //all apis AFTER this line will require authentication as implemented in auth.js

router.route('/').get((req, res) => {
const getResponses = req.user.issuper ? getAllResponses(): getResponsesForAdmin(req.user);

Expand Down Expand Up @@ -219,25 +238,6 @@ router.route('/:id').get((req, res) => {
.catch((err) => console.log(err));
});

//TODO: move to before router.use(auth)?
router.route('/add').post((req, res) => {
const title = req.body.title;
const language = req.body.language;
const questionnaireResponse = req.body.questionnaireResponse;
const newQuestionnaireResponse = new QuestionnaireResponse({
title,
language,
questionnaireResponse,
});

newQuestionnaireResponse
.save()
.then(() => {
res.json('QuestionnaireResponse response added');
})
.catch((err) => console.log(err));
});

router.route('/:id').delete((req, res) => {
QuestionnaireResponse.findByIdAndDelete(req.params.id)
.then((users) => res.json('questionnaire response Deleted'))
Expand Down

0 comments on commit facd827

Please sign in to comment.