Merge pull request #28904 from drodil/topics_null

fix(notifications): filter null topics
This commit is contained in:
Patrik Oldsberg
2025-02-20 09:34:17 +01:00
committed by GitHub
3 changed files with 10 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend': patch
---
Fix null topics being returned from notification API
@@ -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 });
@@ -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) };
}
}