|
| 1 | +// src/transfers/controllers/transfer.controller.ts |
| 2 | +import { |
| 3 | + Controller, |
| 4 | + Get, |
| 5 | + Post, |
| 6 | + Put, |
| 7 | + Delete, |
| 8 | + Body, |
| 9 | + Param, |
| 10 | + Query, |
| 11 | + UseGuards, |
| 12 | + Request, |
| 13 | + HttpCode, |
| 14 | + HttpStatus, |
| 15 | +} from '@nestjs/common'; |
| 16 | +import { ApprovalRuleService } from '../services/approval-rule.service'; |
| 17 | +import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; |
| 18 | +import { ApproveTransferDto } from '../dto/approve-transfer.dto'; |
| 19 | +import { CreateApprovalRuleDto } from '../dto/create-approval-rule.dto'; |
| 20 | +import { CreateTransferDto } from '../dto/create-transfer.dto'; |
| 21 | +import { QueryTransfersDto } from '../dto/query-transfers.dto'; |
| 22 | +import { RejectTransferDto } from '../dto/reject-transfer.dto'; |
| 23 | +import { UpdateApprovalRuleDto } from '../dto/update-approval-rule.dto'; |
| 24 | +import { TransferService } from '../services/transfers.service'; |
| 25 | + |
| 26 | +@Controller('api/v1/transfers') |
| 27 | +@UseGuards(JwtAuthGuard) |
| 28 | +export class TransferController { |
| 29 | + constructor( |
| 30 | + private readonly transferService: TransferService, |
| 31 | + private readonly approvalRuleService: ApprovalRuleService, |
| 32 | + ) {} |
| 33 | + |
| 34 | + @Post() |
| 35 | + async create(@Body() createTransferDto: CreateTransferDto, @Request() req) { |
| 36 | + return this.transferService.create(createTransferDto, req.user.id); |
| 37 | + } |
| 38 | + |
| 39 | + @Get() |
| 40 | + async findAll(@Query() query: QueryTransfersDto) { |
| 41 | + return this.transferService.findAll(query); |
| 42 | + } |
| 43 | + |
| 44 | + @Get('pending-approval') |
| 45 | + async getPendingApprovals(@Request() req) { |
| 46 | + return this.transferService.getPendingApprovals(req.user.id); |
| 47 | + } |
| 48 | + |
| 49 | + @Get(':id') |
| 50 | + async findOne(@Param('id') id: string) { |
| 51 | + return this.transferService.findOne(id); |
| 52 | + } |
| 53 | + |
| 54 | + @Put(':id/approve') |
| 55 | + async approve( |
| 56 | + @Param('id') id: string, |
| 57 | + @Body() dto: ApproveTransferDto, |
| 58 | + @Request() req, |
| 59 | + ) { |
| 60 | + return this.transferService.approve(id, req.user.id, dto); |
| 61 | + } |
| 62 | + |
| 63 | + @Put(':id/reject') |
| 64 | + async reject( |
| 65 | + @Param('id') id: string, |
| 66 | + @Body() dto: RejectTransferDto, |
| 67 | + @Request() req, |
| 68 | + ) { |
| 69 | + return this.transferService.reject(id, req.user.id, dto); |
| 70 | + } |
| 71 | + |
| 72 | + @Delete(':id') |
| 73 | + @HttpCode(HttpStatus.NO_CONTENT) |
| 74 | + async cancel(@Param('id') id: string, @Request() req) { |
| 75 | + await this.transferService.cancel(id, req.user.id); |
| 76 | + } |
| 77 | + |
| 78 | + @Post(':id/execute') |
| 79 | + async execute(@Param('id') id: string, @Request() req) { |
| 80 | + return this.transferService.executeTransfer(id, req.user.id); |
| 81 | + } |
| 82 | + |
| 83 | + @Post(':id/undo') |
| 84 | + async undo(@Param('id') id: string, @Request() req) { |
| 85 | + return this.transferService.undoTransfer(id, req.user.id); |
| 86 | + } |
| 87 | + |
| 88 | + // Approval Rules endpoints |
| 89 | + @Post('approval-rules') |
| 90 | + async createRule(@Body() dto: CreateApprovalRuleDto) { |
| 91 | + return this.approvalRuleService.create(dto); |
| 92 | + } |
| 93 | + |
| 94 | + @Get('approval-rules') |
| 95 | + async findAllRules() { |
| 96 | + return this.approvalRuleService.findAll(); |
| 97 | + } |
| 98 | + |
| 99 | + @Put('approval-rules/:id') |
| 100 | + async updateRule( |
| 101 | + @Param('id') id: string, |
| 102 | + @Body() dto: UpdateApprovalRuleDto, |
| 103 | + ) { |
| 104 | + return this.approvalRuleService.update(id, dto); |
| 105 | + } |
| 106 | + |
| 107 | + @Delete('approval-rules/:id') |
| 108 | + @HttpCode(HttpStatus.NO_CONTENT) |
| 109 | + async deleteRule(@Param('id') id: string) { |
| 110 | + await this.approvalRuleService.remove(id); |
| 111 | + } |
| 112 | +} |
0 commit comments