diff --git a/src/app-auth/controllers/app-auth/app-auth.controller.ts b/src/app-auth/controllers/app-auth/app-auth.controller.ts index 32c9bd9f..efe676ce 100644 --- a/src/app-auth/controllers/app-auth/app-auth.controller.ts +++ b/src/app-auth/controllers/app-auth/app-auth.controller.ts @@ -1,9 +1,10 @@ -import { Controller, Get, ValidationPipe, Post, UsePipes, Body, Req, Res, HttpStatus } from '@nestjs/common'; +import { Controller, Get, ValidationPipe, Post, UsePipes, Body, Req, Res, HttpStatus, Param} from '@nestjs/common'; import { CreateAppDto } from 'src/app-auth/dtos/CreateApp.dto'; import { AppAuthService } from 'src/app-auth/services/app-auth/app-auth.service'; import { ApiBadRequestResponse, ApiCreatedResponse, ApiResponse, ApiTags } from '@nestjs/swagger'; import { IApp } from '../../types/App.types'; import { AppSchema } from '../../schemas/App.schema'; +import { AppNotFoundException } from 'src/app-auth/exceptions/AppNotFound.exception'; @ApiTags('App') @Controller('app') @@ -15,10 +16,17 @@ export class AppAuthController { description: 'List of apps', type: [AppSchema] }) - getAppAuth() { + getApps() { return this.appAuthService.getAllApps(); } + @Get(':appId') + getAppById(@Param('appId') appId: string): IApp { + const app = this.appAuthService.getAppById(appId); + if(app) return app; + else throw new AppNotFoundException(); // Custom Exception handling + } + @Post('/register') @ApiCreatedResponse({ description: 'Newly created app', diff --git a/src/app-auth/exceptions/AppNotFound.exception.ts b/src/app-auth/exceptions/AppNotFound.exception.ts new file mode 100644 index 00000000..dc05c587 --- /dev/null +++ b/src/app-auth/exceptions/AppNotFound.exception.ts @@ -0,0 +1,7 @@ +import { HttpException, HttpStatus } from "@nestjs/common"; + +export class AppNotFoundException extends HttpException { + constructor(msg?: string, status?: HttpStatus){ + super(msg || 'Application Not found', status || HttpStatus.NOT_FOUND) + } +} diff --git a/src/app-auth/services/app-auth/app-auth.service.ts b/src/app-auth/services/app-auth/app-auth.service.ts index 5c89e3d6..4ad76a3e 100644 --- a/src/app-auth/services/app-auth/app-auth.service.ts +++ b/src/app-auth/services/app-auth/app-auth.service.ts @@ -22,4 +22,8 @@ export class AppAuthService { getAllApps () { return this.apps } + + getAppById (appId: string) { + return this.apps.find(app => app.appId === appId) + } }