✨ Improving comprehension of code
This commit is contained in:
parent
70845595df
commit
1d8642b61f
@ -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;
|
||||
}
|
||||
|
@ -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>({
|
||||
|
Loading…
x
Reference in New Issue
Block a user