Skip to content

Commit

Permalink
refactor: applied suggested changes on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelSBatista97 committed Dec 9, 2022
1 parent 807e4cf commit 95628f1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable } from '@nestjs/common';
import RequestWithUser from 'src/libs/interfaces/requestWithUser.interface';
import UpdateUserDto from '../dto/update.user.dto';
import UserDto from '../dto/user.dto';
import { UpdateUserApplication } from '../interfaces/applications/update.user.service.interface';
import { UpdateUserService } from '../interfaces/services/update.user.service.interface';
import { TYPES } from '../interfaces/types';
Expand All @@ -24,7 +24,7 @@ export class UpdateUserApplicationImpl implements UpdateUserApplication {
return this.updateUserService.checkEmail(token);
}

updateSuperAdmin(user: UpdateUserDto, requestUser: RequestWithUser) {
updateSuperAdmin(user: UpdateUserDto, requestUser: UserDto) {
return this.updateUserService.updateSuperAdmin(user, requestUser);
}
}
2 changes: 1 addition & 1 deletion backend/src/modules/users/controller/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ export default class UsersController {
@UseGuards(SuperAdminGuard)
@Put('/sadmin')
updateUserSuperAdmin(@Req() request: RequestWithUser, @Body() userData: UpdateUserDto) {
return this.updateUserApp.updateSuperAdmin(userData, request);
return this.updateUserApp.updateSuperAdmin(userData, request.user);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LeanDocument } from 'mongoose';
import UpdateUserDto from '../../dto/update.user.dto';
import User, { UserDocument } from '../../entities/user.schema';
import RequestWithUser from 'src/libs/interfaces/requestWithUser.interface';
import UserDto from '../../dto/user.dto';

export interface UpdateUserApplication {
setCurrentRefreshToken(
Expand All @@ -17,8 +17,5 @@ export interface UpdateUserApplication {

checkEmail(token: string): Promise<string>;

updateSuperAdmin(
user: UpdateUserDto,
requestUser: RequestWithUser
): Promise<LeanDocument<UserDocument>>;
updateSuperAdmin(user: UpdateUserDto, requestUser: UserDto): Promise<LeanDocument<UserDocument>>;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LeanDocument } from 'mongoose';
import UpdateUserDto from '../../dto/update.user.dto';
import User, { UserDocument } from '../../entities/user.schema';
import RequestWithUser from 'src/libs/interfaces/requestWithUser.interface';
import UserDto from '../../dto/user.dto';

export interface UpdateUserService {
setCurrentRefreshToken(refreshToken: string, userId: string): Promise<User | null>;
Expand All @@ -14,8 +14,5 @@ export interface UpdateUserService {

checkEmail(token: string): Promise<string>;

updateSuperAdmin(
user: UpdateUserDto,
requestUser: RequestWithUser
): Promise<LeanDocument<UserDocument>>;
updateSuperAdmin(user: UpdateUserDto, requestUser: UserDto): Promise<LeanDocument<UserDocument>>;
}
6 changes: 3 additions & 3 deletions backend/src/modules/users/services/update.user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { TYPES } from '../interfaces/types';
import { UserRepositoryInterface } from '../repository/user.repository.interface';
import User, { UserDocument } from '../entities/user.schema';
import { UPDATE_FAILED } from 'src/libs/exceptions/messages';
import RequestWithUser from 'src/libs/interfaces/requestWithUser.interface';
import UserDto from '../dto/user.dto';

@Injectable()
export default class updateUserServiceImpl implements UpdateUserService {
Expand Down Expand Up @@ -61,8 +61,8 @@ export default class updateUserServiceImpl implements UpdateUserService {
}
}

async updateSuperAdmin(user: UpdateUserDto, requestUser: RequestWithUser) {
if (requestUser.user._id.toString() === user._id) {
async updateSuperAdmin(user: UpdateUserDto, requestUser: UserDto) {
if (requestUser._id.toString() === user._id) {
throw new BadRequestException(UPDATE_FAILED);
}
const userUpdated = await this.userRepository.updateSuperAdmin(user._id, user.isSAdmin);
Expand Down

0 comments on commit 95628f1

Please sign in to comment.