diff --git a/app/graphql/mutations/notifications/delete_notification.rb b/app/graphql/mutations/notifications/delete_notification.rb new file mode 100644 index 0000000..0f951f9 --- /dev/null +++ b/app/graphql/mutations/notifications/delete_notification.rb @@ -0,0 +1,25 @@ +module Mutations + module Notifications + class DeleteNotification < BaseMutation + graphql_name 'DeleteNotification' + + # Input argument to indicate which notification to delete. + argument :id, ID, required: true + + # The response indicates success and returns any errors. + field :success, Boolean, null: false + field :errors, [String], null: false + + def resolve(id:) + notification = Notification.find_by(id: id) + return { success: false, errors: ["Notification not found"] } unless notification + + if notification.destroy + { success: true, errors: [] } + else + { success: false, errors: notification.errors.full_messages } + end + end + end + end + end \ No newline at end of file diff --git a/app/graphql/mutations/notifications/mark_notification_as_read.rb b/app/graphql/mutations/notifications/mark_notification_as_read.rb new file mode 100644 index 0000000..1774539 --- /dev/null +++ b/app/graphql/mutations/notifications/mark_notification_as_read.rb @@ -0,0 +1,26 @@ +module Mutations + module Notifications + class MarkNotificationAsRead < BaseMutation + graphql_name 'MarkNotificationAsRead' + + # Input argument to indicate which notification to update. + argument :id, ID, required: true + + # The response includes the updated notification and any errors. + field :notification, Types::NotificationType, null: true + field :errors, [String], null: false + + def resolve(id:) + notification = Notification.find_by(id: id) + return { notification: nil, errors: ["Notification not found"] } unless notification + + notification.read = true + if notification.save + { notification: notification, errors: [] } + else + { notification: nil, errors: notification.errors.full_messages } + end + end + end + end + end \ No newline at end of file