import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Patch,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import { RoleDto } from '../dto/role.dto';
import { TokenDataEntity } from '../../common/entities/token-data.entity';
import { RoleService } from '../service/role.service';

@ApiTags('系统管理 - 角色')
@ApiBearerAuth()
@Controller('system/role')
export class RoleController {
  constructor(private readonly roleService: RoleService) {}

  @Post()
  async create(@Body() roleDto: RoleDto, @TokenData() token: TokenDataEntity) {
    roleDto.creator = roleDto.updater = token.userId;
    return this.roleService.create(roleDto);
  }

  @Get()
  async findAll() {
    return this.roleService.findAll();
  }

  @Patch(':id')
  async update(@Param('id') id: string, @Body() roleDto: RoleDto) {
    return this.roleService.update(+id, roleDto);
  }

  @Delete(':id')
  async remove(@Param('id') id: string) {
    return this.roleService.remove(+id);
  }
}
