import { UserNotFoundError } from "../common/errors" ; import Usecase from "../common/Usecase" ; import { Operation } from "../entities/OperationLog" ; export default class DeleteUser extends Usecase { async exec ( id ) { await this . authorizer . ensureCanDeleteUser ( ) ; const toBeDeletedUser = await this . storages . users . findOne ( id ) ; if ( ! toBeDeletedUser ) { throw new UserNotFoundError ( id ) ; } await this . storages . users . deleteOne ( id ) ; await this . operationLogger . logOperation ( Operation . DeleteUser , { deletedUser : toBeDeletedUser , } ) ; } }