Skip to content

Commit b5a1add

Browse files
committed
garagem
1 parent ad9a8f6 commit b5a1add

6 files changed

Lines changed: 46 additions & 11 deletions

File tree

src/controllers/garagem.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ExtrasController {
77
static async getAllVeiculos(req, res) {
88
const { idEntidade } = req.params;
99
const { rows } = await database.query(SQL.getAll, [idEntidade]);
10-
return ResponseController(res, httpStatus.CREATED, T_PT.capturado, rows);
10+
return ResponseController(res, httpStatus.OK, T_PT.capturado, rows);
1111
}
1212

1313
static async createVeiculo(req, res) {
@@ -30,12 +30,31 @@ class ExtrasController {
3030
static async getAllViagens(req, res) {
3131
const { idEntidade } = req.params;
3232
const { rows } = await database.query(SQL.getAllViagens, [idEntidade]);
33-
return ResponseController(res, httpStatus.CREATED, T_PT.capturado, rows);
33+
return ResponseController(res, httpStatus.OK, T_PT.capturado, rows);
3434
}
35+
3536
static async getAllSolicitacoes(req, res) {
3637
const { idEntidade } = req.params;
3738
const { rows } = await database.query(SQL.getAllSolicitacoes, [idEntidade]);
38-
return ResponseController(res, httpStatus.CREATED, T_PT.capturado, rows);
39+
return ResponseController(res, httpStatus.OK, T_PT.capturado, rows);
40+
}
41+
42+
static async createSolicitacao(req, res) {
43+
const { idEntidade, idUnidade } = req.params;
44+
const data = req.body;
45+
const id = uuid();
46+
47+
await database.query(SQL.createSolicitacao, [
48+
id,
49+
data.ID_VEICULO,
50+
data.DATA_VIAGEM,
51+
data.RESPONSAVEL,
52+
data.MOTIVO,
53+
idUnidade,
54+
idEntidade,
55+
"7c92f4cf-f76b-4333-ac06-6b60bf2b2518",
56+
]);
57+
return ResponseController(res, httpStatus.CREATED, T_PT.cadastrado, id);
3958
}
4059
}
4160

src/controllers/user.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ class UserController {
2222
res,
2323
httpStatus.CONFLICT,
2424
T_PT.cft_usuario,
25-
null
25+
null,
2626
);
2727
}
2828

29+
const { rows } = await database.query(SQL.tipo_almoxarifado, [
30+
data.UNIDADE,
31+
]);
32+
const tipoAlmoxarifado =
33+
data.TIPO_ALMOXARIFE == null
34+
? rows[0].id_tipo_unidade
35+
: data.TIPO_ALMOXARIFE;
36+
2937
const hashPassword = await bcrypt.hash(data.SENHA, 14);
3038

3139
await database.query(SQL.create, [
@@ -37,7 +45,7 @@ class UserController {
3745
data.ORGAO,
3846
data.LOGIN,
3947
hashPassword,
40-
data.TIPO_ALMOXARIFE,
48+
tipoAlmoxarifado,
4149
]);
4250

4351
return ResponseController(res, httpStatus.CREATED, T_PT.cadastrado, id);
@@ -47,7 +55,7 @@ class UserController {
4755
res,
4856
httpStatus.INTERNAL_SERVER_ERROR,
4957
T_PT.no_content,
50-
null
58+
null,
5159
);
5260
}
5361
}
@@ -65,7 +73,7 @@ class UserController {
6573
res,
6674
httpStatus.UNAUTHORIZED,
6775
T_PT.cft_credenciais,
68-
null
76+
null,
6977
);
7078
}
7179

@@ -76,7 +84,7 @@ class UserController {
7684
res,
7785
httpStatus.UNAUTHORIZED,
7886
T_PT.cft_credenciais,
79-
null
87+
null,
8088
);
8189
}
8290

@@ -90,7 +98,7 @@ class UserController {
9098
nome: dados_usuario[0].nome,
9199
},
92100
JWT_SECRET,
93-
{ expiresIn: "3h" }
101+
{ expiresIn: "3h" },
94102
);
95103

96104
const user = {
@@ -114,7 +122,7 @@ class UserController {
114122
res,
115123
httpStatus.INTERNAL_SERVER_ERROR,
116124
T_PT.no_content,
117-
null
125+
null,
118126
);
119127
}
120128
}

src/lib/schemas/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const create = yup.object().shape({
88
LOGIN: yup.string().max(80, "Nome de usuario muito longo.").required(),
99
SENHA: yup.string().max(30, "Senha muito longa.").required(),
1010
NIVEL: yup.number().required(),
11-
TIPO_ALMOXARIFE: yup.number().required(),
11+
TIPO_ALMOXARIFE: yup.number().required().nullable(),
1212
});
1313

1414
module.exports = {

src/models/garagem.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ module.exports = {
2525
where sv.id_orgao = $1
2626
order by sv.data_viagem asc;
2727
`,
28+
29+
createSolicitacao: `
30+
INSERT INTO SOLICIACAO_VEICULAR (id, id_veiculo, data_viagem, responsavel, motivo, id_unidade, id_orgao, id_status) values ($1,$2,$3,$4,$5,$6,$7,$8);
31+
`,
2832
};

src/models/user.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ module.exports = {
99
todosUsuarios: `SELECT ID,NOME, DESCRICAO, NIVEL, LOGIN FROM USUARIO ORDER BY NOME ASC;`,
1010
deleteUsuario: `DELETE FROM USUARIO WHERE ID = $1;`,
1111
updatePass: `UPDATE USUARIO SET SENHA = $1 WHERE LOGIN = $2;`,
12+
tipo_almoxarifado: `SELECT ID_TIPO_UNIDADE FROM UNIDADE WHERE ID = $1;`,
1213
};

src/routes/garagem.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ const controller = require("../controllers/garagem");
66
router.get("/garagem/viajens/:idEntidade", (req, res, next) =>
77
InterceptError(controller.getAllViagens, req, res, next),
88
);
9+
910
router.get("/garagem/viajens/solicitacoes/:idEntidade", (req, res, next) =>
1011
InterceptError(controller.getAllSolicitacoes, req, res, next),
1112
);
13+
1214
router.get("/garagem/veiculos/:idEntidade", (req, res, next) =>
1315
InterceptError(controller.getAllVeiculos, req, res, next),
1416
);
17+
1518
router.post("/garagem/veiculos/:idEntidade", (req, res, next) =>
1619
InterceptError(controller.createVeiculo, req, res, next),
1720
);

0 commit comments

Comments
 (0)