Spaces:
Sleeping
Sleeping
File size: 2,728 Bytes
f183c60 ed9da92 f183c60 ed9da92 f183c60 ed9da92 f183c60 ed9da92 f183c60 ed9da92 f183c60 ed9da92 f183c60 | 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 | import {
Controller,
Get,
Put,
Patch,
Body,
Param,
ParseIntPipe,
UseGuards,
Request,
} from '@nestjs/common';
import {
ApiTags,
ApiOperation,
ApiResponse,
ApiBearerAuth,
ApiParam,
} from '@nestjs/swagger';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { UserManagementService } from './user-management.service';
import {
UpdateProfileDto,
UpdateUserPreferencesDto,
ChangePasswordDto,
} from './dto/user-management.dto';
@ApiTags('User Profile')
@ApiBearerAuth('JWT-auth')
@Controller('api/users')
@UseGuards(JwtAuthGuard)
export class UserProfileController {
constructor(private readonly userManagementService: UserManagementService) {}
@Get('profile')
@ApiOperation({ summary: 'Get current user profile' })
@ApiResponse({
status: 200,
description: 'User profile with completeness score',
})
async getProfile(@Request() req) {
return this.userManagementService.getProfile(req.user.userId);
}
@Put('profile')
@ApiOperation({ summary: 'Update current user profile' })
@ApiResponse({ status: 200, description: 'Updated profile' })
async updateProfile(@Request() req, @Body() dto: UpdateProfileDto) {
return this.userManagementService.updateProfile(req.user.userId, dto);
}
@Get('preferences')
@ApiOperation({ summary: 'Get user preferences' })
@ApiResponse({ status: 200, description: 'User preferences' })
async getPreferences(@Request() req) {
return this.userManagementService.getPreferences(req.user.userId);
}
@Get(':id/public')
@ApiOperation({ summary: 'Get public profile for a user' })
@ApiParam({ name: 'id', type: Number, description: 'User ID' })
@ApiResponse({
status: 200,
description:
'Public profile returned with non-sensitive contact details (email and social links)',
})
@ApiResponse({ status: 404, description: 'User not found' })
async getPublicProfile(@Param('id', ParseIntPipe) userId: number) {
return this.userManagementService.getPublicProfile(userId);
}
@Put('preferences')
@ApiOperation({ summary: 'Update user preferences' })
@ApiResponse({ status: 200, description: 'Updated preferences' })
async updatePreferences(
@Request() req,
@Body() dto: UpdateUserPreferencesDto,
) {
return this.userManagementService.updatePreferences(req.user.userId, dto);
}
@Patch('password')
@ApiOperation({ summary: 'Change password' })
@ApiResponse({ status: 200, description: 'Password changed successfully' })
@ApiResponse({ status: 400, description: 'Current password is incorrect' })
async changePassword(@Request() req, @Body() dto: ChangePasswordDto) {
return this.userManagementService.changePassword(req.user.userId, dto);
}
}
|