import { GroupHasUsersError , GroupNotFoundError } 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 . ensureCanDeleteGroup ( ) ; const toBeDeletedGroup = await this . storages . groups . findOne ( id ) ; if ( ! toBeDeletedGroup ) { throw new GroupNotFoundError ( id ) ; } const hasLinkedUsers = await this . storages . users . anyExistsWithGroup ( id ) ; if ( hasLinkedUsers ) { throw new GroupHasUsersError ( id ) ; } await this . storages . groups . deleteOne ( id ) ; await this . operationLogger . logOperation ( Operation . DeleteGroup , { deletedGroup : toBeDeletedGroup , } ) ; } }