Adding alerted scene to stashes.
This commit is contained in:
@@ -51,11 +51,11 @@ async function removeAlert(alertId) {
|
||||
|
||||
async function notify(scenes) {
|
||||
const releases = await knex.raw(`
|
||||
SELECT alerts.id as alert_id, alerts.notify, alerts.email, releases.id as scene_id, users.id as user_id
|
||||
SELECT alerts.id as alert_id, alerts.notify, alerts.email, releases.id as scene_id, users.id as user_id, COALESCE(json_agg(alerts_stashes.stash_id) FILTER (WHERE alerts_stashes.stash_id IS NOT NULL), '[]') as stashes
|
||||
FROM releases
|
||||
CROSS JOIN alerts
|
||||
LEFT JOIN users ON users.id = alerts.user_id
|
||||
LEFT JOIN releases_tags ON releases_tags.release_id = releases.id
|
||||
LEFT JOIN alerts_stashes ON alerts_stashes.alert_id = alerts.id
|
||||
/* match updated IDs from input */
|
||||
WHERE (releases.id = ANY(:sceneIds))
|
||||
/* match tags */
|
||||
@@ -111,15 +111,26 @@ async function notify(scenes) {
|
||||
sceneIds: scenes.map(scene => scene.id),
|
||||
});
|
||||
|
||||
const notifications = releases.rows.filter(alert => alert.notify);
|
||||
|
||||
await knex('notifications')
|
||||
.insert(notifications.map(notification => ({
|
||||
const notifications = releases.rows
|
||||
.filter(alert => alert.notify)
|
||||
.map(notification => ({
|
||||
user_id: notification.user_id,
|
||||
alert_id: notification.alert_id,
|
||||
scene_id: notification.scene_id,
|
||||
}));
|
||||
|
||||
const stashes = releases.rows
|
||||
.filter(release => release.stashes.length > 0)
|
||||
.flatMap(release => release.stashes.map(stash => ({
|
||||
scene_id: release.scene_id,
|
||||
stash_id: stash,
|
||||
})));
|
||||
|
||||
await Promise.all([
|
||||
knex('notifications').insert(notifications),
|
||||
knex('stashes_scenes').insert(stashes),
|
||||
]);
|
||||
|
||||
return releases.rows;
|
||||
}
|
||||
|
||||
@@ -133,8 +144,6 @@ async function updateNotification(notificationId, notification, sessionUser) {
|
||||
}
|
||||
|
||||
async function updateNotifications(notification, sessionUser) {
|
||||
console.log(notification, sessionUser.id);
|
||||
|
||||
await knex('notifications')
|
||||
.where('user_id', sessionUser.id)
|
||||
.update({
|
||||
|
||||
Reference in New Issue
Block a user