Added actorIds and stashIds aliases to new alert API for consistency.

This commit is contained in:
DebaucheryLibrarian 2025-04-04 06:09:56 +02:00
parent 6492439f56
commit cb47e3fd9e
2 changed files with 8 additions and 3 deletions

View File

@ -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,
}))),

View File

@ -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