Skip to content

Commit c16795d

Browse files
authored
Merge branch 'main' into spell-check
2 parents d287b34 + 6364ea6 commit c16795d

File tree

7 files changed

+62
-37
lines changed

7 files changed

+62
-37
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Abaixo segue uma lista de integrações com a BrasilApi fornecidas pela comunida
6767

6868
**PHP**
6969
* **[brasilapi-php](https://github.com/andreoneres/brasilapi-php)** criado por [@andreoneres](https://github.com/andreoneres)
70+
* **[brasilapi-php](https://github.com/Corviz/brasilapi-php)** Criado por [@carloscarucce](https://github.com/carloscarucce)
7071

7172
**Python**
7273
* **[brasilapy](https://github.com/lipe14-ops/brasilapy)** Criado por [@lipe14-ops](https://github.com/lipe14-ops)
@@ -79,6 +80,7 @@ Abaixo segue uma lista de integrações com a BrasilApi fornecidas pela comunida
7980

8081
**Delphi**
8182
* **[BrasilAPI-Delphi](https://github.com/gabrielbaltazar/brasilapi4D)** Criado por [@GabrielBaltazar](https://github.com/gabrielbaltazar)
83+
8284

8385
## Autores
8486

package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"next": "10.2.0",
2323
"next-connect": "0.9.1",
2424
"next-sitemap": "1.6.168",
25+
"papaparse": "5.4.0",
2526
"piscina": "3.2.0",
2627
"react": "17.0.1",
2728
"react-dom": "17.0.1",

services/banco-central/banksList.json

+1-1
Large diffs are not rendered by default.

services/banco-central/index.js

+23-36
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
1-
import axios from 'axios';
21
import banksList from './banksList.json';
3-
4-
const fetchBanksListFromBacen = async () => {
5-
const url =
6-
'https://www.bcb.gov.br/pom/spb/estatistica/port/ParticipantesSTRport.csv';
7-
8-
const { data: body } = await axios.get(url);
9-
10-
return body;
11-
};
2+
import getCsvAsJson from '../util/getCsvAsJson';
123

134
const formatCsvFile = (file) => {
14-
const LINE_BREAK = '\r\n';
15-
const lines = file.split(LINE_BREAK);
16-
175
// Remove o cabeçalho
18-
lines.shift();
6+
file.shift();
197

20-
return lines
21-
.map((line) => line.split(',')) // Gera um array por coluna
22-
.filter(([ispb]) => ispb) // Filtra apenas linhas válidas
23-
.map(
24-
([
25-
ispb, // ISPB
26-
name, // Nome_Reduzido
27-
code, // Número_Código // Participa_da_Compe // Acesso_Principal
28-
,
29-
,
30-
fullName, // Nome_Extenso // Início_da_Operação
31-
,
32-
]) => {
33-
return {
34-
ispb,
35-
name: name && name.trim(),
36-
code: Number(code),
37-
fullName: fullName && fullName.trim(),
38-
};
39-
}
40-
);
8+
return file.map(
9+
([
10+
ispb, // ISPB
11+
name, // Nome_Reduzido
12+
code, // Número_Código // Participa_da_Compe // Acesso_Principal
13+
,
14+
,
15+
fullName, // Nome_Extenso // Início_da_Operação
16+
,
17+
]) => {
18+
return {
19+
ispb,
20+
name: name && name.trim(),
21+
code: Number(code),
22+
fullName: fullName && fullName.trim().replace(/\\"|"/g, ''), // Remove aspas
23+
};
24+
}
25+
);
4126
};
4227

4328
export const getBanksData = async () => {
4429
try {
45-
const response = await fetchBanksListFromBacen();
30+
const response = await getCsvAsJson(
31+
'https://www.bcb.gov.br/pom/spb/estatistica/port/ParticipantesSTRport.csv'
32+
);
4633
return formatCsvFile(response);
4734
} catch (err) {
4835
return banksList;

services/util/getCsvAsJson.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import axios from 'axios';
2+
import Papa from 'papaparse';
3+
4+
export default async function getCsvAsJson(url) {
5+
const body = await axios.get(url, {
6+
responseType: 'blob',
7+
});
8+
9+
return Papa.parse(body.data).data;
10+
}

tests/banks-v1.test.js

+14
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ describe('banks v1 (E2E)', () => {
1515
});
1616
});
1717

18+
test('Utilizando um bank code válido (com vírgula no nome): 402', async () => {
19+
const requestUrl = `${global.SERVER_URL}/api/banks/v1/402`;
20+
const response = await axios.get(requestUrl);
21+
22+
expect(response.status).toBe(200);
23+
expect(response.data).toEqual({
24+
ispb: '36947229',
25+
name: 'COBUCCIO S.A. SCFI',
26+
code: 402,
27+
fullName:
28+
'COBUCCIO S/A - SOCIEDADE DE CRÉDITO, FINANCIAMENTO E INVESTIMENTOS',
29+
});
30+
});
31+
1832
test('Utilizando um código inexistente: 1111111', async () => {
1933
expect.assertions(2);
2034
const requestUrl = `${global.SERVER_URL}/api/banks/v1/1111111`;

0 commit comments

Comments
 (0)