Skip to content

Commit

Permalink
OV-8: * modify find method in user repository instead of findById
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanchousina committed Aug 21, 2024
1 parent b4fbbde commit a88eca1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
14 changes: 8 additions & 6 deletions backend/src/bundles/users/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class UserRepository implements Repository {
this.userModel = userModel;
}

public find(): ReturnType<Repository['find']> {
return Promise.resolve(null);
public async find(userId: number): Promise<UserEntity | null> {
const user = await this.userModel.query().findById(userId).execute();

return user ? UserEntity.initialize(user) : null;
}

public async findByEmail(email: string): Promise<UserEntity | null> {
Expand All @@ -20,11 +22,11 @@ class UserRepository implements Repository {
return user ? UserEntity.initialize(user) : null;
}

public async findById(userId: number): Promise<UserEntity | null> {
const user = await this.userModel.query().findById(userId).execute();
// public async findById(userId: number): Promise<UserEntity | null> {
// const user = await this.userModel.query().findById(userId).execute();

return user ? UserEntity.initialize(user) : null;
}
// return user ? UserEntity.initialize(user) : null;
// }

public async findAll(): Promise<UserEntity[]> {
const users = await this.userModel.query().execute();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/bundles/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserService implements Service {
}

public async find(userId: number): Promise<UserEntity | null> {
return await this.userRepository.findById(userId);
return await this.userRepository.find(userId);
}

public async findByEmail(email: string): Promise<UserEntity | null> {
Expand Down
3 changes: 1 addition & 2 deletions backend/src/common/types/repository.type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
type Repository<T = unknown> = {
find(): Promise<T>;
find(userId: number): Promise<T | null>;
findAll(): Promise<T[]>;
create(payload: unknown): Promise<T>;
update(): Promise<T>;
delete(): Promise<boolean>;
findById(userId: number): Promise<T | null>;
};

export { type Repository };

0 comments on commit a88eca1

Please sign in to comment.