Add topic field to NotificationGetOptions, add router query topic param, add topic filter to DatabaseNotificationsStore.ts, add unit test

Signed-off-by: Vladimir Kobzev <vkobzev@bol.com>
This commit is contained in:
Vladimir Kobzev
2024-06-03 10:58:42 +02:00
parent cb11e2ce01
commit d7b8ca5aca
5 changed files with 29 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-notifications-backend': patch
---
Added an option to filter notifications by topic
@@ -271,6 +271,20 @@ describe.each(databases.eachSupportedId())(
expect(notifications.length).toBe(1);
expect(notifications.at(0)?.id).toEqual(id2);
});
it('should filter notifications based on topic', async () => {
await storage.saveNotification(testNotification1);
await storage.saveNotification(testNotification2);
await storage.saveNotification(testNotification3);
const notifications = await storage.getNotifications({
user,
topic: 'efgh-topic',
});
expect(notifications.length).toBe(1);
expect(notifications.at(0)?.id).toEqual(id1);
});
});
describe('getNotifications filters on severity', () => {
@@ -204,6 +204,10 @@ export class DatabaseNotificationsStore implements NotificationsStore {
query.whereNull('read');
} // or match both if undefined
if (options.topic) {
query.where('topic', '=', options.topic);
}
if (options.saved) {
query.whereNotNull('saved');
} else if (options.saved === false) {
@@ -35,6 +35,7 @@ export type NotificationGetOptions = {
limit?: number;
search?: string;
orderField?: EntityOrder[];
topic?: string;
read?: boolean;
saved?: boolean;
createdAfter?: Date;
@@ -302,6 +302,11 @@ export async function createRouter(
opts.read = false;
// or keep undefined
}
if (req.query.topic) {
opts.topic = req.query.topic.toString();
}
if (req.query.saved === 'true') {
opts.saved = true;
} else if (req.query.saved === 'false') {