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);
|
||||
|
||||
Reference in New Issue
Block a user