forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.controller.ts
More file actions
58 lines (54 loc) · 1.92 KB
/
Copy pathprofile.controller.ts
File metadata and controls
58 lines (54 loc) · 1.92 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
import {
Controller,
Get,
Patch,
Body,
Param,
Req,
UseGuards,
ValidationPipe,
} from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
import { ProfileService } from './profile.service';
import { UserProfile } from './profile.entity';
import { UpdateProfileDto } from './dto/update-profile.dto';
import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
import { ProfilePolicyGuard } from './profile-policy.guard';
interface AuthRequest {
user: { walletAddress: string; id: string };
}
@ApiTags('Profile')
@Controller('profile')
export class ProfileController {
constructor(private readonly profileService: ProfileService) {}
@Get(':walletAddress')
@ApiOperation({ summary: 'Get user profile by wallet address' })
@ApiParam({
name: 'walletAddress',
description: 'Stellar wallet address (G...)',
example: 'GDZST3XVCDTUJ76ZAV2HA72KYQODXXZ5PTMAPZGDHZ6CS7RO7MGG3DBM',
})
@ApiResponse({ status: 200, description: 'Profile found', type: UserProfile })
@ApiResponse({ status: 404, description: 'Profile not found for wallet address' })
async getByWalletAddress(
@Param('walletAddress') walletAddress: string,
): Promise<UserProfile> {
return this.profileService.getByWalletAddress(walletAddress);
}
@Patch(':walletAddress')
@UseGuards(JwtAuthGuard, ProfilePolicyGuard)
@ApiOperation({ summary: 'Update user profile (creates if not exists)' })
@ApiParam({
name: 'walletAddress',
description: 'Stellar wallet address (G...)',
})
@ApiResponse({ status: 200, description: 'Profile updated', type: UserProfile })
@ApiResponse({ status: 400, description: 'Validation error (e.g. unsupported currency)' })
async update(
@Param('walletAddress') walletAddress: string,
@Body(ValidationPipe) dto: UpdateProfileDto,
@Req() req: AuthRequest,
): Promise<UserProfile> {
return this.profileService.update(walletAddress, dto);
}
}