Boa noite, tenho um projeto desenvolvido em nodejs, onde, para filtrar os dados para gerar os gráficos, tenho a seguinte as seguintes querys:
countTotalSexo: function (req, res) {
var query = "select answer.lookItUpType,
answer.sexo as name, count(*) as y from answer join collectedanswer on answer.answerFrom =
collectedanswer.id join question on answer.question =
question.id where answer.lookItUpType = 'sexo' and question.cidadeId="
+req.param('cidadeId')+" group by
answer.sexo";
Answer.query(query,
function (err, results) {
return
res.json(results);
}
);
},
countTypeInt: function (req, res) {
var query = "Select alternative.description as name, answer.question, (select avg(answer.Valueint) from answer where answer.alternative =
alternative.id) as y, (Select
question.title from question where answer.question =
question.id ) as label from alternative join answer on answer.alternative =
alternative.id join question on answer.question =
question.id WHERE answer.lookItUpType ='int' AND question.cidadeId="
+req.param('cidadeId')+" group by alternative.description,answer.question order by answer.question, answer.alternative";
Answer.query(query,
function (err, results) {
return
res.json(results);
}
);
},
countTypeBool: function (req, res) {
var query = "select question, alternative, count(valueBool) as y, (Select alternative.description from alternative where
alternative.id= alternative) as name ,(Select
question.title from question where answer.question =
question.id) as label from answer join question ON
question.id = answer.question where lookItUpType = 'bool' and valueBool =1 and question.cidadeId ="
+req.param('cidadeId')+" group by alternative";
Answer.query(query,
function (err, results) {
return
res.json(results);
}
);
},
Porém, eu gostaria de deixar ela, por questão de facilitar nos filtros por data, bairro, etc que elas ficassem parecidas com as que eu vou enviar abaixo. As tabelas deverão ser associadas.
FindAll: function (req, res) {
var dateInterval =
req.param('intervalDate'),
start = "",
end = "";
var queryCollected =
CollectedAnswer.find();
queryCollected.where(req.param('conditional'));
if (dateInterval) {
start = dateInterval['start'];
end = dateInterval['end'];
queryCollected.where({"date" : {">" : new Date(start), "<" : new Date(end)}});
}
if (
req.param('street'))
queryCollected.where({"endereco" : {"like" : "%" +
req.param('street') + "%"}});
if (
req.param('order'))
queryCollected.sort('date ' +
req.param('order') + '');
queryCollected.then(function(response){
return
res.json(response);
});
},
Prazo de Entrega: Não estabelecido