diff --git a/.changeset/itchy-houses-whisper.md b/.changeset/itchy-houses-whisper.md new file mode 100644 index 0000000000..2b633dbdee --- /dev/null +++ b/.changeset/itchy-houses-whisper.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-notifications-backend': patch +--- + +Fix null topics being returned from notification API diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d4edcd1e89..0386b516a2 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -14,9 +14,9 @@ * limitations under the License. */ import { + mockServices, TestDatabaseId, TestDatabases, - mockServices, } from '@backstage/backend-test-utils'; import { DatabaseNotificationsStore } from './DatabaseNotificationsStore'; import { Knex } from 'knex'; @@ -748,6 +748,7 @@ describe.each(databases.eachSupportedId())( await storage.saveNotification(testNotification1); await storage.saveNotification(testNotification2); await storage.saveBroadcast(testNotification3); + await storage.saveNotification(testNotification4); // One without topic await storage.saveNotification(otherUserNotification); const topics = await storage.getTopics({ user }); diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index cf19874ff2..b258f38e7a 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -570,7 +570,9 @@ export class DatabaseNotificationsStore implements NotificationsStore { ...options, orderField: [{ field: 'topic', order: 'asc' }], }); - const topics = await notificationQuery.distinct(['topic']); + const topics = await notificationQuery + .whereNotNull('topic') + .distinct(['topic']); return { topics: topics.map(row => row.topic) }; } }