import { map } from "lodash" ; import { BundlesInUseError } from "../common/errors" ; import Usecase from "../common/Usecase" ; import { Operation } from "../entities/OperationLog" ; export default class DeleteBundlesByNameAndTag extends Usecase { async exec ( name , tag ) { await this . authorizer . ensureCanDeleteBundles ( name ) ; const toBeDeletedBundles = await this . storages . bundles . findManyByNameAndTag ( name , tag ) ; const toBeDeletedBundleIds = map ( toBeDeletedBundles , "id" ) ; const hasLinkedEntrypoints = await this . storages . entrypoints . anyExistsWithBundleIdIn ( toBeDeletedBundleIds ) ; if ( hasLinkedEntrypoints ) { throw new BundlesInUseError ( toBeDeletedBundleIds ) ; } await this . storages . bundles . deleteMany ( toBeDeletedBundleIds ) ; await this . operationLogger . logOperation ( Operation . DeleteBundle , { deletedBundles : toBeDeletedBundles , } ) ; } }