Clean code

This commit is contained in:
Adria Navarro 2024-01-05 16:27:45 +01:00
parent dd77779bc1
commit 1f9ee5a206
1 changed files with 6 additions and 12 deletions

View File

@ -45,7 +45,7 @@ export async function getConnector(
): Promise<IntegrationBase | DatasourcePlus> { ): Promise<IntegrationBase | DatasourcePlus> {
const Connector = await getIntegration(datasource.source) const Connector = await getIntegration(datasource.source)
datasource = await getAndMergeDatasource(datasource) datasource = await mergeAndEnrich(datasource)
// can't enrich if it doesn't have an ID yet // can't enrich if it doesn't have an ID yet
if (datasource._id) { if (datasource._id) {
@ -55,17 +55,11 @@ export async function getConnector(
return new Connector(datasource.config) return new Connector(datasource.config)
} }
async function getAndMergeDatasource(datasource: Datasource) { async function mergeAndEnrich(datasource: Datasource) {
let existingDatasource: undefined | Datasource
if (datasource._id) { if (datasource._id) {
existingDatasource = await datasources.get(datasource._id) const existingDatasource = await datasources.get(datasource._id)
datasource = datasources.mergeConfigs(datasource, existingDatasource)
} }
let enrichedDatasource = datasource return await datasources.enrich(datasource)
if (existingDatasource) {
enrichedDatasource = datasources.mergeConfigs(
datasource,
existingDatasource
)
}
return await datasources.enrich(enrichedDatasource)
} }