25 lines
932 B
TypeScript
25 lines
932 B
TypeScript
import { NotFoundError } from "@/src/entities/errors/common"
|
|
import { IUsersRepository } from "../../repositories/users.repository.interface"
|
|
import { IInstrumentationService } from "../../services/instrumentation.service.interface"
|
|
import { User } from "@/src/entities/models/users/users.model"
|
|
|
|
export type IDeleteUserUseCase = ReturnType<typeof deleteUserUseCase>
|
|
|
|
const deleteUserUseCase = (
|
|
instrumentationService: IInstrumentationService,
|
|
usersRepository: IUsersRepository
|
|
) => async (id: string): Promise<User> => {
|
|
return await instrumentationService.startSpan({ name: "deleteUser Use Case", op: "function" },
|
|
async () => {
|
|
const user = await usersRepository.getUserById(id)
|
|
|
|
if (!user) {
|
|
throw new NotFoundError("User not found")
|
|
}
|
|
|
|
const deletedUser = await usersRepository.deleteUser(id)
|
|
|
|
return deletedUser
|
|
}
|
|
)
|
|
} |