architecture refactoring
This commit is contained in:
30
backend/src/domain/use-cases/auth/get-me.use-case.ts
Normal file
30
backend/src/domain/use-cases/auth/get-me.use-case.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* get-me.use-case.ts
|
||||
* GetMeUseCase: obtiene los datos del usuario autenticado.
|
||||
* - Busca el usuario por ID (que viene del JWT)
|
||||
* - Retorna los datos del usuario
|
||||
*/
|
||||
|
||||
import { AuthRepository } from "../../repositories/auth.repository.js";
|
||||
import { CustomError } from "../../errors/custom.error.js";
|
||||
|
||||
export interface GetMeResponse {
|
||||
id: number;
|
||||
email: string;
|
||||
name: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
export class GetMeUseCase {
|
||||
constructor(private repository: AuthRepository) {}
|
||||
|
||||
async execute(userId: number): Promise<GetMeResponse> {
|
||||
const user = await this.repository.findById(userId);
|
||||
|
||||
if (!user) {
|
||||
throw CustomError.notFound("User not found");
|
||||
}
|
||||
|
||||
return user as GetMeResponse;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user