mirror of
https://github.com/unraid/api.git
synced 2026-01-23 17:08:36 -06:00
feat: add notifications mutation
This commit is contained in:
@@ -8,6 +8,7 @@ import GraphQLLong from 'graphql-type-long';
|
||||
import GraphQLUUID from 'graphql-type-uuid';
|
||||
import { GraphQLDateTime } from 'graphql-iso-date';
|
||||
import { Query } from './query';
|
||||
import { Mutation } from './mutation';
|
||||
import { Subscription } from './subscription';
|
||||
import { UserAccount } from './user-account';
|
||||
|
||||
@@ -18,6 +19,7 @@ export const DateTime = GraphQLDateTime;
|
||||
|
||||
export {
|
||||
Query,
|
||||
Mutation,
|
||||
Subscription,
|
||||
UserAccount
|
||||
};
|
||||
|
||||
9
app/graphql/resolvers/mutation/index.ts
Normal file
9
app/graphql/resolvers/mutation/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
/*!
|
||||
* Copyright 2019-2020 Lime Technology Inc. All rights reserved.
|
||||
* Written by: Alexis Tyler
|
||||
*/
|
||||
import notifications from './notifications';
|
||||
|
||||
export const Mutation = {
|
||||
notifications
|
||||
};
|
||||
42
app/graphql/resolvers/mutation/notifications.ts
Normal file
42
app/graphql/resolvers/mutation/notifications.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/*!
|
||||
* Copyright 2021 Lime Technology Inc. All rights reserved.
|
||||
* Written by: Alexis Tyler
|
||||
*/
|
||||
|
||||
import { ensurePermission } from '../../../core/utils';
|
||||
import { mothership } from '../../../mothership/subscribe-to-servers';
|
||||
import { Context } from '../../schema/utils';
|
||||
|
||||
export default async (_: unknown, __: unknown, context: Context) => {
|
||||
const { user } = context;
|
||||
|
||||
// Check permissions
|
||||
ensurePermission(user, {
|
||||
resource: 'notifications',
|
||||
action: 'create',
|
||||
possession: 'own'
|
||||
});
|
||||
|
||||
console.log('notification mutation', { _, __, context });
|
||||
|
||||
const notification = {};
|
||||
|
||||
// Prepare query
|
||||
const query = mothership.request({
|
||||
query: 'mutation ($notification: notificationInput) {\n sendNotification(notification: $notification)\n}\n',
|
||||
variables: {
|
||||
notification
|
||||
}
|
||||
});
|
||||
|
||||
// Send notification to mothership
|
||||
query.subscribe({
|
||||
next: async ({ data, errors }) => {
|
||||
if (!errors || errors.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('FAILED_SENDING_NOTIFICATION', errors);
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -27,6 +27,7 @@ const files = [
|
||||
'./dist/types/graphql/schema/types/info/os.graphql',
|
||||
'./dist/types/graphql/schema/types/info/system.graphql',
|
||||
'./dist/types/graphql/schema/types/info/versions.graphql',
|
||||
'./dist/types/graphql/schema/types/notifications/notifications.graphql',
|
||||
'./dist/types/graphql/schema/types/owner/owner.graphql',
|
||||
'./dist/types/graphql/schema/types/plugins/plugin.graphql',
|
||||
'./dist/types/graphql/schema/types/registration/registration.graphql',
|
||||
|
||||
28
app/graphql/schema/types/notifications/notifications.graphql
Normal file
28
app/graphql/schema/types/notifications/notifications.graphql
Normal file
@@ -0,0 +1,28 @@
|
||||
input NotificationInput {
|
||||
title: String
|
||||
subject: String
|
||||
description: String
|
||||
importance: Importance!
|
||||
link: String
|
||||
}
|
||||
|
||||
type Mutation {
|
||||
sendNotification(notification: NotificationInput!): Notification
|
||||
}
|
||||
|
||||
enum Importance {
|
||||
# Logs
|
||||
info
|
||||
# Warnings
|
||||
warning
|
||||
# Errors
|
||||
alert
|
||||
}
|
||||
|
||||
type Notification {
|
||||
title: String!
|
||||
subject: String!
|
||||
description: String!
|
||||
importance: Importance!
|
||||
link: String!
|
||||
}
|
||||
Reference in New Issue
Block a user