32 lines
955 B
TypeScript
32 lines
955 B
TypeScript
import { Controller, Post, Get, Delete, Body, Param, UseGuards, Request } from '@nestjs/common';
|
|
import { ProjectsService } from './projects.service';
|
|
import { Project } from './project.entity';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
|
|
@Controller('projects')
|
|
export class ProjectsController {
|
|
constructor(private readonly projectsService: ProjectsService) {}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Post('create')
|
|
async create(@Request() req, @Body() body): Promise<Project> {
|
|
return this.projectsService.create({ ...body, ownerId: req.user.userId });
|
|
}
|
|
|
|
@Get()
|
|
async findAll(): Promise<Project[]> {
|
|
return this.projectsService.findAll();
|
|
}
|
|
|
|
@Get(':id')
|
|
async findOne(@Param('id') id: number): Promise<Project | null> {
|
|
return this.projectsService.findOneById(id);
|
|
}
|
|
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@Delete(':id')
|
|
async delete(@Param('id') id: number): Promise<void> {
|
|
return this.projectsService.delete(id);
|
|
}
|
|
}
|