forked from Yara724/api
Preserve actor and user profile fields during partial updates and validate supported personal data. Add Persian HTTP error handling, validation translations, regression tests, and audit documentation.
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { Controller, Get, Body, Patch, UseGuards } from "@nestjs/common";
|
|
import { ApiBearerAuth, ApiBody, ApiTags } from "@nestjs/swagger";
|
|
import { GlobalGuard } from "src/auth/guards/global.guard";
|
|
import { CurrentUser } from "src/decorators/user.decorator";
|
|
import { Roles } from "src/decorators/roles.decorator";
|
|
import { UpdateUserProfileDtoRq } from "./dto/user/update-profile.dto";
|
|
import { ProfileService } from "./profile.service";
|
|
|
|
@Controller("user/profile")
|
|
@ApiTags("user")
|
|
@ApiBearerAuth()
|
|
@Roles()
|
|
export class ProfileController {
|
|
constructor(private readonly profileService: ProfileService) {}
|
|
|
|
@Get()
|
|
@UseGuards(GlobalGuard)
|
|
async getProfile(@CurrentUser() user) {
|
|
return await this.profileService.getProfileDetail(user.username, user.sub);
|
|
}
|
|
|
|
@Patch()
|
|
@UseGuards(GlobalGuard)
|
|
@ApiBody({ type: UpdateUserProfileDtoRq })
|
|
async updateProfile(
|
|
@CurrentUser() user,
|
|
@Body() body: UpdateUserProfileDtoRq,
|
|
) {
|
|
return await this.profileService.updateProfile(
|
|
user.username,
|
|
body as Record<string, unknown>,
|
|
user.sub,
|
|
);
|
|
}
|
|
}
|