From 841256b8dda5fe288c6457f7af2bffa57b1952b1 Mon Sep 17 00:00:00 2001 From: prasanth-ideas2it Date: Fri, 20 Dec 2024 15:17:43 +0530 Subject: [PATCH] fix: review changes --- apps/web-api/src/app.module.ts | 4 +- .../oso-metrics.controller.spec.ts} | 4 +- .../src/oso-metrics/oso-metrics.controller.ts | 17 +++++++++ .../src/oso-metrics/oso-metrics.module.ts | 10 +++++ .../oso-metrics/oso-metrics.service.spec.ts | 18 +++++++++ .../src/oso-metrics/oso-metrics.service.ts | 37 +++++++++++++++++++ ...o_code-metrics-by-project-v1.controller.ts | 17 --------- .../oso_code-metrics-by-project-v1.module.ts | 10 ----- ...code-metrics-by-project-v1.service.spec.ts | 18 --------- .../oso_code-metrics-by-project-v1.service.ts | 27 -------------- 10 files changed, 86 insertions(+), 76 deletions(-) rename apps/web-api/src/{oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.spec.ts => oso-metrics/oso-metrics.controller.spec.ts} (75%) create mode 100644 apps/web-api/src/oso-metrics/oso-metrics.controller.ts create mode 100644 apps/web-api/src/oso-metrics/oso-metrics.module.ts create mode 100644 apps/web-api/src/oso-metrics/oso-metrics.service.spec.ts create mode 100644 apps/web-api/src/oso-metrics/oso-metrics.service.ts delete mode 100644 apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.ts delete mode 100644 apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.module.ts delete mode 100644 apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.spec.ts delete mode 100644 apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.ts diff --git a/apps/web-api/src/app.module.ts b/apps/web-api/src/app.module.ts index b2b89392d..c4b4f9b4a 100644 --- a/apps/web-api/src/app.module.ts +++ b/apps/web-api/src/app.module.ts @@ -41,7 +41,7 @@ import { MemberFeedbacksModule } from './member-feedbacks/member-feedbacks.modul import { HuskyModule } from './husky/husky.module'; import { HomeModule } from './home/home.module'; import { InternalsModule } from './internals/internals.module'; -import { OsoCodeMetricsByProjectV1Module } from './oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.module'; +import { OsoMetricsModule } from './oso-metrics/oso-metrics.module'; @Module({ controllers: [AppController], @@ -98,7 +98,7 @@ import { OsoCodeMetricsByProjectV1Module } from './oso_code-metrics-by-project-v HuskyModule, HomeModule, InternalsModule, - OsoCodeMetricsByProjectV1Module, + OsoMetricsModule, ], providers: [ { diff --git a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.spec.ts b/apps/web-api/src/oso-metrics/oso-metrics.controller.spec.ts similarity index 75% rename from apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.spec.ts rename to apps/web-api/src/oso-metrics/oso-metrics.controller.spec.ts index 6c482224d..863b083bc 100644 --- a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.spec.ts +++ b/apps/web-api/src/oso-metrics/oso-metrics.controller.spec.ts @@ -1,6 +1,6 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { OsoCodeMetricsByProjectV1Controller } from './oso_code-metrics-by-project-v1.controller'; -import { OsoCodeMetricsByProjectV1Service } from './oso_code-metrics-by-project-v1.service'; +import { OsoCodeMetricsByProjectV1Controller } from './oso-metrics.controller'; +import { OsoCodeMetricsByProjectV1Service } from './oso-metrics.service'; describe('OsoCodeMetricsByProjectV1Controller', () => { let controller: OsoCodeMetricsByProjectV1Controller; diff --git a/apps/web-api/src/oso-metrics/oso-metrics.controller.ts b/apps/web-api/src/oso-metrics/oso-metrics.controller.ts new file mode 100644 index 000000000..48eaf5628 --- /dev/null +++ b/apps/web-api/src/oso-metrics/oso-metrics.controller.ts @@ -0,0 +1,17 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { OsoMetricsService } from './oso-metrics.service'; + +@Controller('v1/oso-metrics') +export class OsoMetricsController { + constructor(private readonly osoMetricsService: OsoMetricsService) {} + + @Get() + findAll() { + return this.osoMetricsService.findAll(); + } + + @Get(':name') + findOne(@Param('name') name: string) { + return this.osoMetricsService.findOne(name); + } +} diff --git a/apps/web-api/src/oso-metrics/oso-metrics.module.ts b/apps/web-api/src/oso-metrics/oso-metrics.module.ts new file mode 100644 index 000000000..ce275dd3f --- /dev/null +++ b/apps/web-api/src/oso-metrics/oso-metrics.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { OsoMetricsService } from './oso-metrics.service'; +import { OsoMetricsController } from './oso-metrics.controller'; + +@Module({ + controllers: [OsoMetricsController], + providers: [OsoMetricsService], + exports: [OsoMetricsService], +}) +export class OsoMetricsModule {} diff --git a/apps/web-api/src/oso-metrics/oso-metrics.service.spec.ts b/apps/web-api/src/oso-metrics/oso-metrics.service.spec.ts new file mode 100644 index 000000000..77655524a --- /dev/null +++ b/apps/web-api/src/oso-metrics/oso-metrics.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { OsoMetricsService } from './oso-metrics.service'; + +describe('OsoMetricsService', () => { + let service: OsoMetricsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [OsoMetricsService], + }).compile(); + + service = module.get(OsoMetricsService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/apps/web-api/src/oso-metrics/oso-metrics.service.ts b/apps/web-api/src/oso-metrics/oso-metrics.service.ts new file mode 100644 index 000000000..06b0cd189 --- /dev/null +++ b/apps/web-api/src/oso-metrics/oso-metrics.service.ts @@ -0,0 +1,37 @@ +import { + BadRequestException, + ConflictException, + Injectable, + InternalServerErrorException, + NotFoundException, +} from '@nestjs/common'; +import { OsoPrismaService } from '../shared/oso-prisma.service'; +import { LogService } from '../shared/log.service'; +import { Prisma } from '@prisma/client'; + +@Injectable() +export class OsoMetricsService { + constructor(private prisma: OsoPrismaService, private logger: LogService) {} + + findAll() { + try { + return this.prisma.oso_codeMetricsByProjectV1.findMany(); + } catch (error) { + throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`); + } + } + + async findOne(displayName: string) { + try { + const metric = await this.prisma.oso_codeMetricsByProjectV1.findFirst({ + where: { displayName }, + }); + if (!metric) { + throw new NotFoundException(`Metric with display name "${displayName}" not found.`); + } + return metric; + } catch (error) { + throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`); + } + } +} diff --git a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.ts b/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.ts deleted file mode 100644 index d1608d67a..000000000 --- a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.controller.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; -import { OsoCodeMetricsByProjectV1Service } from './oso_code-metrics-by-project-v1.service'; - -@Controller('v1/oso-code-metrics-by-project-v1') -export class OsoCodeMetricsByProjectV1Controller { - constructor(private readonly osoCodeMetricsByProjectV1Service: OsoCodeMetricsByProjectV1Service) {} - - @Get() - findAll() { - return this.osoCodeMetricsByProjectV1Service.findAll(); - } - - @Get(':name') - findOne(@Param('name') name: string) { - return this.osoCodeMetricsByProjectV1Service.findOne(name); - } -} diff --git a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.module.ts b/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.module.ts deleted file mode 100644 index adae63f8d..000000000 --- a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Module } from '@nestjs/common'; -import { OsoCodeMetricsByProjectV1Service } from './oso_code-metrics-by-project-v1.service'; -import { OsoCodeMetricsByProjectV1Controller } from './oso_code-metrics-by-project-v1.controller'; - -@Module({ - controllers: [OsoCodeMetricsByProjectV1Controller], - providers: [OsoCodeMetricsByProjectV1Service], - exports: [OsoCodeMetricsByProjectV1Service], -}) -export class OsoCodeMetricsByProjectV1Module {} diff --git a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.spec.ts b/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.spec.ts deleted file mode 100644 index 817df62f8..000000000 --- a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { OsoCodeMetricsByProjectV1Service } from './oso_code-metrics-by-project-v1.service'; - -describe('OsoCodeMetricsByProjectV1Service', () => { - let service: OsoCodeMetricsByProjectV1Service; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [OsoCodeMetricsByProjectV1Service], - }).compile(); - - service = module.get(OsoCodeMetricsByProjectV1Service); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -}); diff --git a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.ts b/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.ts deleted file mode 100644 index 6384bf4ca..000000000 --- a/apps/web-api/src/oso_code-metrics-by-project-v1/oso_code-metrics-by-project-v1.service.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Injectable, InternalServerErrorException } from '@nestjs/common'; -import { OsoPrismaService } from '../shared/oso-prisma.service'; - -@Injectable() -export class OsoCodeMetricsByProjectV1Service { - constructor(private prisma: OsoPrismaService) {} - - findAll() { - try { - return this.prisma.oso_codeMetricsByProjectV1.findMany(); - } catch (error) { - throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`); - } - } - - findOne(displayName: string) { - try { - return ( - this.prisma.oso_codeMetricsByProjectV1.findFirst({ - where: { displayName }, - }) ?? {} - ); - } catch (error) { - throw new InternalServerErrorException(`Error occured while retrieving project metrics data: ${error.message}`); - } - } -}