From 5696fe0030861bc9455514a411804ec00bbfe935 Mon Sep 17 00:00:00 2001 From: Dean Date: Fri, 15 Mar 2024 16:52:38 +0000 Subject: [PATCH] Fix to for tenant favourite prefix --- .../worker/src/api/controllers/global/self.ts | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/worker/src/api/controllers/global/self.ts b/packages/worker/src/api/controllers/global/self.ts index d2741116e5..d762f5168a 100644 --- a/packages/worker/src/api/controllers/global/self.ts +++ b/packages/worker/src/api/controllers/global/self.ts @@ -114,9 +114,16 @@ export const syncAppFavourites = async (processedAppIds: string[]) => { if (processedAppIds.length === 0) { return [] } - const apps = await fetchAppsByIds(processedAppIds) + + const tenantId = tenancy.getTenantId() + const appPrefix = + tenantId === tenancy.DEFAULT_TENANT_ID + ? dbCore.APP_DEV_PREFIX + : `${dbCore.APP_DEV_PREFIX}${tenantId}_` + + const apps = await fetchAppsByIds(processedAppIds, appPrefix) return apps?.reduce((acc: string[], app) => { - const id = app.appId.replace(dbCore.APP_DEV_PREFIX, "") + const id = app.appId.replace(appPrefix, "") if (processedAppIds.includes(id)) { acc.push(id) } @@ -124,9 +131,14 @@ export const syncAppFavourites = async (processedAppIds: string[]) => { }, []) } -export const fetchAppsByIds = async (processedAppIds: string[]) => { +export const fetchAppsByIds = async ( + processedAppIds: string[], + appPrefix: string +) => { return await dbCore.getAppsByIDs( - processedAppIds.map(appId => `${dbCore.APP_DEV_PREFIX}${appId}`) + processedAppIds.map(appId => { + return `${appPrefix}${appId}` + }) ) }