59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { Body, Controller, Get, HttpStatus, Patch } from '@nestjs/common';
|
|
import { UsersService } from './providers/users.service';
|
|
import { ActiveUser } from '@/common/decorators/active-user.decorator';
|
|
import { User } from './entities/user.entity';
|
|
import { UpdateProfileDTO } from './dtos/update-profile.dto';
|
|
import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator';
|
|
import { GetProfileDTO } from './dtos/responses/get-profile.dto';
|
|
|
|
@Controller('users')
|
|
export class UsersController {
|
|
constructor(
|
|
/**
|
|
* Inject Users Service
|
|
*/
|
|
private readonly usersService: UsersService,
|
|
) {}
|
|
|
|
@Get('profile')
|
|
@ApiAppResponse([
|
|
{
|
|
status: HttpStatus.OK,
|
|
variants: [
|
|
{
|
|
model: GetProfileDTO,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
status: HttpStatus.UNAUTHORIZED,
|
|
variants: [
|
|
{
|
|
messageExample: 'دسترسی غیر مجاز',
|
|
},
|
|
],
|
|
},
|
|
])
|
|
public getUserProfile(@ActiveUser() user: User) {
|
|
return this.usersService.getProfile(user);
|
|
}
|
|
|
|
@Patch('profile')
|
|
@ApiAppResponse([
|
|
{
|
|
status: HttpStatus.OK,
|
|
variants: [
|
|
{
|
|
messageExample: 'تغییرات با موفقیت اعمال شد.',
|
|
},
|
|
],
|
|
},
|
|
])
|
|
public async updateUserProfile(
|
|
@ActiveUser() user: User,
|
|
@Body() updateProfileDto: UpdateProfileDTO,
|
|
) {
|
|
return await this.usersService.updateProfile(user, updateProfileDto);
|
|
}
|
|
}
|