Skip to content

Commit

Permalink
feat: update user repository method to update user by email efficiently
Browse files Browse the repository at this point in the history
  • Loading branch information
ribeirogab committed Sep 16, 2024
1 parent d05bee7 commit d7ec5e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface UserRepository {
updateByEmail(dto: {
email: string;
update: Partial<Omit<User, 'id' | 'email' | 'created_at'>>;
}): Promise<User>;
}): Promise<void>;
}
24 changes: 21 additions & 3 deletions src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,26 @@ export class UserRepository implements UserRepositoryInterface {
return this.users.find((user) => user.email === dto.email) || null;
}

// Temporary method to get all users
public find(): User[] {
return this.users;
public async updateByEmail({
update,
email,
}: {
update: Partial<Omit<User, 'id' | 'email' | 'created_at'>>;
email: string;
}): Promise<void> {
const user = this.users.find((model) => model.email === email);

if (!user) {
return;
}

const updatedUser = {
...user,
...update,
};

this.users.splice(this.users.indexOf(user), 1, updatedUser);

this.logger.debug('User updated:', updatedUser);
}
}

0 comments on commit d7ec5e4

Please sign in to comment.