Skip to content

Commit a220c4c

Browse files
committed
garagem
1 parent c315d4f commit a220c4c

4 files changed

Lines changed: 52 additions & 0 deletions

File tree

src/controllers/garagem.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const { database } = require("../client/database");
2+
const { T_PT, ResponseController, httpStatus } = require("../lib");
3+
const SQL = require("../models/garagem");
4+
const { v4: uuid } = require("uuid");
5+
6+
class ExtrasController {
7+
static async getAllVeiculos(req, res) {
8+
const { idEntidade } = req.params;
9+
const { rows } = await database.query(SQL.getAll, [idEntidade]);
10+
return ResponseController(res, httpStatus.CREATED, T_PT.capturado, rows);
11+
}
12+
13+
static async createVeiculo(req, res) {
14+
const { idEntidade } = req.params;
15+
const data = req.body;
16+
const id = uuid();
17+
await database.query(SQL.createVeiculo, [
18+
id,
19+
data.NOME,
20+
data.MARCA,
21+
data.MODEDO,
22+
data.PLACA,
23+
1,
24+
idEntidade,
25+
]);
26+
return ResponseController(res, httpStatus.CREATED, T_PT.cadastrado, id);
27+
}
28+
}
29+
30+
module.exports = ExtrasController;

src/models/garagem.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
getAll: `SELECT v.id, v.nome, v.marca, v.modelo, v.placa, s.nome as status
3+
FROM VEICULOS v
4+
JOIN status_veiculo s on v.status = s.id
5+
WHERE ORGAO = $1 ORDER BY NOME ASC;`,
6+
7+
createVeiculo: `
8+
INSERT INTO VEICULO (ID, NOME, MARCA, MODELO, PLACA, STATUS, ORGAO) VALUES ($1, $2, $3, $4, $5, $6, $7);
9+
`,
10+
};

src/routes/garagem.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const router = require("express").Router();
2+
3+
const InterceptError = require("../middlewares/intercept-erros");
4+
const controller = require("../controllers/garagem");
5+
6+
router.get("/garagem/veiculos/:idEntidade", (req, res, next) =>
7+
InterceptError(controller.getAllVeiculos, req, res, next),
8+
);
9+
10+
module.exports = router;

src/routes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ const unidade = require("./unidade");
66
const armazem = require("./armazem");
77
const solicitacao = require("./solicitacao");
88
const extras = require("./extra");
9+
const garagem = require("./garagem");
910

11+
router.use("/v1", garagem);
1012
router.use("/v1", extras);
1113
router.use("/v1", user);
1214
router.use("/v1", orgao);

0 commit comments

Comments
 (0)