Skip to content
Snippets Groups Projects
state.js 812 B
const express = require('express');

const stateApp = express();

const libs = `${process.cwd()}/libs`;

const squel = require('squel');

const query = require(`${libs}/middlewares/query`);

const response = require(`${libs}/middlewares/response`);

stateApp.get('/', (req, res, next) => {
    req.query = squel.select().from('estados').toParam();
    next();
}, query, response);

stateApp.get('/:id', (req, res, next) => {
    req.query = squel.select().from('estados').where('pk_estado_id = ?',
        parseInt(req.params.id, 10)).toParam();
    next();
}, query, response);

stateApp.get('/region/:id', (req, res, next) => {
    req.query = squel.select().from('estados').where('fk_regiao_id = ?',
        parseInt(req.params.id, 10)).toParam();
    next();
}, query, response);

module.exports = stateApp;