From c439fa3ed3e228eb99f7d9fc4cfa1d24807384bb Mon Sep 17 00:00:00 2001 From: Nagarjun Sanji Date: Fri, 27 Sep 2024 11:40:31 +0530 Subject: [PATCH] updated code --- src/helpers/debrickedServiceHelper.ts | 32 ++++++++++++++++++++++++++- src/services/dependencyService.ts | 8 ++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/helpers/debrickedServiceHelper.ts b/src/helpers/debrickedServiceHelper.ts index 03523d6..7d6aed1 100644 --- a/src/helpers/debrickedServiceHelper.ts +++ b/src/helpers/debrickedServiceHelper.ts @@ -1,5 +1,5 @@ import { ApiHelper } from "./apiHelper"; -import { Repository, RequestParam } from "../types/index"; +import { DependencyResponse, DependencyVulnerabilityWrapper, Repository, RequestParam } from "../types/index"; import { Logger } from "./loggerHelper"; import { SecondService } from "../constants"; import { SentryHelper } from "./sentryHelper"; @@ -31,4 +31,34 @@ export class DebrickedServiceHelper { throw error; } } + + /** + * Fetches Dependencies Hierarchy. + * + * @returns {Promise} A promise resolving to Dependencies Hierarchy. + */ + public async fetchDependenciesHierarchy(requestParam: RequestParam): Promise { + this.logger.logInfo("Fetching Dependencies Hierarchy"); + try { + return await this.apiHelper.get(requestParam); + } catch (error: any) { + SentryHelper.captureException(error); + throw error; + } + } + + /** + * Fetches Vulnerabilities. + * + * @returns {Promise} A promise resolving to Vulnerabilities. + */ + public async fetchVulnerabilities(requestParam: RequestParam): Promise { + this.logger.logInfo("Fetching Vulnerabilities"); + try { + return await this.apiHelper.get(requestParam); + } catch (error: any) { + SentryHelper.captureException(error); + throw error; + } + } } diff --git a/src/services/dependencyService.ts b/src/services/dependencyService.ts index d5bb912..ae24148 100644 --- a/src/services/dependencyService.ts +++ b/src/services/dependencyService.ts @@ -1,4 +1,4 @@ -import { apiHelper, globalStore, Logger } from "../helpers"; +import { debrickedServiceHelper, globalStore, Logger } from "../helpers"; import { Package, RequestParam } from "../types"; import { DependencyVulnerability, @@ -17,7 +17,8 @@ export class DependencyService { repoId: repoID, commitId: commitId, }; - const response: DependencyResponse = await apiHelper.get(requestParam); + + const response: DependencyResponse = await debrickedServiceHelper.fetchDependenciesHierarchy(requestParam); const packageData = globalStore.getPackages(); response.dependencies.forEach((dependency: Dependency) => { @@ -66,7 +67,8 @@ export class DependencyService { repoId: repoId, commitId: commitId, }; - const response: DependencyVulnerabilityWrapper = await apiHelper.get(requestParam); + const response: DependencyVulnerabilityWrapper = + await await debrickedServiceHelper.fetchVulnerabilities(requestParam); const vulnerabilityMap = new Map(); response.vulnerabilities.forEach((vul: DependencyVulnerability) => {