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