Skip to content

Commit

Permalink
answer validations added
Browse files Browse the repository at this point in the history
  • Loading branch information
eferhatg committed Apr 20, 2016
1 parent 045bb79 commit 72505d2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 25 deletions.
15 changes: 8 additions & 7 deletions controllers/answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

var Boom = require('boom');
var AnswerModel = require('../models/answer');
var QuestionModel = require('../models/question');
var async = require('async');


function AnswerController(db) {
this.answerModel = new AnswerModel(db);
this.questionModel = new QuestionModel(db);
};

AnswerController.prototype.answer = function(request, reply) {
Expand All @@ -24,19 +26,18 @@ AnswerController.prototype.answer = function(request, reply) {
newAnswer.user_id = request.payload.user_id;
newAnswer.text = request.payload.text;
newAnswer.client_id = request.payload.client_id;



self.answerModel.answer(newAnswer, function(answered) {
callback(null,answered);

});

},
function(user_data, callback) {
//question düzenle
},
function(user_data, callback) {
//user'i düzenle
function(answer, callback) {
this.questionModel.increaseStats(answer, function(answered) {
callback(null,answer);

});
}
], function(err, result) {
if (!result || err) {
Expand Down
42 changes: 24 additions & 18 deletions models/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,32 @@ QuestionModel.prototype.fetchQuestions = function(app, cb) {
});
};

QuestionModel.prototype.increaseStats = function(answer,cb) {


switch(answer.option) {
case 'a':
code block
break;
case 'b':
code block
break;
case 's':
code block
break;
default:
default code block
}
QuestionModel.prototype.increaseStats = function(answer, cb) {

this.questionSchema.findAll().then(function(questions) {
cb(questions);

this.questionSchema.increment()

var incrementField = 'skip_count';

switch (answer.option) {
case 'a':
incrementField = 'option_a_count';
break;
case 'b':
incrementField = 'option_b_count';
break;
case 's':
incrementField = 'skip_count';
break;
default:
incrementField = 'skip_count';
break;

}
this.questionSchema.increment(incrementField).then(function() {
cb('OK');
});

};


Expand Down

0 comments on commit 72505d2

Please sign in to comment.