import { Body, Controller, Delete, Get, HttpException, Param, Post, Put, Query, UseGuards, UseInterceptors } from '@nestjs/common'; import { LogDto } from './log.dto'; import { LogEntity } from './log.entity'; import { LogService } from './log.service'; import { CustomError } from '../error/customError'; import { AuthGuard, Public } from '@noahspan/noahspan-modules'; import { LogInterceptor } from './log.interceptor'; import { FileService } from '../file/file.service'; import { DeleteResult, InsertResult, UpdateResult } from 'typeorm'; import { Reflector } from '@nestjs/core'; import { Logs } from './logs.interface'; const reflector = new Reflector(); @Controller('logs') @UseInterceptors(new LogInterceptor(reflector)) export class LogController { constructor( private readonly fileService: FileService, private readonly logService: LogService ) {} @Get() @Public() async findLogsWithCount(@Query('skip') skip?, @Query('take') take?: number,): Promise { try { return await this.logService.findLogsWithCount(skip, take) } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode) } } @Get('flights') @Public() async findLogsWithTracks(@Query('skip') skip?, @Query('take') take?: number,): Promise { try { return await this.logService.findLogsWithTracks(skip, take) } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode); } } @Get(':id') @Public() async find( @Param('id') id: string, ): Promise { try { return await this.logService.find(id); } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode); } } @Post() @UseGuards(AuthGuard) async create(@Body() logDto: LogDto) { try { return await this.logService.create(logDto); } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode); } } @Put(':id') @UseGuards(AuthGuard) async update( @Param('id') id: string, @Body() logDto: LogDto ) { try { return await this.logService.update(id, logDto); } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode); } } @Delete(':id') @UseGuards(AuthGuard) async delete( @Param('id') id: string, ): Promise { try { return await this.logService.delete(id); } catch (error) { const customError = error as CustomError; throw new HttpException(customError.message, customError.statusCode); } } }