Commit 1c232038 authored by Glenda Train's avatar Glenda Train

Add state and city

parent b7887945
Pipeline #15658 failed with stage
in 60 minutes and 5 seconds
module.exports = function stateName(id) {
switch (id) {
case '11':
return 'Rondônia';
case '12':
return 'Acre';
case '13':
return 'Amazonas';
case '14':
return 'Roraima';
case '15':
return 'Pará';
case '16':
return 'Amapá';
case '17':
return 'Tocantins';
case '21':
return 'Maranhão';
case '22':
return'Piauí';
case '23':
return 'Ceará';
case '24':
return 'Rio Grande do Norte';
case '25':
return 'Paraíba';
case '26':
return 'Pernambuco';
case '27':
return 'Alagoas';
case '28':
return 'Sergipe';
case '29':
return 'Bahia';
case '31':
return 'Minas Gerais';
case '32':
return 'Espírito Santo';
case '33':
return 'Rio de Janeiro ';
case '35':
return 'São Paulo';
case '41':
return 'Paraná';
case '42':
return 'Santa Catarina';
case '43':
return 'Rio Grande do Sul';
case '50':
return 'Mato Grosso do Sul';
case '51':
return 'Mato Grosso';
case '52':
return 'Goiás';
case '53':
return 'Distrito Federal';
}
};
const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const xml = require('js2xmlparser');
const csv = require('csv-express');
// Custom generic middleware used respond requests.
// The function reads the req.query.format param and respond in json, xml or csv
function response(value) {
return (req, res, next) => {
if (req.query.format === 'csv') {
res.attachment(`${value}.csv`);
res.csv(req.result, true);
} else if (req.query.format === 'xml') {
res.send(xml.parse('result', { [value]: req.result }));
} else {
res.json({ result: req.result });
}
};
}
module.exports = response;
const express = require('express');
const cityApp = express();
const libs = `${process.cwd()}/libs`;
const config = require(`${libs}/config`);
const log = require(`${libs}/log`)(module);
const response = require(`${libs}/middlewares/response`);
const request = require(`request`);
cityApp.get('/', (req, res, next) => {
request.get('https://simcaq.c3sl.ufpr.br/api/v1/city', (err, response, body) => {
if(err) {
log.error(err);
return res.json({error: err});
}
res.json({result: JSON.parse(body).result});
});
});
cityApp.get('/:id', (req, res, next) => {
var url = 'https://simcaq.c3sl.ufpr.br/api/v1/city?filter=state:' + req.params.id.toString();
request.get(url, (err, response, body) => {
if(err) {
log.error(err);
return res.json({error: err});
}
res.json({result: JSON.parse(body).result});
});
});
module.exports = cityApp;
const express = require('express');
const stateApp = express();
const libs = `${process.cwd()}/libs`;
const config = require(`${libs}/config`);
const log = require(`${libs}/log`)(module);
const response = require(`${libs}/middlewares/response`);
const request = require(`request`);
const stateName = require(`${libs}/convert/stateName`);
stateApp.get('/', (req, res, next) => {
request.get('https://simcaq.c3sl.ufpr.br/api/v1/state', (err, response, body) => {
if(err) {
log.error(err);
return res.json({error: err});
}
res.json({ result: JSON.parse(body).result });
});
});
stateApp.get('/:id', (req, res, next) => {
let state = stateName(req.params.id.toString());
res.json({result: { name: state }});
});
module.exports = stateApp;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment