Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query for subscriptions by email #673

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion server/lib/orcasite/notifications/resources/subscription.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ defmodule Orcasite.Notifications.Subscription do
actions do
defaults [:destroy, :read, create: :*]

read :by_email do
argument :email, :string
filter expr(meta[:email] == ^arg(:email))
end

read :available_for_notification do
description """
Subscriptions that can be sent a notification. Finds subscriptions that haven't been sent a
Expand Down Expand Up @@ -176,6 +181,10 @@ defmodule Orcasite.Notifications.Subscription do
change manage_relationship(:last_notification, type: :append)
change set_attribute(:last_notified_at, &DateTime.utc_now/0)
end

update :unsubscribe do
change set_attribute(:active, false)
end
end

def unsubscribe_token(subscription) do
Expand All @@ -186,7 +195,7 @@ defmodule Orcasite.Notifications.Subscription do

admin do
table_columns [:id, :name, :meta, :active, :event_type, :subscriber_id, :inserted_at]
read_actions [:read, :available_for_notification]
read_actions [:read, :available_for_notification, :by_email]
format_fields meta: {Jason, :encode!, []}
end
end
Loading