-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1144154
commit 6f269ad
Showing
9 changed files
with
2,364 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "server", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"cors": "^2.8.5", | ||
"dotenv": "^8.2.0", | ||
"express": "^4.17.1", | ||
"express-promise-router": "^3.0.3", | ||
"mssql": "^6.2.0", | ||
"nodemon": "^2.0.4", | ||
"pg": "^8.2.1", | ||
"sequelize": "^5.21.11", | ||
"tedious": "^8.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Arquivo: app.js | ||
* Descrição: arquivo responsável por toda a configuração da aplicação. | ||
*/ | ||
|
||
const express = require('express'); | ||
const cors = require('cors'); | ||
|
||
const app = express(); | ||
|
||
// ==> Rotas da API: | ||
const licitacoesRoute = require('./routes/licitacoes.routes'); | ||
|
||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use(express.json({ type: 'application/vnd.api+json' })); | ||
app.use(cors()); | ||
|
||
app.use('/api/', licitacoesRoute); | ||
|
||
module.exports = app; | ||
|
||
const port = 3000; | ||
|
||
app.listen(port, () => { | ||
console.log('Aplicação executando na porta ', port); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Arquivo: config/credentials.js | ||
* Descrição: arquivo responsável por recuperar as configurações de | ||
* cada banco de dados utilizado. | ||
*/ | ||
|
||
const path = require('path') | ||
// Define o caminho para o .env inicial | ||
require('dotenv').config({ path: path.resolve(__dirname, '../../.env') }); | ||
|
||
// configurações dos bancos de dados | ||
module.exports = { | ||
SAGRES: { | ||
username: process.env.SQLSERVER_SAGRES19_USER, | ||
host: process.env.SQLSERVER_SAGRES19_HOST, | ||
database: process.env.SQLSERVER_SAGRES19_Database, | ||
password: process.env.SQLSERVER_SAGRES19_PASS, | ||
port: parseInt(process.env.SQLSERVER_SAGRES19_PORT), | ||
driver: 'tedious', | ||
stream: false, | ||
dialect: 'mssql', | ||
options: { | ||
trustedConnection: true, | ||
encrypt: false, | ||
enableArithAbort: true | ||
} | ||
} //, AL_DB {...} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Arquivo: config/db.config.js | ||
* Descrição: arquivo responsável por criar a conexão com o banco de dados. | ||
*/ | ||
|
||
const { Sequelize } = require('sequelize'); | ||
const { SAGRES } = require("./credentials"); | ||
|
||
/** Adiciona as configurações específicas de um banco. Caso seja necessário mudar | ||
o BD basta alterar o parâmetro do Sequelize. | ||
*/ | ||
const sequelize = new Sequelize(SAGRES) | ||
|
||
// Testa se a conexão foi estabelecida | ||
run().catch(error => console.log(error.stack)); | ||
async function run() { | ||
try { | ||
await sequelize.authenticate(); | ||
console.log('Conexão estabelecida com o banco de dados ', SAGRES.database); | ||
} catch (error) { | ||
console.error('Não foi possível conectar-se ao banco de dados:', error); | ||
} | ||
} | ||
|
||
module.exports = { | ||
sequelize | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Arquivo: controllers/licitacoes.controller.js | ||
* Descrição: arquivo responsável por recuperar informações relacionadas as | ||
* licitações. | ||
*/ | ||
|
||
const models = require("../models/index.model"); | ||
const Licitacao = models.licitacao; | ||
const Op = models.Sequelize.Op; | ||
|
||
const BAD_REQUEST = 400; | ||
const SUCCESS = 200; | ||
|
||
// Retorna as 10 primeiras licitações (terá mudanças) | ||
exports.getLicitacoes = async (req, res) => { | ||
Licitacao.findAll({limit: 100, where: { de_Obs: { [Op.ne]: null } }}) | ||
.then(licitacoes => res.status(SUCCESS).json(licitacoes)) | ||
.catch(err => res.status(BAD_REQUEST).json({ err })); | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* Arquivo: models/index.model.js | ||
* Descrição: arquivo responsável por importar os modelos com o sequelize. | ||
*/ | ||
|
||
const Sequelize = require("sequelize"); | ||
const { sequelize } = require("../config/db.config"); | ||
|
||
const LicitacaoModel = "./licitacao.model.js"; | ||
|
||
global.models = { | ||
Sequelize: Sequelize, | ||
sequelize: sequelize, | ||
// Adicione os módulos abaixo | ||
licitacao: sequelize.import(LicitacaoModel), | ||
|
||
}; | ||
|
||
module.exports = global.models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Arquivo: models/index.model.js | ||
* Descrição: arquivo com o modelo da licitacao. | ||
*/ | ||
|
||
module.exports = (sequelize, type) => { | ||
Licitacao = sequelize.define( | ||
"Licitacao", | ||
{ | ||
nu_licitacao: { // deixei este como PK por enquanto | ||
type: type.STRING, | ||
primaryKey: true | ||
}, | ||
cd_UGestora: type.INTEGER, | ||
vl_licitacao: type.INTEGER, | ||
de_Obs: type.STRING, | ||
}, | ||
{ | ||
freezeTableName: true, | ||
timestamps: false | ||
} | ||
); | ||
|
||
return Licitacao; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Arquivo: src/routes/licitacoes.routes.js | ||
* Descrição: arquivo responsável pelas rotas da api relacionadas a classe 'Licitacoes'. | ||
*/ | ||
|
||
const router = require('express-promise-router')(); | ||
const licitacoesController = require('../controllers/licitacoes.controller'); | ||
|
||
// Retrieve all Customers | ||
// Example: http://localhost:3000/api/licitacoes | ||
router.get('/licitacoes', licitacoesController.getLicitacoes) | ||
|
||
module.exports = router; |