From cea894a8bd236d5997e564f7dd88c1c2c5317ef5 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 11 Nov 2022 13:28:37 +0100 Subject: [PATCH] fix: dashboard error --- apps/api/src/lib/common.ts | 2 +- apps/api/src/lib/services.ts | 13 ++++-- apps/api/src/lib/services/handlers.ts | 1 - apps/ui/src/routes/index.svelte | 63 +++++++++++++++++++++------ package.json | 2 +- 5 files changed, 60 insertions(+), 21 deletions(-) diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 352df307e..93ec5a55a 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -17,7 +17,7 @@ import { day } from './dayjs'; import { saveBuildLog } from './buildPacks/common'; import { scheduler } from './scheduler'; -export const version = '3.11.6'; +export const version = '3.11.7'; export const isDev = process.env.NODE_ENV === 'development'; const algorithm = 'aes-256-ctr'; diff --git a/apps/api/src/lib/services.ts b/apps/api/src/lib/services.ts index 17086fa8a..7dfe6f0c8 100644 --- a/apps/api/src/lib/services.ts +++ b/apps/api/src/lib/services.ts @@ -2,11 +2,16 @@ import { isDev } from "./common"; import fs from 'fs/promises'; export async function getTemplates() { const templatePath = isDev ? './templates.json' : '/app/templates.json'; - const ts = await fs.readFile(templatePath, 'utf8') - if (ts) { - return JSON.parse(ts); + const open = await fs.open(templatePath, 'r'); + let data; + try { + data = await open.readFile({ encoding: 'utf-8' }); + return JSON.parse(data); + } catch (error) { + return [] + } finally { + await open?.close() } - return []; } const compareSemanticVersions = (a: string, b: string) => { const a1 = a.split('.'); diff --git a/apps/api/src/lib/services/handlers.ts b/apps/api/src/lib/services/handlers.ts index f0be78133..3cf9c256e 100644 --- a/apps/api/src/lib/services/handlers.ts +++ b/apps/api/src/lib/services/handlers.ts @@ -34,7 +34,6 @@ export async function startService(request: FastifyRequest, fa const { id } = request.params; const teamId = request.user.teamId; const service = await getServiceFromDB({ id, teamId }); - console.log({service}) const arm = isARM(service.arch); const { type, destinationDockerId, destinationDocker, persistentStorage, exposePort } = service; diff --git a/apps/ui/src/routes/index.svelte b/apps/ui/src/routes/index.svelte index 7c0a14f24..190d05b89 100644 --- a/apps/ui/src/routes/index.svelte +++ b/apps/ui/src/routes/index.svelte @@ -90,31 +90,50 @@ return { applications: !onlyOthers && - applications.filter((application: any) => application.teams[0].id === $appSession.teamId), + applications.filter( + (application: any) => + application?.teams.length > 0 && application.teams[0].id === $appSession.teamId + ), otherApplications: applications.filter( - (application: any) => application.teams[0].id !== $appSession.teamId + (application: any) => + application?.teams.length > 0 && application.teams[0].id !== $appSession.teamId ), databases: !onlyOthers && - databases.filter((database: any) => database.teams[0].id === $appSession.teamId), + databases.filter( + (database: any) => + database?.teams.length > 0 && database.teams[0].id === $appSession.teamId + ), otherDatabases: databases.filter( - (database: any) => database.teams[0].id !== $appSession.teamId + (database: any) => database?.teams.length > 0 && database.teams[0].id !== $appSession.teamId ), services: !onlyOthers && - services.filter((service: any) => service.teams[0].id === $appSession.teamId), - otherServices: services.filter((service: any) => service.teams[0].id !== $appSession.teamId), + services.filter( + (service: any) => service?.teams.length > 0 && service.teams[0].id === $appSession.teamId + ), + otherServices: services.filter( + (service: any) => service?.teams.length > 0 && service.teams[0].id !== $appSession.teamId + ), gitSources: !onlyOthers && - gitSources.filter((gitSource: any) => gitSource.teams[0].id === $appSession.teamId), + gitSources.filter( + (gitSource: any) => + gitSource?.teams.length > 0 && gitSource.teams[0].id === $appSession.teamId + ), otherGitSources: gitSources.filter( - (gitSource: any) => gitSource.teams[0].id !== $appSession.teamId + (gitSource: any) => + gitSource?.teams.length > 0 && gitSource.teams[0].id !== $appSession.teamId ), destinations: !onlyOthers && - destinations.filter((destination: any) => destination.teams[0].id === $appSession.teamId), + destinations.filter( + (destination: any) => + destination?.teams.length > 0 && destination.teams[0].id === $appSession.teamId + ), otherDestinations: destinations.filter( - (destination: any) => destination.teams[0].id !== $appSession.teamId + (destination: any) => + destination?.teams.length > 0 && destination.teams[0].id !== $appSession.teamId ) }; } @@ -682,7 +701,11 @@