Skip to content

Commit

Permalink
refactor(hooks): extract connections info calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
LeKer29 committed Aug 11, 2023
1 parent 8c597ec commit 07f6bbf
Showing 1 changed file with 35 additions and 18 deletions.
53 changes: 35 additions & 18 deletions src/hooks/services/hooks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,24 +495,11 @@ export class HooksService {
/**
* 3.b. Get personal information from every connection
*/
const connectionsInfo: { [key: string]: BudgetInsightOwner } = {};
if (!this.config.budgetInsight.enableAccountOwnerships) {
for (const connection of connections) {
try {
connectionsInfo[connection.id] = await this.aggregator.getInfo(
permanentToken,
`${connection.id}`,
serviceAccountConfig,
);
} catch (err) {
this.logger.warn({
message: `Unable to get user personal information`,
error: err,
connection,
});
}
}
}
const connectionsInfo: { [key: string]: BudgetInsightOwner } = await this.getConnectionsInfo(
connections,
permanentToken,
serviceAccountConfig,
);

const enrichedConnections: EnrichedConnection[] = mapBudgetInsightAccount(
accounts,
Expand Down Expand Up @@ -546,6 +533,36 @@ export class HooksService {
return enrichedConnections;
}

/**
* Get personal information from every connection
* @param connections
* @param token
* @param clientConfig
* @private
*/
private async getConnectionsInfo(
connections: Connection[],
token: string,
clientConfig?: ClientConfig,
): Promise<{ [key: string]: BudgetInsightOwner }> {
const connectionsInfo: { [key: string]: BudgetInsightOwner } = {};
if (!this.config.budgetInsight.enableAccountOwnerships) {
for (const connection of connections) {
try {
connectionsInfo[connection.id] = await this.aggregator.getInfo(token, `${connection.id}`, clientConfig);
} catch (err) {
this.logger.warn({
message: `Unable to get user personal information`,
error: err,
connection,
});
}
}
}

return connectionsInfo;
}

/**
* Gets the Service Account given the event
*/
Expand Down

0 comments on commit 07f6bbf

Please sign in to comment.