diff --git a/controllers/question.js b/controllers/question.js index 28ccbba..65295e3 100644 --- a/controllers/question.js +++ b/controllers/question.js @@ -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 { diff --git a/models/question.js b/models/question.js index 55aad79..7d999eb 100644 --- a/models/question.js +++ b/models/question.js @@ -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; " + diff --git a/routes/v1/question.js b/routes/v1/question.js index b5d3370..630b0a5 100644 --- a/routes/v1/question.js +++ b/routes/v1/question.js @@ -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',