forked from InsurNiffy/niff-Stellar-shurance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaims.controller.ts
More file actions
125 lines (119 loc) · 4.33 KB
/
Copy pathclaims.controller.ts
File metadata and controls
125 lines (119 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import {
Controller,
Get,
Param,
Query,
UseGuards,
ParseIntPipe,
DefaultValuePipe,
Post,
HttpCode,
HttpStatus,
Body,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiBearerAuth,
ApiQuery,
} from '@nestjs/swagger';
import { Throttle } from '@nestjs/throttler';
import { ClaimsService } from './claims.service';
import { ClaimsListResponseDto, ClaimDetailResponseDto } from './dto/claim.dto';
import { BuildClaimTransactionDto } from './dto/build-claim-transaction.dto';
import { SubmitTransactionDto } from './dto/submit-transaction.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { WalletAddress } from '../auth/decorators/wallet-address.decorator';
import { RateLimitGuard } from '../rate-limit/rate-limit.guard';
import { MAX_LIMIT, DEFAULT_LIMIT } from '../helpers/pagination';
@ApiTags('claims')
@Controller('claims')
export class ClaimsController {
constructor(private readonly claimsService: ClaimsService) {}
@Get()
@ApiOperation({ summary: 'List claims with cursor-based pagination' })
@ApiQuery({
name: 'after',
required: false,
type: String,
description: 'Opaque cursor from a previous response next_cursor. Omit for the first page.',
})
@ApiQuery({
name: 'limit',
required: false,
type: Number,
description: `Items per page. Clamped to [1, ${MAX_LIMIT}]. Default ${DEFAULT_LIMIT}.`,
})
@ApiQuery({
name: 'status',
required: false,
enum: ['pending', 'approved', 'rejected', 'paid'],
description: 'Filter by claim status.',
})
@ApiResponse({ status: 200, description: 'Paginated list of claims', type: ClaimsListResponseDto })
@ApiResponse({ status: 400, description: 'Invalid cursor' })
async listClaims(
@Query('after') after?: string,
@Query('limit', new DefaultValuePipe(DEFAULT_LIMIT), ParseIntPipe) limit?: number,
@Query('status') status?: string,
): Promise<ClaimsListResponseDto> {
return this.claimsService.listClaims({ after, limit, status });
}
@Get('needs-my-vote')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get claims requiring the authenticated user to vote' })
@ApiQuery({
name: 'after',
required: false,
type: String,
description: 'Opaque cursor from a previous response next_cursor.',
})
@ApiQuery({
name: 'limit',
required: false,
type: Number,
description: `Items per page. Clamped to [1, ${MAX_LIMIT}]. Default ${DEFAULT_LIMIT}.`,
})
@ApiResponse({ status: 200, description: 'Claims where user has not voted yet', type: ClaimsListResponseDto })
@ApiResponse({ status: 400, description: 'Invalid cursor' })
@ApiResponse({ status: 401, description: 'Unauthorized' })
async getClaimsNeedingMyVote(
@WalletAddress() walletAddress: string,
@Query('after') after?: string,
@Query('limit', new DefaultValuePipe(DEFAULT_LIMIT), ParseIntPipe) limit?: number,
): Promise<ClaimsListResponseDto> {
return this.claimsService.getClaimsNeedingVote(walletAddress, { after, limit });
}
@Get(':id')
@ApiOperation({ summary: 'Get detailed claim view' })
@ApiResponse({ status: 200, description: 'Detailed claim with vote tallies', type: ClaimDetailResponseDto })
@ApiResponse({ status: 404, description: 'Claim not found' })
async getClaim(@Param('id', ParseIntPipe) id: number): Promise<ClaimDetailResponseDto> {
return this.claimsService.getClaimById(id);
}
@Post('build-transaction')
@HttpCode(HttpStatus.OK)
@Throttle({ default: { limit: 10, ttl: 60_000 } })
@ApiOperation({ summary: 'Build unsigned file_claim transaction' })
@ApiResponse({ status: 200, description: 'Unsigned transaction XDR + fee estimates' })
async buildTransaction(@Body() dto: BuildClaimTransactionDto) {
return this.claimsService.buildTransaction({
holder: dto.holder,
policyId: dto.policyId,
amount: BigInt(dto.amount),
details: dto.details,
imageUrls: dto.imageUrls,
});
}
@Post('submit')
@UseGuards(RateLimitGuard)
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: 'Submit signed claim transaction' })
@ApiResponse({ status: 200, description: 'Transaction submitted' })
@ApiResponse({ status: 429, description: 'Rate limit exceeded' })
async submitTransaction(@Body() dto: SubmitTransactionDto) {
return this.claimsService.submitTransaction(dto.transactionXdr);
}
}