From 1f9ee5a2066e18331fcd5967b5f32b5e2ecfc37e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 5 Jan 2024 16:27:45 +0100 Subject: [PATCH] Clean code --- .../server/src/sdk/app/datasources/plus.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/packages/server/src/sdk/app/datasources/plus.ts b/packages/server/src/sdk/app/datasources/plus.ts index 65b908526c..0049730119 100644 --- a/packages/server/src/sdk/app/datasources/plus.ts +++ b/packages/server/src/sdk/app/datasources/plus.ts @@ -45,7 +45,7 @@ export async function getConnector( ): Promise { 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 if (datasource._id) { @@ -55,17 +55,11 @@ export async function getConnector( return new Connector(datasource.config) } -async function getAndMergeDatasource(datasource: Datasource) { - let existingDatasource: undefined | Datasource +async function mergeAndEnrich(datasource: Datasource) { if (datasource._id) { - existingDatasource = await datasources.get(datasource._id) + const existingDatasource = await datasources.get(datasource._id) + + datasource = datasources.mergeConfigs(datasource, existingDatasource) } - let enrichedDatasource = datasource - if (existingDatasource) { - enrichedDatasource = datasources.mergeConfigs( - datasource, - existingDatasource - ) - } - return await datasources.enrich(enrichedDatasource) + return await datasources.enrich(datasource) }