28 lines
937 B
TypeScript
28 lines
937 B
TypeScript
import { NotFoundError } from "@/src/entities/errors/common"
|
|
import { IUsersRepository } from "../../repositories/users.repository"
|
|
import { IInstrumentationService } from "../../services/instrumentation.service.interface"
|
|
import { UserResponse } from "@/src/entities/models/users/users.model"
|
|
|
|
|
|
export type IGetCurrentUserUseCase = ReturnType<typeof getCurrentUserUseCase>
|
|
|
|
export const getCurrentUserUseCase = (
|
|
instrumentationService: IInstrumentationService,
|
|
usersRepository: IUsersRepository
|
|
) => async (): Promise<UserResponse> => {
|
|
return await instrumentationService.startSpan({ name: "getCurrentUser Use Case", op: "function" },
|
|
async () => {
|
|
|
|
const existingUser = await usersRepository.getCurrentUser()
|
|
|
|
if (!existingUser) {
|
|
throw new NotFoundError("User not found")
|
|
}
|
|
|
|
return {
|
|
...existingUser
|
|
}
|
|
}
|
|
)
|
|
}
|