Exposing stashes on scenes GraphQL object.

This commit is contained in:
2025-04-01 00:55:41 +02:00
parent acef14b02c
commit f5d8c30ff3
5 changed files with 206 additions and 93 deletions

View File

@@ -1,3 +1,5 @@
import Router from 'express-promise-router';
import {
fetchAlerts,
createAlert,
@@ -7,18 +9,124 @@ import {
updateNotification,
} from '../alerts.js';
export const alertsSchema = `
extend type Query {
alerts: [Alert]
alert(
id: Int!
): Alert
}
extend type Mutation {
createAlert(
all: Boolean = true
allActors: Boolean = true
allTags: Boolean = true
allMatches: Boolean = true
actors: [Int!]
tags: [Int!]
entities: [Int!]
matches: [AlertMatchInput!]
notify: Boolean = true
email: Boolean = false
stashes: [Int!]
): Alert
}
type AlertAnd {
fields: Boolean
actors: Boolean
tags: Boolean
entities: Boolean
matches: Boolean
}
type AlertActor {
id: Int
name: String
slug: String
}
type AlertTag {
id: Int
name: String
slug: String
}
enum EntityType {
network
channel
studio
info
}
type AlertEntity {
id: Int
name: String
slug: String
type: EntityType
}
type AlertMatch {
id: Int
property: String
expression: String
}
input AlertMatchInput {
property: String!
expression: String!
}
type AlertStash {
id: Int
name: String
slug: String
isPrimary: Boolean
}
type Alert {
id: Int
notify: Boolean
email: Boolean
isFromPreset: Boolean
isPrimary: Boolean
createdAt: Date
and: AlertAnd
actors: [AlertActor]
tags: [AlertTag]
entities: [AlertEntity]
matches: [AlertMatch]
stashes: [AlertStash]
}
`;
export async function fetchAlertsApi(req, res) {
const alerts = await fetchAlerts(req.user);
res.send(alerts);
}
export async function fetchAlertsGraphql(query, req) {
const alerts = await fetchAlerts(req.user);
return alerts;
}
export async function createAlertApi(req, res) {
const alert = await createAlert(req.body, req.user);
res.send(alert);
}
export async function createAlertGraphql(query, req) {
console.log('CREATE ALERT', query);
const alert = await createAlert(query, req.user);
return alert;
}
export async function removeAlertApi(req, res) {
await Promise.all(req.params.alertId.split(',').map(async (alertId) => removeAlert(alertId, req.user)));
@@ -44,3 +152,13 @@ export async function updateNotificationApi(req, res) {
res.status(204).send();
}
export const router = Router();
router.get('/api/alerts', fetchAlertsApi);
router.post('/api/alerts', createAlertApi);
router.delete('/api/alerts/:alertId', removeAlertApi);
router.get('/api/users/:userId/notifications', fetchNotificationsApi);
router.patch('/api/users/:userId/notifications', updateNotificationsApi);
router.patch('/api/users/:userId/notifications/:notificationId', updateNotificationApi);