Improving comprehension of code

This commit is contained in:
Maxime Lalo 2023-12-04 11:17:31 +01:00
parent 70845595df
commit 1d8642b61f
2 changed files with 6 additions and 7 deletions

View File

@ -6,7 +6,6 @@ import CustomersService, {
InvalidPasswordError,
InvalidTotpCodeError,
NotRegisteredCustomerError,
PasswordAlreadySetError,
SmsNotExpiredError,
TooSoonForNewCode,
TotpCodeExpiredError,
@ -141,7 +140,7 @@ export default class AuthController extends ApiController {
}
try {
const customer = await this.customerService.setFirstPassword(email, totpCode, password);
const customer = await this.customerService.setPassword(email, totpCode, password);
if (!customer) {
this.httpBadRequest(response, "Customer not found");
return;
@ -153,7 +152,7 @@ export default class AuthController extends ApiController {
const refreshToken = this.authService.generateRefreshToken(payload);
this.httpSuccess(response, { accessToken, refreshToken });
} catch (error) {
if (error instanceof TotpCodeExpiredError || error instanceof PasswordAlreadySetError) {
if (error instanceof TotpCodeExpiredError) {
this.httpBadRequest(response, error.message);
return;
}

View File

@ -180,7 +180,7 @@ export default class CustomersService extends BaseService {
* @param password
* @returns
*/
public async setFirstPassword(email: string, totpCode: string, password: string): Promise<Customer | null> {
public async setPassword(email: string, totpCode: string, password: string): Promise<Customer | null> {
// 1: Check if the customer exists
const customer = await this.getByEmail(email);
if (!customer) return null;
@ -212,7 +212,7 @@ export default class CustomersService extends BaseService {
const hashedPassword = await this.authService.hashPassword(password);
// 7: Set the password in database and return the result of the update
return await this.setPassword(customer, hashedPassword);
return await this.setPasswordInDatabase(customer, hashedPassword);
}
/**
@ -300,7 +300,7 @@ export default class CustomersService extends BaseService {
* @description : Set password for a customer
* @throws {Error} If customer cannot be updated
*/
private async setPassword(customer: Customer, password: string) {
private async setPasswordInDatabase(customer: Customer, password: string) {
return await this.customerRepository.update(
customer.uid as string,
Customer.hydrate<Customer>({