feat: make notification page filters work

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
Heikki Hellgren
2023-12-15 14:41:04 +02:00
parent f24a0c1f6a
commit 92c327211a
11 changed files with 100 additions and 35 deletions
+2
View File
@@ -5,6 +5,7 @@
```ts
import { Notification as Notification_2 } from '@backstage/plugin-notifications-common';
import { NotificationStatus } from '@backstage/plugin-notifications-common';
import { NotificationType } from '@backstage/plugin-notifications-common';
import { PluginDatabaseManager } from '@backstage/backend-common';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
@@ -32,6 +33,7 @@ export class DatabaseNotificationsStore implements NotificationsStore {
// @public (undocumented)
export type NotificationGetOptions = {
user_ref: string;
type?: NotificationType;
};
// @public (undocumented)
@@ -55,15 +55,22 @@ export class DatabaseNotificationsStore implements NotificationsStore {
return typeof val === 'string' ? Number.parseInt(val, 10) : val ?? 0;
};
private getNotificationsBaseQuery = (options: NotificationGetOptions) => {
const { user_ref, type } = options;
const query = this.db('notifications').where('userRef', user_ref);
if (type === 'unread') {
query.whereNull('read');
} else if (type === 'read') {
query.whereNotNull('read');
}
// TODO: Saved
return query;
};
async getNotifications(options: NotificationGetOptions) {
const { user_ref } = options;
const notificationQuery = this.db('notifications').where(
'userRef',
user_ref,
);
const notificationQuery = this.getNotificationsBaseQuery(options);
const notifications = await notificationQuery.select('*');
return notifications;
}
@@ -72,12 +79,7 @@ export class DatabaseNotificationsStore implements NotificationsStore {
}
async getStatus(options: NotificationGetOptions) {
const { user_ref } = options;
const notificationQuery = this.db('notifications').where(
'userRef',
user_ref,
);
const notificationQuery = this.getNotificationsBaseQuery(options);
const unreadQuery = await notificationQuery
.clone()
.whereNull('read')
@@ -17,11 +17,13 @@
import {
Notification,
NotificationStatus,
NotificationType,
} from '@backstage/plugin-notifications-common';
/** @public */
export type NotificationGetOptions = {
user_ref: string;
type?: NotificationType;
};
/** @public */