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 tagIds = (await getIdsBySlug(alert.tags, 'tags') || []).concat(alert.tagIds || []);
const entityIds = (await getIdsBySlug(alert.entities || [], 'entities')).concat(alert.entityIds || []); 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); 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'); .returning('id');
await Promise.all([ 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, alert_id: alertId,
actor_id: actorId, actor_id: actorId,
}))), }))),
@ -187,7 +189,7 @@ export async function createAlert(alert, reqUser) {
? match.expression.slice(1, -1) ? match.expression.slice(1, -1)
: escapeRegexp(match.expression), : 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, alert_id: alertId,
stash_id: stashId, stash_id: stashId,
}))), }))),

View File

@ -9,6 +9,7 @@ import {
updateNotification, updateNotification,
} from '../alerts.js'; } from '../alerts.js';
// actors and actorIds, stashes and stashIds are aliases for consistency
export const alertsSchema = ` export const alertsSchema = `
extend type Query { extend type Query {
alerts: [Alert] alerts: [Alert]
@ -29,6 +30,7 @@ export const alertsSchema = `
allTags: Boolean = true allTags: Boolean = true
allMatches: Boolean = true allMatches: Boolean = true
actors: [Int!] actors: [Int!]
actorIds: [Int!]
tags: [String!] tags: [String!]
tagIds: [Int!] tagIds: [Int!]
entities: [String!] entities: [String!]
@ -37,6 +39,7 @@ export const alertsSchema = `
notify: Boolean = true notify: Boolean = true
email: Boolean = false email: Boolean = false
stashes: [Int!] stashes: [Int!]
stashIds: [Int!]
comment: String comment: String
meta: JSON meta: JSON
): Alert ): Alert