From 930857cf735e102ebf1be7e8772cc251a3ddc1a2 Mon Sep 17 00:00:00 2001 From: Robin Genz Date: Mon, 10 Jun 2024 16:59:39 +0200 Subject: [PATCH] fix: throw error if no app exists --- src/commands/apps/bundles/create.ts | 4 ++++ src/commands/apps/bundles/delete.ts | 4 ++++ src/commands/apps/bundles/update.ts | 4 ++++ src/commands/apps/channels/create.ts | 4 ++++ src/commands/apps/channels/delete.ts | 4 ++++ src/commands/apps/delete.ts | 4 ++++ src/commands/apps/devices/delete.ts | 4 ++++ 7 files changed, 28 insertions(+) diff --git a/src/commands/apps/bundles/create.ts b/src/commands/apps/bundles/create.ts index 888a4d3..589435f 100644 --- a/src/commands/apps/bundles/create.ts +++ b/src/commands/apps/bundles/create.ts @@ -64,6 +64,10 @@ export default defineCommand({ } if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before creating a bundle.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to deploy to:', { type: 'select', diff --git a/src/commands/apps/bundles/delete.ts b/src/commands/apps/bundles/delete.ts index e9c944b..091d276 100644 --- a/src/commands/apps/bundles/delete.ts +++ b/src/commands/apps/bundles/delete.ts @@ -25,6 +25,10 @@ export default defineCommand({ let bundleId = ctx.args.bundleId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before deleting a bundle.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to delete the bundle from?', { type: 'select', diff --git a/src/commands/apps/bundles/update.ts b/src/commands/apps/bundles/update.ts index df05cb5..6a222f5 100644 --- a/src/commands/apps/bundles/update.ts +++ b/src/commands/apps/bundles/update.ts @@ -52,6 +52,10 @@ export default defineCommand({ let bundleId = ctx.args.bundleId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before updating a bundle.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to update the bundle for?', { type: 'select', diff --git a/src/commands/apps/channels/create.ts b/src/commands/apps/channels/create.ts index afe5ca6..63efe55 100644 --- a/src/commands/apps/channels/create.ts +++ b/src/commands/apps/channels/create.ts @@ -23,6 +23,10 @@ export default defineCommand({ let appId = ctx.args.appId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before creating a channel.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to delete the channel from?', { type: 'select', diff --git a/src/commands/apps/channels/delete.ts b/src/commands/apps/channels/delete.ts index a6d07be..8a92f31 100644 --- a/src/commands/apps/channels/delete.ts +++ b/src/commands/apps/channels/delete.ts @@ -23,6 +23,10 @@ export default defineCommand({ let appId = ctx.args.appId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before deleting a bundle.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to delete the channel from?', { type: 'select', diff --git a/src/commands/apps/delete.ts b/src/commands/apps/delete.ts index bdda873..5621f83 100644 --- a/src/commands/apps/delete.ts +++ b/src/commands/apps/delete.ts @@ -18,6 +18,10 @@ export default defineCommand({ let appId = ctx.args.appId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before deleting it.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to delete?', { type: 'select', diff --git a/src/commands/apps/devices/delete.ts b/src/commands/apps/devices/delete.ts index 5add299..aa97413 100644 --- a/src/commands/apps/devices/delete.ts +++ b/src/commands/apps/devices/delete.ts @@ -23,6 +23,10 @@ export default defineCommand({ let appId = ctx.args.appId; if (!appId) { const apps = await appsService.findAll(); + if (!apps.length) { + consola.error('You must create an app before deleting a device.'); + return; + } // @ts-ignore wait till https://github.com/unjs/consola/pull/280 is merged appId = await prompt('Which app do you want to delete the device from?', { type: 'select',