-
Notifications
You must be signed in to change notification settings - Fork 577
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/dados-senado
- Loading branch information
Showing
21 changed files
with
842 additions
and
64 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,41 @@ | ||
import app from '@/app'; | ||
|
||
import BaseError from '@/errors/BaseError'; | ||
import NotFoundError from '@/errors/NotFoundError'; | ||
import InternalError from '@/errors/InternalError'; | ||
|
||
import { getExchangesData } from '../../../../../services/cvm/corretoras'; | ||
|
||
const action = async (request, response) => { | ||
try { | ||
const exchangeCode = request.query.cnpj.replace(/\D/gim, ''); | ||
|
||
const allExchangesData = await getExchangesData(); | ||
|
||
const exchangeData = allExchangesData.find( | ||
({ cnpj }) => cnpj === exchangeCode | ||
); | ||
|
||
if (!exchangeData) { | ||
throw new NotFoundError({ | ||
message: 'Nenhuma corretora localizada', | ||
type: 'exchange_error', | ||
name: 'EXCHANGE_NOT_FOUND', | ||
}); | ||
} | ||
|
||
response.status(200).json(exchangeData); | ||
} catch (err) { | ||
if (err instanceof BaseError) { | ||
throw err; | ||
} | ||
|
||
throw new InternalError({ | ||
message: 'Erro ao buscar informações sobre corretora', | ||
type: 'exchange_error', | ||
name: 'EXCHANGE_INTERNAL', | ||
}); | ||
} | ||
}; | ||
|
||
export default app({ cache: 86400 }).get(action); |
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 @@ | ||
import app from '@/app'; | ||
|
||
import BaseError from '@/errors/BaseError'; | ||
|
||
import InternalError from '@/errors/InternalError'; | ||
import { getExchangesData } from '../../../../../services/cvm/corretoras'; | ||
|
||
const action = async (request, response) => { | ||
try { | ||
const allExchangesData = await getExchangesData(); | ||
response.status(200).json(allExchangesData); | ||
} catch (err) { | ||
if (err instanceof BaseError) { | ||
throw err; | ||
} | ||
|
||
throw new InternalError({ | ||
message: 'Erro ao buscar informações sobre corretora', | ||
type: 'exchange_error', | ||
name: 'EXCHANGE_INTERNAL', | ||
}); | ||
} | ||
}; | ||
|
||
export default app({ cache: 86400 }).get(action); |
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,52 @@ | ||
import app from '@/app'; | ||
import BaseError from '@/errors/BaseError'; | ||
import InternalError from '@/errors/InternalError'; | ||
import { getPixParticipants, formatCsvFile } from '@/services/pix/participants'; | ||
|
||
const obtainPixParticipantList = async (actual = true) => { | ||
try { | ||
const response = await getPixParticipants(); | ||
|
||
return response; | ||
} catch (error) { | ||
if (actual && error.response.status === 404) { | ||
return getPixParticipants(false); | ||
} | ||
|
||
throw new InternalError({ | ||
status: 500, | ||
message: `Erro ao obter as informações do BCB ou informações inexistentes`, | ||
name: 'PIX_LIST_ERROR', | ||
type: 'PIX_LIST_ERROR', | ||
}); | ||
} | ||
}; | ||
|
||
const action = async (request, response) => { | ||
try { | ||
const pixParticipantsList = await obtainPixParticipantList(); | ||
|
||
const parsedData = formatCsvFile(pixParticipantsList); | ||
|
||
response.status(200); | ||
response.json(parsedData); | ||
} catch (error) { | ||
if (error instanceof BaseError) { | ||
throw error; | ||
} | ||
|
||
throw new InternalError({ | ||
status: 500, | ||
message: `Erro ao obter as informações do BCB`, | ||
name: 'PIX_LIST_ERROR', | ||
type: 'PIX_LIST_ERROR', | ||
}); | ||
} | ||
}; | ||
|
||
/** | ||
* Cache de 21600s (6 horas) devido a não saber que horas os dados são gerados pelo BCB. | ||
* Logo foi utilizado um cache longo para caso não exista as infos, utilize a do dia anterior como base, já que não é um dado que tem alta atualização | ||
*/ | ||
|
||
export default app({ cache: 21600 }).get(action); |
Oops, something went wrong.