feat: add createdAfter filtering to the Notifications

Signed-off-by: Marek Libra <marek.libra@gmail.com>
This commit is contained in:
Marek Libra
2024-02-22 12:06:47 +01:00
parent 94c4fe2782
commit 5d9c5ba0a6
9 changed files with 71 additions and 36 deletions
@@ -106,6 +106,10 @@ export class DatabaseNotificationsStore implements NotificationsStore {
query.orderBy('created', options.sortOrder ?? 'desc');
}
if (options.createdAfter) {
query.where('created', '>=', options.createdAfter.valueOf());
}
if (options.limit) {
query.limit(options.limit);
}
@@ -31,6 +31,7 @@ export type NotificationGetOptions = {
sortOrder?: 'asc' | 'desc';
read?: boolean;
saved?: boolean;
createdAfter?: Date;
};
/** @internal */
@@ -204,6 +204,13 @@ export async function createRouter(
opts.read = false;
// or keep undefined
}
if (req.query.created_after) {
const sinceEpoch = Date.parse(req.query.created_after.toString());
if (isNaN(sinceEpoch)) {
throw new InputError('Unexpected date format');
}
opts.createdAfter = new Date(sinceEpoch);
}
const notifications = await store.getNotifications(opts);
res.send(notifications);