| 1 | import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common'; |
| 2 | import { ApiOperation, ApiTags } from '@nestjs/swagger'; |
| 3 | import { AccountGroupService } from './accountGroup.service'; |
| 4 | import { ApiResult } from '../../../common/decorators/api-result.decorator'; |
| 5 | import { AccountGroup } from '../../../db/schema/accountGroup.schema'; |
| 6 | import { GetToken } from '../../../auth/auth.guard'; |
| 7 | import { TokenInfo } from '../../../auth/interfaces/auth.interfaces'; |
| 8 | import { ParamsValidationPipe } from '../../../validation.pipe'; |
| 9 | import { |
| 10 | CreateAccountGroupDto, |
| 11 | DeleteAccountGroupDto, |
| 12 | UpdateAccountGroupDto, |
| 13 | } from './dto/accountGroup.dto'; |
| 14 | import { Account } from '../../../db/schema/account.schema'; |
| 15 | |
| 16 | @ApiTags('账户组') |
| 17 | @Controller('accountGroup') |
| 18 | export class AccountGroupController { |
| 19 | constructor(private readonly accountGroupService: AccountGroupService) {} |
| 20 | |
| 21 | @ApiOperation({ summary: '创建组' }) |
| 22 | @Post('create') |
| 23 | @ApiResult({ type: AccountGroup }) |
| 24 | async create( |
| 25 | @GetToken() token: TokenInfo, |
| 26 | @Body(new ParamsValidationPipe()) body: CreateAccountGroupDto, |
| 27 | ) { |
| 28 | return this.accountGroupService.addOrUpdateAccountGroup({ |
| 29 | userId: token.id, |
| 30 | ...body, |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | @ApiOperation({ summary: '更新组' }) |
| 35 | @Post('update') |
| 36 | @ApiResult({ type: AccountGroup }) |
| 37 | async update( |
| 38 | @GetToken() token: TokenInfo, |
| 39 | @Body(new ParamsValidationPipe()) body: UpdateAccountGroupDto, |
| 40 | ) { |
| 41 | return this.accountGroupService.addOrUpdateAccountGroup({ |
| 42 | userId: token.id, |
| 43 | ...body, |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | @ApiOperation({ summary: '删除账户组' }) |
| 48 | @Post('deletes') |
| 49 | @ApiResult({ type: AccountGroup }) |
| 50 | async deletes( |
| 51 | @GetToken() token: TokenInfo, |
| 52 | @Body(new ParamsValidationPipe()) body: DeleteAccountGroupDto, |
| 53 | ) { |
| 54 | return this.accountGroupService.deleteAccountGroup(body.ids, token.id); |
| 55 | } |
| 56 | |
| 57 | @ApiOperation({ summary: '获取用户所有账户组' }) |
| 58 | @Get('getList') |
| 59 | @ApiResult({ type: [Account] }) |
| 60 | async getUserAccounts(@GetToken() token: TokenInfo) { |
| 61 | return this.accountGroupService.getAccountGroup(token.id); |
| 62 | } |
| 63 | } |
| 64 |