feat: add createdAfter filtering to the Notifications
Signed-off-by: Marek Libra <marek.libra@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user