Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, IsEmail, IsStrongPassword, MaxLength } from 'class-validator';

export class ChangeUsualUserPasswordDs {
export class ChangeUsualUserPasswordDto {
@ApiProperty()
@IsNotEmpty()
@IsString()
Expand All @@ -26,3 +26,7 @@ export class ChangeUsualUserPasswordDs {
@IsString()
oldPassword: string;
}

export class ChangeUsualUserPasswordDs extends ChangeUsualUserPasswordDto {
userId: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { IGlobalDatabaseContext } from '../../../common/application/global-datab
import { BaseType } from '../../../common/data-injection.tokens.js';
import { Messages } from '../../../exceptions/text/messages.js';
import { Encryptor } from '../../../helpers/encryption/encryptor.js';
import { ChangeUsualUserPasswordDs } from '../application/data-structures/change-usual-user-password.ds.js';
import {
ChangeUsualUserPasswordDs,
ChangeUsualUserPasswordDto,
} from '../application/data-structures/change-usual-user-password.ds.js';
import { generateGwtToken, IToken } from '../utils/generate-gwt-token.js';
import { IUsualPasswordChange } from './user-use-cases.interfaces.js';
import { get2FaScope } from '../utils/is-jwt-scope-need.util.js';

@Injectable()
export class ChangeUsualPasswordUseCase
extends AbstractUseCase<ChangeUsualUserPasswordDs, IToken>
extends AbstractUseCase<ChangeUsualUserPasswordDto, IToken>
implements IUsualPasswordChange
{
constructor(
Expand All @@ -22,7 +25,7 @@ export class ChangeUsualPasswordUseCase
}

protected async implementation(userData: ChangeUsualUserPasswordDs): Promise<IToken> {
const user = await this._dbContext.userRepository.findOneUserByEmail(userData.email);
const user = await this._dbContext.userRepository.findOneUserById(userData.email);
if (!user) {
throw new NotFoundException(Messages.USER_NOT_FOUND);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { InTransactionEnum } from '../../../enums/index.js';
import { ChangeUserEmailDs } from '../application/data-structures/change-user-email.ds.js';
import { ChangeUserNameDS } from '../application/data-structures/change-user-name.ds.js';
import { ChangeUsualUserPasswordDs } from '../application/data-structures/change-usual-user-password.ds.js';
import { ChangeUsualUserPasswordDto } from '../application/data-structures/change-usual-user-password.ds.js';
import { CreateUserDs } from '../application/data-structures/create-user.ds.js';
import { CreatedUserDs } from '../application/data-structures/created-user.ds.js';
import { FindUserDs } from '../application/data-structures/find-user.ds.js';
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface IFacebookLogin {
}

export interface IUsualPasswordChange {
execute(inputData: ChangeUsualUserPasswordDs, inTransaction: InTransactionEnum): Promise<IToken>;
execute(inputData: ChangeUsualUserPasswordDto, inTransaction: InTransactionEnum): Promise<IToken>;
}

export interface IVerifyEmail {
Expand Down
8 changes: 5 additions & 3 deletions backend/src/entities/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Constants } from '../../helpers/constants/constants.js';
import { SentryInterceptor } from '../../interceptors/index.js';
import { ChangeUserEmailDs } from './application/data-structures/change-user-email.ds.js';
import { ChangeUserNameDS } from './application/data-structures/change-user-name.ds.js';
import { ChangeUsualUserPasswordDs } from './application/data-structures/change-usual-user-password.ds.js';
import { ChangeUsualUserPasswordDs, ChangeUsualUserPasswordDto } from './application/data-structures/change-usual-user-password.ds.js';
import { FindUserDs } from './application/data-structures/find-user.ds.js';
import { FoundUserDto } from './dto/found-user.dto.js';
import { OperationResultMessageDs } from './application/data-structures/operation-result-message.ds.js';
Expand Down Expand Up @@ -198,7 +198,7 @@ export class UserController {
}

@ApiOperation({ summary: 'Change user password' })
@ApiBody({ type: ChangeUsualUserPasswordDs })
@ApiBody({ type: ChangeUsualUserPasswordDto })
@ApiResponse({
status: 201,
description: 'Change user password.',
Expand All @@ -207,13 +207,15 @@ export class UserController {
@Post('user/password/change/')
async changeUsualPassword(
@Res({ passthrough: true }) response: Response,
@Body() changePasswordData: ChangeUsualUserPasswordDs,
@Body() changePasswordData: ChangeUsualUserPasswordDto,
@UserId() userId: string,
): Promise<ITokenExp> {
const { email, newPassword, oldPassword } = changePasswordData;
const inputData: ChangeUsualUserPasswordDs = {
email: email,
newPassword: newPassword,
oldPassword: oldPassword,
userId: userId,
};
const tokenInfo = await this.changeUsualPasswordUseCase.execute(inputData, InTransactionEnum.ON);
response.cookie(Constants.JWT_COOKIE_KEY_NAME, tokenInfo.token, {
Expand Down
1 change: 1 addition & 0 deletions backend/src/entities/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export class UserModule implements NestModule {
{ path: 'user/settings', method: RequestMethod.POST },
{ path: 'user/settings', method: RequestMethod.GET },
{ path: 'user/test/connections/display/', method: RequestMethod.PUT },
{ path: 'user/password/change', method: RequestMethod.POST },
)
.apply(TemporaryAuthMiddleware)
.forRoutes({ path: 'user/otp/login', method: RequestMethod.POST })
Expand Down
Loading