feat: implement full DepartmentsController with 9 endpoints

This commit is contained in:
2026-07-05 23:48:43 +08:00
parent 0e08770cf4
commit ca53f9471b

View File

@@ -1,7 +1,78 @@
import { Controller } from '@nestjs/common';
import {
Controller,
Get,
Post,
Put,
Delete,
Body,
Param,
ParseIntPipe,
UseGuards,
} from '@nestjs/common';
import { DepartmentsService } from './departments.service';
import {
CreateDepartmentDto,
UpdateDepartmentDto,
AssignUserDto,
} from './dto/department.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
@Controller('api/departments')
@UseGuards(JwtAuthGuard)
@Controller('departments')
export class DepartmentsController {
constructor(private readonly departmentsService: DepartmentsService) {}
@Get()
findAll() {
return this.departmentsService.findAll();
}
@Get('tree')
findTree() {
return this.departmentsService.findTree();
}
@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return this.departmentsService.findOne(id);
}
@Post()
create(@Body() dto: CreateDepartmentDto) {
return this.departmentsService.create(dto);
}
@Put(':id')
update(
@Param('id', ParseIntPipe) id: number,
@Body() dto: UpdateDepartmentDto,
) {
return this.departmentsService.update(id, dto);
}
@Delete(':id')
remove(@Param('id', ParseIntPipe) id: number) {
return this.departmentsService.remove(id);
}
@Get(':id/users')
getUsers(@Param('id', ParseIntPipe) id: number) {
return this.departmentsService.getUsers(id);
}
@Post(':id/users')
assignUser(
@Param('id', ParseIntPipe) id: number,
@Body() dto: AssignUserDto,
) {
return this.departmentsService.assignUser(id, dto);
}
@Delete(':id/users/:userId')
removeUser(
@Param('id', ParseIntPipe) id: number,
@Param('userId', ParseIntPipe) userId: number,
) {
return this.departmentsService.removeUser(id, userId);
}
}