@arsendoman/book-publisher-store
Version:
A Nest.js package for book publishing and storing
121 lines (112 loc) • 3.61 kB
text/typescript
import {
Body,
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Patch,
Put,
Request,
SerializeOptions,
UseGuards,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { Roles } from '../../database/mongo/schemas';
import { AllowedRoles } from 'src/application/decorators/roles.decorator';
import { PermissionGuard } from 'src/application/guards/auth.guard';
import { RequestInterface } from 'src/application/auth/types/request.auth';
import { ProfileResponseDto } from 'src/application/dtos/response/profile/profile.response.dto';
import { ProfileService } from 'src/application/services/profiles/profiles.service';
import { JwtAuthGuard } from '../../application/guards/jwt.auth.guard';
import { ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import { RoleUpdateDto } from '../../application/dtos/request/profile/profileUpdate.dto';
import { ProfileDto } from '../../application/dtos/request/profile/profileDto';
export class ProfileController {
constructor(private readonly profileService: ProfileService) {}
getCurrentProfile(
req: RequestInterface,
id: string,
): Promise<ProfileResponseDto> {
if (req.user.role == 'customer' && req.user.id !== id) {
throw new HttpException(
'You do not have a permissions to see this profile',
HttpStatus.FORBIDDEN,
);
}
return this.profileService.getCurrentProfile(id);
}
getAllProfilesInfo(
req: RequestInterface,
): Promise<ProfileResponseDto[]> {
return this.profileService.getAllProfiles(req.user.id);
}
deleteCurrentProfile( id: string) {
this.profileService.deleteCurrentProfile(id);
return HttpStatus.NO_CONTENT;
}
updateProfileInfo(
profileUpdateDto: ProfileDto,
req: RequestInterface,
id: string,
): Promise<ProfileResponseDto> {
if (req.user.role == 'customer' && req.user.id !== id) {
throw new HttpException(
'You do not have a permissions to update this profile',
HttpStatus.FORBIDDEN,
);
}
return this.profileService.updateUserProfile(id, profileUpdateDto);
}
updateUserRole(
id: string, // Specify the type explicitly as 'string'
userRole: RoleUpdateDto,
): Promise<ProfileResponseDto> {
return this.profileService.updateUserRole(id, userRole);
}
}