From 1d8642b61fed3d3467463f805bc31ec49767cc08 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Mon, 4 Dec 2023 11:17:31 +0100 Subject: [PATCH] :sparkles: Improving comprehension of code --- src/app/api/customer/AuthController.ts | 5 ++--- .../customer/CustomersService/CustomersService.ts | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/api/customer/AuthController.ts b/src/app/api/customer/AuthController.ts index f4067dd9..55c922a2 100644 --- a/src/app/api/customer/AuthController.ts +++ b/src/app/api/customer/AuthController.ts @@ -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; } diff --git a/src/services/customer/CustomersService/CustomersService.ts b/src/services/customer/CustomersService/CustomersService.ts index 46a0843b..922455f8 100644 --- a/src/services/customer/CustomersService/CustomersService.ts +++ b/src/services/customer/CustomersService/CustomersService.ts @@ -180,7 +180,7 @@ export default class CustomersService extends BaseService { * @param password * @returns */ - public async setFirstPassword(email: string, totpCode: string, password: string): Promise { + public async setPassword(email: string, totpCode: string, password: string): Promise { // 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({ @@ -360,7 +360,7 @@ export default class CustomersService extends BaseService { // Envoi du SMS if (!customer.contact?.phone_number) return; - let success = await selectedProvider.sendSms(customer.contact?.phone_number, totpPin.toString()); + let success = await selectedProvider.sendSms(customer.contact?.phone_number, totpPin.toString()); // Si l'envoi échoue, basculez automatiquement sur le second fournisseur if (!success) {