Skip to content
Snippets Groups Projects
Commit 88921f01 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Merge branch 'development' into feature_teacher_route

Conflicts:
	src/libs/middlewares/id2str.js
parents 550611f6 58d9b4cd
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!50Feature teacher route
Pipeline #
module.exports = function agreement(id) {
switch (id) {
case 1:
return 'Estadual';
case 2:
return 'Municipal';
case 3:
return 'Estadual e Municipal';
default:
return 'Não declarada';
}
};
module.exports = function admDependency(id) { module.exports = function booleanVariable(id) {
if (id == null) if (id == null)
return 'Não Disponível'; return 'Não Declarado';
else if (id == false) else if (id == false)
return 'Não'; return 'Não';
else if (id == true) else if (id == true)
......
...@@ -5,6 +5,7 @@ const schoolYear = require(`${libs}/convert/schoolYear`); ...@@ -5,6 +5,7 @@ const schoolYear = require(`${libs}/convert/schoolYear`);
const admDependency = require(`${libs}/convert/admDependency`); const admDependency = require(`${libs}/convert/admDependency`);
const location = require(`${libs}/convert/location`); const location = require(`${libs}/convert/location`);
const ethnicGroup = require(`${libs}/convert/ethnicGroup`); const ethnicGroup = require(`${libs}/convert/ethnicGroup`);
const agreement = require(`${libs}/convert/agreement`);
const booleanVariable = require(`${libs}/convert/booleanVariable`); const booleanVariable = require(`${libs}/convert/booleanVariable`);
const educationLevel = require(`${libs}/convert/educationLevel`); const educationLevel = require(`${libs}/convert/educationLevel`);
const educationLevelMod = require(`${libs}/convert/educationLevelMod`); const educationLevelMod = require(`${libs}/convert/educationLevelMod`);
...@@ -20,7 +21,37 @@ const ids = { ...@@ -20,7 +21,37 @@ const ids = {
adm_dependency_detailed_id: admDependency, adm_dependency_detailed_id: admDependency,
location_id: location, location_id: location,
ethnic_group_id: ethnicGroup, ethnic_group_id: ethnicGroup,
agreement_id: agreement,
integral_time_id: booleanVariable, integral_time_id: booleanVariable,
government_agreement_id: booleanVariable,
building_school_id: booleanVariable,
informatics_lab_id: booleanVariable,
science_lab_id: booleanVariable,
directors_room_id: booleanVariable,
teacher_room_id: booleanVariable,
cook_room_id: booleanVariable,
playground_id: booleanVariable,
indor_sports_court_id: booleanVariable,
nusery_id: booleanVariable,
special_attendence_room_id: booleanVariable,
toilet_inside_building_id: booleanVariable,
denpendency_pne_id: booleanVariable,
restroom_pne_id: booleanVariable,
broadband_id: booleanVariable,
energy_id: booleanVariable,
water_id: booleanVariable,
wastepipe_id: booleanVariable,
education_day_care_child_id: booleanVariable,
education_preschool_child_id: booleanVariable,
education_begin_elementary_school_id: booleanVariable,
education_end_elementary_school_id: booleanVariable,
education_middle_school_id: booleanVariable,
education_professional_id: booleanVariable,
education_eja_id: booleanVariable,
library_reading_room_id: booleanVariable,
library_id: booleanVariable,
reading_room_id: booleanVariable,
water_id: booleanVariable,
education_type_id: educationType education_type_id: educationType
}; };
...@@ -48,6 +79,7 @@ module.exports = { ...@@ -48,6 +79,7 @@ module.exports = {
admDependency, admDependency,
location, location,
ethnicGroup, ethnicGroup,
agreement,
booleanVariable, booleanVariable,
educationLevel, educationLevel,
educationLevelMod, educationLevelMod,
......
...@@ -210,24 +210,55 @@ class ReqQueryFields { ...@@ -210,24 +210,55 @@ class ReqQueryFields {
// Se o valor é um campo a ser incluído no SELECT // Se o valor é um campo a ser incluído no SELECT
if(typeof field.field !== 'undefined' && field.field) { if(typeof field.field !== 'undefined' && field.field) {
log.debug('SELECT'); log.debug('SELECT');
req.sql.field(value.table+'.'+value.tableField, value.resultField || value.tableField) if (Array.isArray(value.resultField)) {
.group(value.table+'.'+value.tableField) value.tableField.forEach((f, i) => {
.order(value.table+'.'+value.tableField); req.sql.field(value.table+'.'+f, value.resultField[i] || f)
.group(value.table+'.'+f);
})
}else{
req.sql.field(value.table+'.'+value.tableField, value.resultField || value.tableField)
.group(value.table+'.'+value.tableField);
}
} }
// Se o valor é um campo para ser usado no WHERE // Se o valor é um campo para ser usado no WHERE
if(typeof field.where !== 'undefined' && field.where) { if(typeof field.where !== 'undefined' && field.where) {
log.debug('WHERE'); log.debug('WHERE');
// Valor do where // Valor do where
let whereValue = param[k]; let whereValue = param[k];
// Valor sempre vem como string, necessário fazer parse para o banco // Valor sempre vem como string, necessário fazer parse para o banco
if(value.where.type === 'integer') whereValue = parseInt(whereValue, 10); if(value.where.type === 'integer') whereValue = parseInt(whereValue, 10);
if(value.where.type === 'double') whereValue = parseFloat(whereValue); if(value.where.type === 'double') whereValue = parseFloat(whereValue);
if(value.where.type === 'string') whereValue = '%'+whereValue+'%'; if(value.where.type === 'string') whereValue = '%'+whereValue+'%';
if(value.where.type === 'boolean') whereValue = (whereValue.toLowerCase() === 'true' || parseInt(whereValue, 10) === 1); if(value.where.type === 'boolean') {
if (whereValue.toLowerCase() === 'null') {
whereValue = null;
console.log('Fazendo uma consulta Null');
} else {
whereValue = (whereValue.toLowerCase() === 'true' || parseInt(whereValue, 10) === 1);
console.log('Fazendo uma consulta True');
}
}
let tbl = value.where.table || value.table; let tbl = value.where.table || value.table;
let whereField = (value.where.type === 'string')? 'LOWER('+tbl+'.'+value.where.field+')' : tbl+'.'+value.where.field; // multiple where, only tested for boolean filds
let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? '; if (Array.isArray(value.tableField)) {
req.sql.where(whereField + ' ' + value.where.relation + lower, whereValue); let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? ';
let whereField = '';
let whereValues = [];
value.where.field.forEach((f, i, arr) => {
whereValues.push(whereValue);
whereField += (value.where.type === 'string') ? 'LOWER(' + tbl + '.' + value.where.field[i] + ')' : tbl + '.' + value.where.field[i];
whereField += ' ' + value.where.relation + ' ?';
if (i < arr.length - 1) {
whereField += ' ' + value.where.condition + ' ';
}
});
req.sql.where(whereField, ...whereValues);
} else {
let whereField = (value.where.type === 'string') ? 'LOWER(' + tbl + '.' + value.where.field + ')' : tbl + '.' + value.where.field;
let lower = (value.where.type === 'string') ? ' LOWER(?) ' : ' ? ';
req.sql.where(whereField + ' ' + value.where.relation + lower, whereValue);
}
} }
} }
}); });
......
...@@ -10,9 +10,305 @@ const query = require(`${libs}/middlewares/query`); ...@@ -10,9 +10,305 @@ const query = require(`${libs}/middlewares/query`);
const response = require(`${libs}/middlewares/response`); const response = require(`${libs}/middlewares/response`);
const id2str = require(`${libs}/middlewares/id2str`);
const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`); const ReqQueryFields = require(`${libs}/middlewares/reqQueryFields`);
let rqf = new ReqQueryFields(); let rqf = new ReqQueryFields();
let rqfCount = new ReqQueryFields();
// Return location
schoolApp.get('/year_range', (req, res, next) => {
req.sql.from('escola')
.field('MIN(escola.ano_censo)', 'start_year')
.field('MAX(escola.ano_censo)', 'end_year');
next();
}, query, response('range'));
schoolApp.get('/location', (req, res, next) => {
req.result = [
{id: 1, name: 'Urbana'},
{id: 2, name: 'Rural'}
];
next();
}, response('location'));
schoolApp.get('/adm_dependency', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id')
.field('nome', 'name')
.where('id <= 4');
next();
}, query, response('adm_dependency'));
schoolApp.get('/adm_dependency_detailed', (req, res, next) => {
req.sql.from('dependencia_adm')
.field('id', 'id')
.field('nome', 'name');
next();
}, query, response('adm_dependency_detailed'));
schoolApp.get('/government_agreement', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('government_agreement'));
schoolApp.get('/agreement', (req, res, next) => {
req.result = [
{id: 1, name: 'Estadual'},
{id: 2, name: 'Municipal'},
{id: 3, name: 'Estadual e Municipal'}
];
next();
}, response('agreement'));
schoolApp.get('/building_school', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('building_school'));
schoolApp.get('/informatics_lab', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('informatics_lab'));
schoolApp.get('/science_lab', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('/science_lab'));
schoolApp.get('/directors_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('directors_room'));
schoolApp.get('/teacher_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('teacher_room'));
schoolApp.get('/cook_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('cook_room'));
schoolApp.get('/playground', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('playground'));
schoolApp.get('/indor_sports_court', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('indor_sports_court'));
schoolApp.get('/nusery', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('nusery'));
schoolApp.get('/special_attendence_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('special_attendence_room'));
schoolApp.get('/toilet_inside_building', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('toilet_inside_building'));
schoolApp.get('/denpendency_pne', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('denpendency_pne'));
schoolApp.get('/restroom_pne', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('restroom_pne'));
schoolApp.get('/broadband', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('broadband'));
schoolApp.get('/energy', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('energy'));
schoolApp.get('/water', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('water'));
schoolApp.get('/wastepipe', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('wastepipe'));
schoolApp.get('/education_day_care_child', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_day_care_child'));
schoolApp.get('/education_preschool_child', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_preschool_child'));
schoolApp.get('/education_begin_elementary_school', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_begin_elementary_school'));
schoolApp.get('/education_end_elementary_school', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_end_elementary_school'));
schoolApp.get('/education_middle_school', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_middle_school'));
schoolApp.get('/education_professional', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_professional'));
schoolApp.get('/education_eja', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('education_eja'));
schoolApp.get('/library', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('library'));
schoolApp.get('/reading_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('reading_room'));
schoolApp.get('/library_reading_room', (req, res, next) => {
req.result = [
{id: null, name: 'Não Declarado'},
{id: 0, name: 'Não'},
{id: 1, name: 'Sim'}
];
next();
}, response('library_reading_room'));
rqf.addField({ rqf.addField({
name: 'filter', name: 'filter',
...@@ -72,6 +368,447 @@ rqf.addField({ ...@@ -72,6 +368,447 @@ rqf.addField({
} }
}); });
rqfCount.addField({
name: 'filter',
field: false,
where: true
}).addField({
name: 'dims',
field: true,
where: false
}).addValue({
name: 'id',
table: 'escola',
tableField: 'id',
where: {
relation: '=',
type: 'integer',
field: 'id'
}
}).addValue({
name: 'city',
table: 'municipio',
tableField: 'nome',
resultField: 'city_name',
where: {
relation: '=',
type: 'integer',
field: 'municipio_id',
table: 'escola'
},
join: {
primary: 'id',
foreign: 'municipio_id',
foreignTable: 'escola'
}
}).addValue({
name: 'state',
table: 'estado',
tableField: 'nome',
resultField: 'state_name',
where: {
relation: '=',
type: 'integer',
field: 'estado_id',
table: 'escola'
},
join: {
primary: 'id',
foreign: 'estado_id',
foreignTable: 'escola'
}
}).addValue({
name: 'region',
table: 'regiao',
tableField: 'nome',
resultField: 'region_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'regiao_id',
foreignTable: 'escola'
}
}).addValue({
name: 'year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '=',
type: 'integer',
field: 'ano_censo',
table: 'escola'
}
}).addValue({
name: 'adm_dependency',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_id',
foreignTable: 'escola'
}
}).addValue({
name: 'adm_dependency_detailed',
table: 'dependencia_adm',
tableField: 'nome',
resultField: 'adm_dependency_detailed_name',
where: {
relation: '=',
type: 'integer',
field: 'id'
},
join: {
primary: 'id',
foreign: 'dependencia_adm_priv',
foreignTable: 'escola'
}
}).addValue({
name: 'location',
table: 'escola',
tableField: 'cod_localizacao',
resultField: 'location_id',
where: {
relation: '=',
type: 'integer',
field: 'cod_localizacao'
}
}).addValue({
name: 'cook_room',
table: 'escola',
tableField: 'cozinha',
resultField: 'cook_room_id',
where: {
relation: '=',
type: 'boolean',
field: 'cozinha'
}
}).addValue({
name: 'government_agreement',
table: 'escola',
tableField: 'conveniada_pp',
resultField: 'government_agreement_id',
where: {
relation: '=',
type: 'boolean',
field: 'conveniada_pp'
}
}).addValue({
name: 'informatics_lab',
table: 'escola',
tableField: 'lab_informatica',
resultField: 'informatics_lab_id',
where: {
relation: '=',
type: 'boolean',
field: 'lab_informatica'
}
}).addValue({
name: 'science_lab',
table: 'escola',
tableField: 'lab_ciencias',
resultField: 'science_lab_id',
where: {
relation: '=',
type: 'boolean',
field: 'lab_ciencias'
}
}).addValue({
name: 'special_attendence_room',
table: 'escola',
tableField: 'sala_atendimento_especial',
resultField: 'special_attendence_room_id',
where: {
relation: '=',
type: 'boolean',
field: 'sala_atendimento_especial'
}
}).addValue({
name: 'indor_sports_court',
table: 'escola',
tableField: 'quadra_esportes_coberta',
resultField: 'indor_sports_court_id',
where: {
relation: '=',
type: 'boolean',
field: 'quadra_esportes_coberta'
}
}).addValue({
name: 'education_eja',
table: 'escola',
tableField: 'ensino_eja',
resultField: 'education_eja_id',
where: {
relation: '=',
type: 'boolean',
field: 'ensino_eja'
}
}).addValue({
name: 'education_professional',
table: 'escola',
tableField: 'educacao_profissional',
resultField: 'education_professional_id',
where: {
relation: '=',
type: 'boolean',
field: 'educacao_profissional'
}
}).addValue({
name: 'education_middle_school',
table: 'escola',
tableField: 'reg_medio_medio',
resultField: 'education_middle_school_id',
where: {
relation: '=',
type: 'boolean',
field: 'reg_medio_medio'
}
}).addValue({
name: 'education_end_elementary_school',
table: 'escola',
tableField: 'reg_fund_af',
resultField: 'education_end_elementary_school_id',
where: {
relation: '=',
type: 'boolean',
field: 'reg_fund_af'
}
}).addValue({
name: 'education_begin_elementary_school',
table: 'escola',
tableField: 'reg_fund_ai',
resultField: 'education_begin_elementary_school_id',
where: {
relation: '=',
type: 'boolean',
field: 'reg_fund_ai'
}
}).addValue({
name: 'education_preschool_child',
table: 'escola',
tableField: 'reg_infantil_preescola',
resultField: 'education_preschool_child_id',
where: {
relation: '=',
type: 'boolean',
field: 'reg_infantil_preescola'
}
}).addValue({
name: 'education_day_care_child',
table: 'escola',
tableField: 'reg_infantil_creche',
resultField: 'education_day_care_child_id',
where: {
relation: '=',
type: 'boolean',
field: 'reg_infantil_creche'
}
}).addValue({
name: 'directors_room',
table: 'escola',
tableField: 'sala_diretoria',
resultField: 'directors_room_id',
where: {
relation: '=',
type: 'boolean',
field: 'sala_diretoria'
}
}).addValue({
name: 'teacher_room',
table: 'escola',
tableField: 'sala_professor',
resultField: 'teacher_room_id',
where: {
relation: '=',
type: 'boolean',
field: 'sala_professor'
}
}).addValue({
name: 'playground',
table: 'escola',
tableField: 'parque_infantil',
resultField: 'playground_id',
where: {
relation: '=',
type: 'boolean',
field: 'parque_infantil'
}
}).addValue({
name: 'nusery',
table: 'escola',
tableField: 'bercario',
resultField: 'nusery_id',
where: {
relation: '=',
type: 'boolean',
field: 'bercario'
}
}).addValue({
name: 'toilet_inside_building',
table: 'escola',
tableField: 'sanitario_dentro_predio',
resultField: 'toilet_inside_building_id',
where: {
relation: '=',
type: 'boolean',
field: 'sanitario_dentro_predio'
}
}).addValue({
name: 'wastepipe',
table: 'escola',
tableField: 'esgoto_sanitario',
resultField: 'wastepipe_id',
where: {
relation: '=',
type: 'boolean',
field: 'esgoto_sanitario'
}
}).addValue({
name: 'water',
table: 'escola',
tableField: 'fornecimento_agua',
resultField: 'water_id',
where: {
relation: '=',
type: 'boolean',
field: 'fornecimento_agua '
}
}).addValue({
name: 'energy',
table: 'escola',
tableField: 'fornecimento_energia',
resultField: 'energy_id',
where: {
relation: '=',
type: 'boolean',
field: 'fornecimento_energia '
}
}).addValue({
name: 'broadband',
table: 'escola',
tableField: 'internet_banda_larga',
resultField: 'broadband_id',
where: {
relation: '=',
type: 'boolean',
field: 'internet_banda_larga '
}
}).addValue({
name: 'restroom_pne',
table: 'escola',
tableField: 'sanitario_pne',
resultField: 'restroom_pne_id',
where: {
relation: '=',
type: 'boolean',
field: 'sanitario_pne '
}
}).addValue({
name: 'denpendency_pne',
table: 'escola',
tableField: 'dependencias_pne',
resultField: 'denpendency_pne_id',
where: {
relation: '=',
type: 'boolean',
field: 'dependencias_pne '
}
}).addValue({
name: 'agreement',
table: 'escola',
tableField: 'tipo_convenio_pp',
resultField: 'agreement_id',
where: {
relation: '=',
type: 'integer',
field: 'tipo_convenio_pp'
}
}).addValue({
name: 'building_school',
table: 'escola',
tableField: 'local_func_predio_escolar',
resultField: 'building_school_id',
where: {
relation: '=',
type: 'boolean',
field: 'local_func_predio_escolar'
}
}).addValue({
name: 'library',
table: 'escola',
tableField: 'biblioteca',
resultField: 'library_id',
where: {
relation: '=',
type: 'boolean',
field: 'biblioteca'
}
}).addValue({
name: 'reading_room',
table: 'escola',
tableField: 'sala_leitura',
resultField: 'reading_room_id',
where: {
relation: '=',
type: 'boolean',
field: 'sala_leitura'
}
}).addValue({
name: 'library_reading_room',
table: 'escola',
tableField: 'biblioteca_sala_leitura',
resultField: 'library_reading_room_id',
where: {
relation: '=',
type: 'boolean',
condition: 'or',
field: 'biblioteca_sala_leitura'
}
}).addValue({
name: 'min_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '>=',
type: 'integer',
field: 'ano_censo'
}
}).addValue({
name: 'max_year',
table: 'escola',
tableField: 'ano_censo',
resultField: 'year',
where: {
relation: '<=',
type: 'integer',
field: 'ano_censo'
}
});
// .addValue({ //Using multiple_where
// name: 'library_reading_room',
// table: 'escola',
// tableField: ['biblioteca', 'sala_leitura', 'biblioteca_sala_leitura'],
// resultField: 'library_or_reading_room',
// where: {
// relation: '=',
// type: 'boolean',
// condition: 'or',
// field: ['biblioteca', 'sala_leitura', 'biblioteca_sala_leitura']
// }
// SELECT COUNT(escola.id) AS "total", 'Brasil' AS "name", escola.ano_censo AS "year" FROM escola WHERE (escola.biblioteca = ? OR escola.sala_leitura = ? OR escola.biblioteca_sala_leitura) AND (escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1) GROUP BY escola.ano_censo ORDER BY escola.ano_censo ASC
schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
console.log(req.filter); console.log(req.filter);
if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) { if(typeof req.filter === 'undefined' || Object.keys(req.filter).length === 0) {
...@@ -90,4 +827,16 @@ schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => { ...@@ -90,4 +827,16 @@ schoolApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
next(); next();
}, query, response('school')); }, query, response('school'));
schoolApp.get('/count', rqfCount.parse(), rqfCount.build(), (req, res, next) => {
req.sql.from('escola')
.field('COUNT(escola.id)', 'total')
.field("'Brasil'", 'name')
.field('escola.ano_censo', 'year')
.group('escola.ano_censo')
.order('escola.ano_censo')
.where('escola.situacao_de_funcionamento = 1 AND escola.ensino_regular = 1');
next();
}, query, id2str.transform(true), response('school'));
module.exports = schoolApp; module.exports = schoolApp;
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment