Simplifica start:prod e ajusta consultas de ofertas para 10x (codplpagmax=42), com melhorias de sanitização e imports.
24 lines
738 B
TypeScript
24 lines
738 B
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { UserRepository } from '../users/UserRepository';
|
|
import * as md5 from 'md5';
|
|
|
|
@Injectable()
|
|
export class ChangePasswordService {
|
|
constructor(private readonly userRepository: UserRepository) {}
|
|
|
|
async execute(userId: number, oldPassword: string, newPassword: string) {
|
|
const current = await this.userRepository.findByIdAndPassword(
|
|
userId,
|
|
md5(oldPassword).toUpperCase(),
|
|
);
|
|
|
|
if (!current) {
|
|
throw new NotFoundException('Usuário não encontrado ou senha inválida');
|
|
}
|
|
|
|
const newPasswordHash = md5(newPassword).toUpperCase();
|
|
await this.userRepository.updatePassword(userId, newPasswordHash);
|
|
return current;
|
|
}
|
|
}
|