Skip to content

Commit

Permalink
Merge pull request #6 from fga-eps-mds/fixing_tests
Browse files Browse the repository at this point in the history
redone e write permissions to routes
  • Loading branch information
guipeeix7 authored Jan 30, 2025
2 parents 1b97c95 + 57369fe commit bb8f6d1
Show file tree
Hide file tree
Showing 13 changed files with 585 additions and 311 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CHANGE ALL VARIABLES ON DEPLOY

NODE_ENV=development
MONGO_URI=mongodb://root:password@financedb:27017/
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=password
DB_HOST=financedb
PORT=3002
BACK_USERS_URL=http://127.0.0.1:3001/
SECRET = S3T1N3L3L4
2 changes: 0 additions & 2 deletions src/Controllers/bankAccountController.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ const getBankAccountbyId = async (req, res) => {
}
};


const deleteBankAccount = async (req, res) => {
try {

const { id } = req.params;

if (!id || !mongoose.Types.ObjectId.isValid(id)) {
Expand Down
1 change: 0 additions & 1 deletion src/Controllers/financialMovementsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const validateCPF = (cpf) => {
return /\d{3}\.\d{3}\.\d{3}-\d{2}/.test(cpf);
};


const createFinancialMovements = async (req, res) => {
try {
console.log("Dados recebidos:", req.body);

Check warning on line 9 in src/Controllers/financialMovementsController.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
Expand Down
10 changes: 5 additions & 5 deletions src/Controllers/financialReportController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const generateFinancialReport = async (req, res) => {
const query = {
sitPagamento: sanitizedSitPagamento,
datadeVencimento: {
$gte: new Date(dataInicio),
$lte: new Date(dataFinal),
}
$gte: new Date(dataInicio),
$lte: new Date(dataFinal),
},
};
if (sanitizedNomeOrigem) query.nomeOrigem = sanitizedNomeOrigem;
if (sanitizedContaOrigem) query.contaOrigem = sanitizedContaOrigem;
Expand All @@ -80,7 +80,7 @@ const generateFinancialReport = async (req, res) => {
if (req.body.contaOrigem) {
query.contaOrigem = req.body.contaOrigem;
}

if (sanitizedSitPagamento) {
const today = new Date(); // Data atual

Expand All @@ -93,7 +93,7 @@ const generateFinancialReport = async (req, res) => {
{ datadePagamento: { $eq: null } },
{ datadePagamento: { $gt: today } },
];
}else {
} else {
delete query.datadePagamento;
}
}
Expand Down
30 changes: 30 additions & 0 deletions src/Middlewares/accessControlMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const jwt = require("jsonwebtoken");

const checkPermissions = (permissionName) => {
return async (req, res, next) => {
try {
const decoded = jwt.decode(
req.headers.authorization?.split(" ")[1]
);
if (!decoded) {
return res
.status(401)
.json({ mensagem: "Tokem não fornecido." });
}
const permission = decoded.permissions.find(
(perm) => perm === permissionName
);

if (!permission) {
return res
.status(400)
.send("user has no permission to access resource");
}
next();
} catch (error) {
next(error);
}
};
};

module.exports = { checkPermissions };
32 changes: 22 additions & 10 deletions src/Models/csvGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const formatNumericDate = (date) => {
return `${day}/${month}/${year}`;
};

const generateFinancialReportCSV = (financialMovements, filePath, includeFields) => {
const generateFinancialReportCSV = (
financialMovements,
filePath,
includeFields
) => {
return new Promise((resolve, reject) => {
try {
if (financialMovements.length === 0) {
Expand All @@ -22,7 +26,10 @@ const generateFinancialReportCSV = (financialMovements, filePath, includeFields)
}

const allFields = {
tipoDocumento: { label: "Tipo Documento", value: "tipoDocumento" },
tipoDocumento: {
label: "Tipo Documento",
value: "tipoDocumento",
},
valorBruto: { label: "Valor Bruto", value: "valorBruto" },
valorLiquido: { label: "Valor Líquido", value: "valorLiquido" },
contaOrigem: { label: "Conta Origem", value: "contaOrigem" },
Expand All @@ -37,37 +44,42 @@ const generateFinancialReportCSV = (financialMovements, filePath, includeFields)
label: "Data de Pagamento",
value: (row) => formatNumericDate(row.datadePagamento),
},
formaPagamento: { label: "Forma de Pagamento", value: "formaPagamento" },
formaPagamento: {
label: "Forma de Pagamento",
value: "formaPagamento",
},
sitPagamento: {
label: "Situação de Pagamento",
value: (row) => {
// Verificar se a linha ou o campo de data está ausente ou inválido
if (!row || row.datadePagamento == null) {
console.log("Linha sem data de pagamento:", row); // Log para debugar
return "Não pago"; // Retorna 'Não pago' se não houver data
return "Não pago"; // Retorna 'Não pago' se não houver data
}

// Verificar se a data é válida
const paymentDate = new Date(row.datadePagamento);
if (isNaN(paymentDate.getTime())) {
console.log("Data inválida:", row.datadePagamento); // Log para debugar
return "Não pago"; // Retorna 'Não pago' se a data for inválida
return "Não pago"; // Retorna 'Não pago' se a data for inválida
}

const today = new Date();
return paymentDate <= today ? "Pago" : "Não pago";
},
},

descricao: { label: "Descrição", value: "descricao" },
};

if (!includeFields || includeFields.length === 0) {
fs.writeFileSync(filePath, "");
return resolve();
}

const fields = includeFields.map((field) => allFields[field]).filter(Boolean);
const fields = includeFields
.map((field) => allFields[field])
.filter(Boolean);

if (fields.length === 0) {
fs.writeFileSync(filePath, "");
Expand Down
Loading

0 comments on commit bb8f6d1

Please sign in to comment.