25 lines
547 B
TypeScript
25 lines
547 B
TypeScript
|
|
|
|
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;
|
|
}
|
|
} |