From 997e729535813448dc7c50a514300d15de6d6047 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Thu, 24 Oct 2024 16:46:08 +0200 Subject: [PATCH] refactor: Use hooks with refetched record for app config --- packages/backend/src/models/app-config.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/models/app-config.js b/packages/backend/src/models/app-config.js index a4f3a0fb..a996f378 100644 --- a/packages/backend/src/models/app-config.js +++ b/packages/backend/src/models/app-config.js @@ -55,15 +55,21 @@ class AppConfig extends Base { } async computeConnectionAllowedProperty() { - const appAuthClients = await this.$relatedQuery('appAuthClients'); + const refetchedRecord = await AppConfig.query().findOne({ key: this.key }); + + if (!refetchedRecord) return; + + const appAuthClients = await refetchedRecord.$relatedQuery( + 'appAuthClients' + ); const hasSomeActiveAppAuthClients = appAuthClients?.some((appAuthClient) => appAuthClient.active) || false; const conditions = [ hasSomeActiveAppAuthClients, - this.shared, - !this.disabled, + refetchedRecord.shared, + !refetchedRecord.disabled, ]; const connectionAllowed = conditions.every(Boolean);