- 基于 NestJS + TypeScript + MySQL + Redis 架构 - 完整的模块化设计(认证、用户、小组、游戏、预约等) - JWT 认证和 RBAC 权限控制系统 - Docker 容器化部署支持 - 添加 CLAUDE.md 项目开发指南 - 配置 .gitignore 忽略文件 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
85 lines
2.4 KiB
TypeScript
85 lines
2.4 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Body,
|
|
Patch,
|
|
Param,
|
|
Delete,
|
|
UseGuards,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { AssetsService } from './assets.service';
|
|
import { CreateAssetDto, UpdateAssetDto, BorrowAssetDto, ReturnAssetDto } from './dto/asset.dto';
|
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
|
|
@ApiTags('assets')
|
|
@Controller('assets')
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
export class AssetsController {
|
|
constructor(private readonly assetsService: AssetsService) {}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: '创建资产(管理员)' })
|
|
create(@CurrentUser() user, @Body() createDto: CreateAssetDto) {
|
|
return this.assetsService.create(user.id, createDto);
|
|
}
|
|
|
|
@Get('group/:groupId')
|
|
@ApiOperation({ summary: '查询小组资产列表' })
|
|
findAll(@Param('groupId') groupId: string) {
|
|
return this.assetsService.findAll(groupId);
|
|
}
|
|
|
|
@Get(':id')
|
|
@ApiOperation({ summary: '查询资产详情' })
|
|
findOne(@CurrentUser() user, @Param('id') id: string) {
|
|
return this.assetsService.findOne(id, user.id);
|
|
}
|
|
|
|
@Patch(':id')
|
|
@ApiOperation({ summary: '更新资产(管理员)' })
|
|
update(
|
|
@CurrentUser() user,
|
|
@Param('id') id: string,
|
|
@Body() updateDto: UpdateAssetDto,
|
|
) {
|
|
return this.assetsService.update(user.id, id, updateDto);
|
|
}
|
|
|
|
@Post(':id/borrow')
|
|
@ApiOperation({ summary: '借用资产' })
|
|
borrow(
|
|
@CurrentUser() user,
|
|
@Param('id') id: string,
|
|
@Body() borrowDto: BorrowAssetDto,
|
|
) {
|
|
return this.assetsService.borrow(user.id, id, borrowDto);
|
|
}
|
|
|
|
@Post(':id/return')
|
|
@ApiOperation({ summary: '归还资产' })
|
|
returnAsset(
|
|
@CurrentUser() user,
|
|
@Param('id') id: string,
|
|
@Body() returnDto: ReturnAssetDto,
|
|
) {
|
|
return this.assetsService.return(user.id, id, returnDto.note);
|
|
}
|
|
|
|
@Get(':id/logs')
|
|
@ApiOperation({ summary: '查询资产借还记录' })
|
|
getLogs(@Param('id') id: string) {
|
|
return this.assetsService.getLogs(id);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: '删除资产(管理员)' })
|
|
remove(@CurrentUser() user, @Param('id') id: string) {
|
|
return this.assetsService.remove(user.id, id);
|
|
}
|
|
}
|