Skip to content

Commit

Permalink
Updated Question's router and renamed init method of Question model t…
Browse files Browse the repository at this point in the history
…o initialize
  • Loading branch information
nishant-jain-94 committed Oct 30, 2017
1 parent 305ca63 commit a519108
Show file tree
Hide file tree
Showing 6 changed files with 178 additions and 8 deletions.
169 changes: 167 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"express": "^4.16.2",
"json-diff-rfc6902": "^1.3.3",
"mongoose": "^4.12.4",
"simple-neo4j-wrapper": "^1.0.5",
"sinon": "^4.0.1"
},
"devDependencies": {
Expand All @@ -28,7 +29,7 @@
"supertest": "^3.0.0"
},
"engines": {
"node": "8.6.0"
"node": "8.6.0"
},
"scripts": {
"start": "node bin/www.js",
Expand Down
2 changes: 1 addition & 1 deletion question/question.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const historyController = require('../history/history.controller');

// Initialize an empty question in a Question and History collection
const initQuestion = async () => {
const initializedQuestion = await Question.init();
const initializedQuestion = await Question.initialize();
return initializedQuestion;
};

Expand Down
2 changes: 1 addition & 1 deletion question/question.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const questionSchema = new Schema({

questionSchema.set('toJSON', { getters: true, hide: '_id' });

questionSchema.statics.init = async function init() {
questionSchema.statics.initialize = async function init() {
const question = new this();
const initializedQuestion = await question.save();
return initializedQuestion.toJSON();
Expand Down
6 changes: 5 additions & 1 deletion question/question.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ router.get('/initialize', async (req, res) => {
res.json(initializedQuestion);
});

router.get('/published', async (req, res) => {
const publishedQuestions = await questionController.fetchAllQuestions();
res.json(publishedQuestions);
});

router.get('/:questionId', async (req, res) => {
const fetchedQuestions = await questionController.fetchQuestion(req.params.questionId);
res.json(fetchedQuestions);
});


module.exports = router;
4 changes: 2 additions & 2 deletions question/test/question.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe('Question Model\'s', () => {
});

it('Should initialize a question using init method', async () => {
const initializedEmptyQuestion = await Question.init();
const initializedEmptyQuestion = await Question.initialize();
should.exist(initializedEmptyQuestion);
});

it('Should patch a question object using patch method', async () => {
const initializedEmptyQuestion = await Question.init();
const initializedEmptyQuestion = await Question.initialize();
initializedEmptyQuestion.question.rawMdQuestion = '# Question';
const patchedQuestion = await Question.patch(initializedEmptyQuestion);
should.exist(patchedQuestion);
Expand Down

0 comments on commit a519108

Please sign in to comment.