From cb47e3fd9ec4a69e5ce007ff9dbe1d94a4ae27d5 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Fri, 4 Apr 2025 06:09:56 +0200 Subject: [PATCH] Added actorIds and stashIds aliases to new alert API for consistency. --- src/alerts.js | 8 +++++--- src/web/alerts.js | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/alerts.js b/src/alerts.js index e149f04..10121fb 100755 --- a/src/alerts.js +++ b/src/alerts.js @@ -138,8 +138,10 @@ export async function createAlert(alert, reqUser) { const tagIds = (await getIdsBySlug(alert.tags, 'tags') || []).concat(alert.tagIds || []); const entityIds = (await getIdsBySlug(alert.entities || [], 'entities')).concat(alert.entityIds || []); + const actorIds = [...(alert.actors || []), ...(alert.actorIds || [])]; // for consistency with tagIds and entityIds + const stashIds = [...(alert.stashes || []), ...(alert.stashIds || [])]; // for consistency with tagIds and entityIds - if ((!alert.actors || alert.actors.length === 0) && tagIds.length === 0 && entityIds.length === 0 && (!alert.matches || alert.matches.length === 0)) { + if (actorIds.length === 0 && tagIds.length === 0 && entityIds.length === 0 && (!alert.matches || alert.matches.length === 0)) { throw new HttpError('Alert must contain at least one actor, tag or entity', 400); } @@ -172,7 +174,7 @@ export async function createAlert(alert, reqUser) { .returning('id'); await Promise.all([ - alert.actors?.length > 0 && knex('alerts_actors').insert(alert.actors.map((actorId) => ({ + actorIds?.length > 0 && knex('alerts_actors').insert(actorIds.map((actorId) => ({ alert_id: alertId, actor_id: actorId, }))), @@ -187,7 +189,7 @@ export async function createAlert(alert, reqUser) { ? match.expression.slice(1, -1) : escapeRegexp(match.expression), }))), - alert.stashes?.length > 0 && knex('alerts_stashes').insert(alert.stashes.map((stashId) => ({ + stashIds?.length > 0 && knex('alerts_stashes').insert(stashIds.map((stashId) => ({ alert_id: alertId, stash_id: stashId, }))), diff --git a/src/web/alerts.js b/src/web/alerts.js index 4d9dca8..4ea1c98 100755 --- a/src/web/alerts.js +++ b/src/web/alerts.js @@ -9,6 +9,7 @@ import { updateNotification, } from '../alerts.js'; +// actors and actorIds, stashes and stashIds are aliases for consistency export const alertsSchema = ` extend type Query { alerts: [Alert] @@ -29,6 +30,7 @@ export const alertsSchema = ` allTags: Boolean = true allMatches: Boolean = true actors: [Int!] + actorIds: [Int!] tags: [String!] tagIds: [Int!] entities: [String!] @@ -37,6 +39,7 @@ export const alertsSchema = ` notify: Boolean = true email: Boolean = false stashes: [Int!] + stashIds: [Int!] comment: String meta: JSON ): Alert