Skip to content

Commit

Permalink
answer
Browse files Browse the repository at this point in the history
  • Loading branch information
eferhatg committed Apr 20, 2016
1 parent d9f23d4 commit 045bb79
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 23 deletions.
50 changes: 36 additions & 14 deletions controllers/answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,42 @@ function AnswerController(db) {
};

AnswerController.prototype.answer = function(request, reply) {
try {


/*
Bu kısımda yapılacaklar:
1- userId'sini güncelle installation_id'nin
2- answer create
3- question'ın count'unu düzenle
*/

// this.answerModel.answer();
try {

var self = this;

async.waterfall([
function(callback) {

var newAnswer = {};
newAnswer.installation_id = request.headers['x-voter-installation'];
newAnswer.option = request.payload.option;
newAnswer.question_id = request.payload.question_id;
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(err, result) {
if (!result || err) {
reply(Boom.badImplementation(JSON.stringify(err)));
return;
} else {
reply({ data: result });
}
});

} catch (e) {
reply(Boom.badRequest(e.message));
Expand Down
23 changes: 23 additions & 0 deletions models/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,27 @@ 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
}

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


module.exports = QuestionModel;
15 changes: 6 additions & 9 deletions routes/v1/answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ exports.register = function(server, options, next) {
config: {
description: 'Answer route',
tags: ['api', 'user', 'add'],
notes: ['Answer','cevaplardan'
],
notes: ['Answer','cevaplardan'],
handler: answerController.answer,
validate: {
payload: Joi.object().keys({
installation_id: Joi.string().required().description('installation_id veya imei'),
option:Joi.string().required().description('installation_id veya imei'),
question_text: Joi.when('app', { is: 0, then: Joi.required() }).description('Soru metni'),
question_image: Joi.when('app', { is: 0, then: Joi.required() }).description('Soru resim linki'),
user_id: Joi.string().required().description('User id'),
app: Joi.number().min(0).max(1).required().description('App referandum için 0, kapistir için 1'),
option_a: Joi.when('app', { is: 1, then: Joi.required() }).description('A şıkkı metni ya da resim linki'),
option_b: Joi.when('app', { is: 1, then: Joi.required() }).description('B şıkkı metni ya da resim linki'),
option:Joi.string().required().description(' soldaki "a" sağdaki "b" skip "s" '),
question_id:Joi.string().required().description('question_id'),
user_id:Joi.string().required().description('user_id'),
text:Joi.string().required().description('answer text or image link'),
client_id:Joi.string().required().description('kapistir için 1 referandum için 0')
}),
headers: Joi.object({
'x-voter-client-id': Joi.string().required().description('Her app için farklı olacak.'),
Expand Down

0 comments on commit 045bb79

Please sign in to comment.