From 45df67031c0cdfb17c82a49927b311838f7b990b Mon Sep 17 00:00:00 2001 From: Konstantinos Kamaropoulos Date: Sat, 4 Jan 2020 20:49:23 +0200 Subject: [PATCH] feat: Add logs controller implementation Co-authored-by: Iro Athina Valagouti --- src/logs/logs.controller.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/logs/logs.controller.ts b/src/logs/logs.controller.ts index cc5e79e..6e38fc9 100644 --- a/src/logs/logs.controller.ts +++ b/src/logs/logs.controller.ts @@ -1,4 +1,30 @@ -import { Controller } from '@nestjs/common'; +import { Controller, Get, Post, Body, Response, HttpStatus } from '@nestjs/common'; +import { LogsService } from './logs.service'; +import { ILogs } from './logs.interface'; @Controller('logs') -export class LogsController {} +export class LogsController { + constructor(private readonly logsService: LogsService) {} + + @Get() + async getPosts() { + return this.logsService.getLogs(); + } + + @Post() + async postLogs(@Body() body, @Response() res: any) { + let success: Boolean = await this.logsService.storeLog(body); + if (success){ + return res.status(HttpStatus.CREATED) + .json({ + message: "Log stored successfully!" + }); + + } else { + return res.status(HttpStatus.INTERNAL_SERVER_ERROR) + .json({ + message: "An error occured during storing the log." + }); + } + } +}