import { AppHasEntrypointsError , AppNotFoundError } from "../common/errors" ; import Usecase from "../common/Usecase" ; import { Operation } from "../entities/OperationLog" ; export default class DeleteApp extends Usecase { async exec ( id ) { const toBeDeletedApp = await this . storages . apps . findOne ( id ) ; if ( ! toBeDeletedApp ) { throw new AppNotFoundError ( id , "id" ) ; } await this . authorizer . ensureCanDeleteApp ( toBeDeletedApp . name ) ; const hasLinkedEntrypoints = await this . storages . entrypoints . anyExistsWithAppId ( id ) ; if ( hasLinkedEntrypoints ) { throw new AppHasEntrypointsError ( id ) ; } await this . storages . apps . deleteOne ( id ) ; await this . operationLogger . logOperation ( Operation . DeleteApp , { deletedApp : toBeDeletedApp , } ) ; } }