Added alert dialog context trigger to quick alert bell.
This commit is contained in:
@@ -49,7 +49,7 @@ function curateAlert(alert, context = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchAlerts(user) {
|
||||
export async function fetchAlerts(user, alertIds) {
|
||||
const {
|
||||
alerts,
|
||||
actors,
|
||||
@@ -60,31 +60,61 @@ export async function fetchAlerts(user) {
|
||||
} = await promiseProps({
|
||||
alerts: knex('alerts')
|
||||
.where('user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('id', alertIds);
|
||||
}
|
||||
})
|
||||
.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')
|
||||
.leftJoin('actors', 'actors.id', 'alerts_actors.actor_id')
|
||||
.where('alerts.user_id', user.id),
|
||||
.where('alerts.user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('alerts.id', alertIds);
|
||||
}
|
||||
}),
|
||||
tags: knex('alerts_tags')
|
||||
.select('alerts_tags.*', 'tags.name as tag_name', 'tags.slug as tag_slug')
|
||||
.leftJoin('alerts', 'alerts.id', 'alerts_tags.alert_id')
|
||||
.leftJoin('tags', 'tags.id', 'alerts_tags.tag_id')
|
||||
.where('alerts.user_id', user.id),
|
||||
.where('alerts.user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('alerts.id', alertIds);
|
||||
}
|
||||
}),
|
||||
entities: knex('alerts_entities')
|
||||
.select('alerts_entities.*', 'entities.name as entity_name', 'entities.slug as entity_slug', 'entities.type as entity_type')
|
||||
.leftJoin('alerts', 'alerts.id', 'alerts_entities.alert_id')
|
||||
.leftJoin('entities', 'entities.id', 'alerts_entities.entity_id')
|
||||
.where('alerts.user_id', user.id),
|
||||
.where('alerts.user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('alerts.id', alertIds);
|
||||
}
|
||||
}),
|
||||
matches: knex('alerts_matches')
|
||||
.select('alerts_matches.*')
|
||||
.leftJoin('alerts', 'alerts.id', 'alerts_matches.alert_id')
|
||||
.where('alerts.user_id', user.id),
|
||||
.where('alerts.user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('alerts.id', alertIds);
|
||||
}
|
||||
}),
|
||||
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),
|
||||
.where('alerts.user_id', user.id)
|
||||
.where((builder) => {
|
||||
if (alertIds) {
|
||||
builder.whereIn('alerts.id', alertIds);
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
const curatedAlerts = alerts.map((alert) => curateAlert(alert, {
|
||||
@@ -157,7 +187,9 @@ export async function createAlert(alert, reqUser) {
|
||||
alert.entities?.length > 0 && knex.schema.refreshMaterializedView('alerts_users_entities'),
|
||||
]);
|
||||
|
||||
return alertId;
|
||||
const [newAlert] = await fetchAlerts(reqUser, [alertId]);
|
||||
|
||||
return newAlert;
|
||||
}
|
||||
|
||||
export async function removeAlert(alertId, reqUser) {
|
||||
|
||||
@@ -14,9 +14,9 @@ export async function fetchAlertsApi(req, res) {
|
||||
}
|
||||
|
||||
export async function createAlertApi(req, res) {
|
||||
const alertId = await createAlert(req.body, req.user);
|
||||
const alert = await createAlert(req.body, req.user);
|
||||
|
||||
res.send({ id: alertId });
|
||||
res.send(alert);
|
||||
}
|
||||
|
||||
export async function removeAlertApi(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user