Skip to content

Commit

Permalink
empty again
Browse files Browse the repository at this point in the history
  • Loading branch information
eferhatg committed Apr 26, 2016
1 parent 908597f commit d28e918
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
11 changes: 10 additions & 1 deletion controllers/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ QuestionController.prototype.all = function(request, reply) {

// [GET] /tasks/{id}
QuestionController.prototype.userquestions = function(request, reply) {
//questions

this.questionModel.userquestions(request.query.user_id, request.query.limit,function(data) {
reply({
data: {
"count": data.length,
"rows": data
}
});
});

};
QuestionController.prototype.fetch = function(request, reply) {
try {
Expand Down
12 changes: 12 additions & 0 deletions models/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ QuestionModel.prototype.showAllQuestions = function(cb) {

};

QuestionModel.prototype.userQuestions = function(user_id,limit,cb) {

this.questionSchema.findAll({
where: { user_id: user_id },
limit:limit,
is_deleted:false
}).then(function(questions) {
cb(questions);
});

};

QuestionModel.prototype.fetchQuestions = function(app, limit, user_id, installation_id, cb) {

var rawQuery = "DROP TABLE IF EXISTS tempUserQuestionTable; " +
Expand Down
60 changes: 60 additions & 0 deletions routes/v1/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,66 @@ exports.register = function(server, options, next) {
}
}
}
},{
method: 'POST',
path: '/v1/question',
config: {
description: 'Add question route for both application',
tags: ['api', 'question', 'add'],
notes: ['Referandum uygulamasından data post ederken **option_a** ve **option_b** parametrelerini göndermenize gerek yok.',
'Kapıştır uygulamasından data post ederken **question_text** ve **question_image** parametrelerini göndermenize gerek yok.',
'Success durumunda verilen response hata durumunda statusCode 200 den farklı olarak dünüyor.',
'İsteğin başarımını response status code dan anlayabilirsiniz. Dönen dataya bakmaya gerek yok.',
'Headerlar zorunlu.'
],

handler: questionController.addQuestion,
validate: {
payload: Joi.object().keys({
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'),
}),
headers: Joi.object({
'x-voter-client-id': Joi.string().required().description('Her app için farklı olacak.'),
'x-voter-version': Joi.string().required().description('Versiyon - Mobil uygulama versiyonu.'),
'x-voter-installation': Joi.string().required().description('Her installation için farklı bir id olacak.'),
}).unknown()
},
plugins: {
'hapi-swagger': {
responses: {
'200': {
'description': 'Response success örneği, aynı object hata durumunda da dönüyor.',
'schema': Joi.object({
statusCode: 200,
error: null,
message: "success",
timestamp: Date.now(),
data: {
"id": "5d3e2860-d8d0-11e5-9d43-8948e35a3da2",
"option_a_count": 0,
"option_b_count": 0,
"skip_count": 0,
"created_at": "2016-02-21T19:21:53.000Z",
"updated_at": "2016-02-21T19:21:53.000Z",
"is_deleted": false,
"user_id": "user_id",
"app": 0,
"question_text": "Bu pantolon güzel mi?",
"question_image": "http://cdn1.lcwaikiki.com/ProductImages/20152/3/2418450/M_20152-5K8893Z6-2B0_A.jpg",
"option_b": "hayir",
"option_a": "evet"
}
}).label('Result')
}
}
}
}
}
}, {
method: 'POST',
path: '/v1/question/image',
Expand Down

0 comments on commit d28e918

Please sign in to comment.