Improved alerts overview.

This commit is contained in:
2024-05-28 05:49:28 +02:00
parent cb5d931309
commit 2dbfd556e1
4 changed files with 257 additions and 64 deletions

View File

@@ -39,6 +39,12 @@ function curateAlert(alert, context = {}) {
property: match.property,
expression: match.expression,
})) || [],
stashes: context.stashes?.map((stash) => ({
id: stash.stash_id,
name: stash.stash_name,
slug: stash.stash_slug,
isPrimary: stash.stash_primary,
})) || [],
};
}
@@ -49,9 +55,11 @@ export async function fetchAlerts(user) {
tags,
entities,
matches,
stashes,
} = await promiseProps({
alerts: knex('alerts')
.where('user_id', user.id),
.where('user_id', user.id)
.orderBy('created_at', 'desc'),
actors: knex('alerts_actors')
.select('alerts_actors.*', 'actors.name as actor_name', 'actors.slug as actor_slug')
.leftJoin('alerts', 'alerts.id', 'alerts_actors.alert_id')
@@ -71,6 +79,11 @@ export async function fetchAlerts(user) {
.select('alerts_matches.*')
.leftJoin('alerts', 'alerts.id', 'alerts_matches.alert_id')
.where('alerts.user_id', user.id),
stashes: knex('alerts_stashes')
.select('alerts_stashes.*', 'stashes.id as stash_id', 'stashes.name as stash_name', 'stashes.slug as stash_slug', 'stashes.primary as stash_primary')
.leftJoin('alerts', 'alerts.id', 'alerts_stashes.alert_id')
.leftJoin('stashes', 'stashes.id', 'alerts_stashes.stash_id')
.where('alerts.user_id', user.id),
});
const curatedAlerts = alerts.map((alert) => curateAlert(alert, {
@@ -78,6 +91,7 @@ export async function fetchAlerts(user) {
tags: tags.filter((tag) => tag.alert_id === alert.id),
entities: entities.filter((entity) => entity.alert_id === alert.id),
matches: matches.filter((match) => match.alert_id === alert.id),
stashes: stashes.filter((stash) => stash.alert_id === alert.id),
}));
return curatedAlerts;