diff --git a/apps/api/src/routes/api/v1/destinations/handlers.ts b/apps/api/src/routes/api/v1/destinations/handlers.ts index 11b790316..3966ecab9 100644 --- a/apps/api/src/routes/api/v1/destinations/handlers.ts +++ b/apps/api/src/routes/api/v1/destinations/handlers.ts @@ -54,7 +54,7 @@ export async function getDestination(request: FastifyRequest) { const teamId = request.user?.teamId; const destination = await prisma.destinationDocker.findFirst({ where: { id, teams: { some: { id: teamId === '0' ? undefined : teamId } } }, - include: { sshKey: true } + include: { sshKey: true, application: true, service: true, database: true } }); if (!destination && id !== 'new') { throw { status: 404, message: `Destination not found.` }; diff --git a/apps/ui/src/routes/destinations/[id]/__layout.svelte b/apps/ui/src/routes/destinations/[id]/__layout.svelte index d97c547bc..a653c17aa 100644 --- a/apps/ui/src/routes/destinations/[id]/__layout.svelte +++ b/apps/ui/src/routes/destinations/[id]/__layout.svelte @@ -58,8 +58,10 @@ import DeleteIcon from '$lib/components/DeleteIcon.svelte'; const { id } = $page.params; - + const isDestinationDeletable = destination.application.length === 0 && destination.database.length === 0 && destination.service.length === 0 + async function deleteDestination(destination: any) { + if (!isDestinationDeletable) return const sure = confirm($t('application.confirm_to_delete', { name: destination.name })); if (sure) { try { @@ -70,20 +72,29 @@ } } } + function deletable() { + if (!isDestinationDeletable) { + return "Please delete all resources before deleting this." + } + if ($appSession.isAdmin) { + return $t('destination.delete_destination') + } else { + return $t('destination.permission_denied_delete_destination') + } + } {#if id !== 'new'} {/if}