70 lines
2.1 KiB
TypeScript
70 lines
2.1 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
import { ProjectsCrudService } from './projects-crud.service';
|
|
import { CreateProjectDto } from './dto/create-project.dto';
|
|
import { UpdateProjectDto } from './dto/update-project.dto';
|
|
import { Project } from './entities/project.entity';
|
|
import { PaginatedResponse } from '@common/pagination.dto';
|
|
|
|
@ApiTags('Projects CRUD')
|
|
@Controller('projects/manage')
|
|
export class ProjectsCrudController {
|
|
constructor(private readonly projectsCrudService: ProjectsCrudService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'List all projects' })
|
|
@ApiQuery({ name: 'domainId', required: false })
|
|
@ApiQuery({ name: 'type', required: false })
|
|
@ApiQuery({ name: 'isActive', required: false, type: Boolean })
|
|
findAll(@Query() query: Record<string, unknown>): Promise<PaginatedResponse<Project>> {
|
|
return this.projectsCrudService.findAll(query);
|
|
}
|
|
|
|
@Get('slug/:slug')
|
|
@ApiOperation({ summary: 'Get project by slug' })
|
|
findBySlug(@Param('slug') slug: string): Promise<Project> {
|
|
return this.projectsCrudService.findBySlug(slug);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: 'Get project by ID' })
|
|
findOne(@Param('id') id: string): Promise<Project> {
|
|
return this.projectsCrudService.findOne(id);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'Create project' })
|
|
create(@Body() dto: CreateProjectDto): Promise<Project> {
|
|
return this.projectsCrudService.createProject(dto);
|
|
}
|
|
|
|
@Patch('reorder')
|
|
@ApiOperation({ summary: 'Reorder projects' })
|
|
reorder(@Body() body: { ids: string[] }): Promise<void> {
|
|
return this.projectsCrudService.reorder(body.ids);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: 'Update project' })
|
|
update(@Param('id') id: string, @Body() dto: UpdateProjectDto): Promise<Project> {
|
|
return this.projectsCrudService.updateProject(id, dto);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HttpCode(HttpStatus.NO_CONTENT)
|
|
@ApiOperation({ summary: 'Delete project' })
|
|
remove(@Param('id') id: string): Promise<void> {
|
|
return this.projectsCrudService.removeProject(id);
|
|
}
|
|
}
|