Files
noahspan-flying/api/src/pilot/pilot.controller.ts
noahspannbauer 487afb08d6 adding api unit tests (#108)
* adding api unit tests

* adding not signed in alerts to flights and logs
2026-03-08 14:58:24 -05:00

92 lines
2.1 KiB
TypeScript

import {
Body,
Controller,
Delete,
Get,
HttpException,
Param,
Post,
Put,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { PilotDto } from './pilot.dto';
import { PilotService } from './pilot.service';
import { CustomError } from '../error/customError';
import { PilotInterceptor } from './pilot.interceptor';
import { AuthGuard, Public } from '@noahspan/noahspan-modules';
import { Reflector } from '@nestjs/core';
const reflector = new Reflector();
@Controller('pilots')
@UseInterceptors(new PilotInterceptor(reflector))
export class PilotController {
constructor(private readonly pilotService: PilotService) {}
@Get(':id')
@Public()
async find(@Param('id') id: string) {
try {
return await this.pilotService.find(id);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Get()
@Public()
async findAll() {
try {
return await this.pilotService.findAll();
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Post()
@UseGuards(AuthGuard)
async create(@Body() pilotDto: PilotDto): Promise<PilotDto> {
try {
return await this.pilotService.create(pilotDto);
} 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() pilotDto: PilotDto
) {
try {
return await this.pilotService.update(id, pilotDto);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
@Delete(':id')
@UseGuards(AuthGuard)
async delete(
@Param('id') id: string,
) {
try {
return await this.pilotService.delete(id);
} catch (error) {
const customError = error as CustomError;
throw new HttpException(customError.message, customError.statusCode);
}
}
}