|
@ -6,21 +6,30 @@ import { ILogs } from './logs.interface'; |
|
|
export class LogsController { |
|
|
export class LogsController { |
|
|
constructor(private readonly logsService: LogsService) {} |
|
|
constructor(private readonly logsService: LogsService) {} |
|
|
|
|
|
|
|
|
|
|
|
// GET /logs Endpoint
|
|
|
|
|
|
// Get all logs from Mongo
|
|
|
@Get() |
|
|
@Get() |
|
|
async getPosts() { |
|
|
async getLogs() { |
|
|
|
|
|
// Get and return logs from logsRervice
|
|
|
return this.logsService.getLogs(); |
|
|
return this.logsService.getLogs(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// POST /logs Endpoint
|
|
|
|
|
|
// Store a new log into Mongo
|
|
|
@Post() |
|
|
@Post() |
|
|
async postLogs(@Body() body, @Response() res: any) { |
|
|
async postLogs(@Body() body, @Response() res: any) { |
|
|
|
|
|
// Try to store data into Mongo
|
|
|
let success: Boolean = await this.logsService.storeLog(body); |
|
|
let success: Boolean = await this.logsService.storeLog(body); |
|
|
|
|
|
// If the operation was successful
|
|
|
if (success){ |
|
|
if (success){ |
|
|
|
|
|
// respond with HTTP Code 201 CREATED
|
|
|
|
|
|
// and a success message
|
|
|
return res.status(HttpStatus.CREATED) |
|
|
return res.status(HttpStatus.CREATED) |
|
|
.json({ |
|
|
.json({ |
|
|
message: "Log stored successfully!" |
|
|
message: "Log stored successfully!" |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
// If not, respond with 500, internal server error and an error message
|
|
|
return res.status(HttpStatus.INTERNAL_SERVER_ERROR) |
|
|
return res.status(HttpStatus.INTERNAL_SERVER_ERROR) |
|
|
.json({ |
|
|
.json({ |
|
|
message: "An error occured during storing the log." |
|
|
message: "An error occured during storing the log." |
|
|