Added GraphQL queries for alerts and notifications.
This commit is contained in:
@@ -16,6 +16,10 @@ export const alertsSchema = `
|
||||
alert(
|
||||
id: Int!
|
||||
): Alert
|
||||
|
||||
notifications(
|
||||
limit: Int = 10
|
||||
): Notifications
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
@@ -32,6 +36,17 @@ export const alertsSchema = `
|
||||
email: Boolean = false
|
||||
stashes: [Int!]
|
||||
): Alert
|
||||
|
||||
removeAlert(id: Int!): Alert
|
||||
|
||||
updateNotification(
|
||||
id: Int!
|
||||
seen: Boolean
|
||||
): Int!
|
||||
|
||||
updateNotifications(
|
||||
seen: Boolean
|
||||
): Int!
|
||||
}
|
||||
|
||||
type AlertAnd {
|
||||
@@ -100,6 +115,23 @@ export const alertsSchema = `
|
||||
matches: [AlertMatch]
|
||||
stashes: [AlertStash]
|
||||
}
|
||||
|
||||
type Notifications {
|
||||
notifications: [Notification!]!
|
||||
unseen: Int!
|
||||
}
|
||||
|
||||
type Notification {
|
||||
id: Int!
|
||||
alertId: Int
|
||||
sceneId: Int
|
||||
scene: Release
|
||||
isSeen: Boolean!
|
||||
matchedActors: [Actor!]!
|
||||
matchedTags: [Tag!]!
|
||||
matchedEntity: Entity
|
||||
createdAt: Date!
|
||||
}
|
||||
`;
|
||||
|
||||
export async function fetchAlertsApi(req, res) {
|
||||
@@ -121,7 +153,6 @@ export async function createAlertApi(req, res) {
|
||||
}
|
||||
|
||||
export async function createAlertGraphql(query, req) {
|
||||
console.log('CREATE ALERT', query);
|
||||
const alert = await createAlert(query, req.user);
|
||||
|
||||
return alert;
|
||||
@@ -133,6 +164,12 @@ export async function removeAlertApi(req, res) {
|
||||
res.status(204).send();
|
||||
}
|
||||
|
||||
export async function removeAlertGraphql(query, req) {
|
||||
const removedAlert = await removeAlert(query.id, req.user);
|
||||
|
||||
return removedAlert;
|
||||
}
|
||||
|
||||
export async function fetchNotificationsApi(req, res) {
|
||||
const notifications = await fetchNotifications(req.user, {
|
||||
limit: req.query.limit || 10,
|
||||
@@ -141,18 +178,38 @@ export async function fetchNotificationsApi(req, res) {
|
||||
res.send(notifications);
|
||||
}
|
||||
|
||||
export async function fetchNotificationsGraphql(query, req) {
|
||||
const notifications = await fetchNotifications(req.user, {
|
||||
limit: query.limit || 10,
|
||||
});
|
||||
|
||||
return notifications;
|
||||
}
|
||||
|
||||
export async function updateNotificationsApi(req, res) {
|
||||
await updateNotifications(req.body, req.user);
|
||||
|
||||
res.status(204).send();
|
||||
}
|
||||
|
||||
export async function updateNotificationsGraphql(query, req) {
|
||||
const updatedCount = await updateNotifications(query, req.user);
|
||||
|
||||
return updatedCount;
|
||||
}
|
||||
|
||||
export async function updateNotificationApi(req, res) {
|
||||
await updateNotification(req.params.notificationId, req.body, req.user);
|
||||
|
||||
res.status(204).send();
|
||||
}
|
||||
|
||||
export async function updateNotificationGraphql(query, req) {
|
||||
const updatedNotification = await updateNotification(query.id, query, req.user);
|
||||
|
||||
return updatedNotification;
|
||||
}
|
||||
|
||||
export const router = Router();
|
||||
|
||||
router.get('/api/alerts', fetchAlertsApi);
|
||||
|
||||
@@ -50,6 +50,10 @@ import {
|
||||
alertsSchema,
|
||||
fetchAlertsGraphql,
|
||||
createAlertGraphql,
|
||||
removeAlertGraphql,
|
||||
fetchNotificationsGraphql,
|
||||
updateNotificationGraphql,
|
||||
updateNotificationsGraphql,
|
||||
} from './alerts.js';
|
||||
|
||||
import { verifyKey } from '../auth.js';
|
||||
@@ -133,6 +137,7 @@ export async function graphqlApi(req, res) {
|
||||
stashes: async (query) => fetchUserStashesGraphql(query, req),
|
||||
stash: async (query) => fetchStashGraphql(query, req),
|
||||
alerts: async (query) => fetchAlertsGraphql(query, req),
|
||||
notifications: async (query) => fetchNotificationsGraphql(query, req),
|
||||
// stash mutation
|
||||
createStash: async (query) => createStashGraphql(query, req),
|
||||
updateStash: async (query) => updateStashGraphql(query, req),
|
||||
@@ -145,6 +150,9 @@ export async function graphqlApi(req, res) {
|
||||
unstashMovie: async (query) => unstashMovieGraphql(query, req),
|
||||
// alert mutation
|
||||
createAlert: async (query) => createAlertGraphql(query, req),
|
||||
removeAlert: async (query) => removeAlertGraphql(query, req),
|
||||
updateNotification: async (query) => updateNotificationGraphql(query, req),
|
||||
updateNotifications: async (query) => updateNotificationsGraphql(query, req),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ export const scenesSchema = `
|
||||
covers: [Media!]!
|
||||
movies: [Release!]!
|
||||
stashes: [Stash!]
|
||||
isStashed(stash: String!): Boolean
|
||||
}
|
||||
|
||||
type Tag {
|
||||
@@ -173,6 +174,19 @@ function getScope(query) {
|
||||
return 'latest';
|
||||
}
|
||||
|
||||
function attachResolvers(scene) {
|
||||
return {
|
||||
...scene,
|
||||
isStashed(args) {
|
||||
if (!scene.stashes) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return scene.stashes.some((stash) => stash.slug === args.stash) || false;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function fetchScenesGraphql(query, req) {
|
||||
const mainEntity = query.entities?.find((entity) => entity.charAt(0) !== '!');
|
||||
|
||||
@@ -223,7 +237,7 @@ export async function fetchScenesGraphql(query, req) {
|
||||
}, req.user);
|
||||
|
||||
return {
|
||||
nodes: scenes,
|
||||
nodes: scenes.map((scene) => attachResolvers(scene)),
|
||||
total,
|
||||
/* restrict until deemed essential for 3rd party apps
|
||||
aggregates: {
|
||||
@@ -252,10 +266,10 @@ export async function fetchScenesByIdGraphql(query, req) {
|
||||
});
|
||||
|
||||
if (query.ids) {
|
||||
return scenes;
|
||||
return scenes.map((scene) => attachResolvers(scene));
|
||||
}
|
||||
|
||||
return scenes[0];
|
||||
return attachResolvers(scenes[0]);
|
||||
}
|
||||
|
||||
async function fetchSceneRevisionsApi(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user