/
andreas300000
/
webpinger-backend
Обзор
Документация
Войти
/
andreas300000
/
webpinger-backend
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/core/projects/projects.controller.ts
94 строки
2 KB
bethanle
проекты и инциденты полностью оснащены крудами и добавлены триггеры для отслеживания послежних изменений ссылках, связанных с проектом
01 июн 2025, 03:25
01 июн 2025, 03:25
c2517ae
Код
Авторство
О чём код?
import { Controller, Get, Query, ParseIntPipe, UseGuards, Param, Delete, HttpException, HttpStatus, Put, Body, Post, } from '@nestjs/common'; import { ProjectsService } from './projects.service'; import { JwtAuthGuard } from '../auth/jwt-auth.guard'; @UseGuards(JwtAuthGuard) @Controller('project') export class ProjectsController { constructor(private readonly projectsService: ProjectsService) {} @Get('user') async getUserProjects(@Query('userId', ParseIntPipe) userId: number) { return this.projectsService.getUserProjects(userId); } @Get('links') async getProjectLinks(@Query('projectId', ParseIntPipe) projectId: number) { return this.projectsService.getProjectLinks(projectId); } @Get() async getProjects() { return this.projectsService.getProjects(); } @Get('companies') async getCompanies() { return this.projectsService.getCompanies(); } @Get(':id') async getProjectById(@Param('id', ParseIntPipe) id: number) { return this.projectsService.getProjectById(id); } @Delete(':id') async deleteProject(@Param('id', ParseIntPipe) id: number) { try { return await this.projectsService.deleteProject(id); } catch (err) { const msg = err instanceof Error ? err.message : 'Unknown error'; throw new HttpException( msg, HttpStatus.BAD_REQUEST ); } } @Put(':id') async updateProject( @Param('id', ParseIntPipe) id: number, @Body() data: { name: string; description?: string; company_name?: string } ) { try { return await this.projectsService.updateProject(id, data); } catch (err) { if (err instanceof HttpException) { throw err; } throw new HttpException( err.message, HttpStatus.BAD_REQUEST ); } } @Post() async createProject( @Body() data: { name: string; description?: string; company_name?: string } ) { try { return await this.projectsService.createProject(data); } catch (err) { if (err instanceof HttpException) { throw err; } throw new HttpException( err.message, HttpStatus.BAD_REQUEST ); } } }