Commit 3df0c882 authored by Miguel Basticioto's avatar Miguel Basticioto
Browse files

feat: adicionado notifications_context

parent e84a9bb7
defmodule NotificationDispatcher.Context.NotificationsContext do
@moduledoc """
The Notifications context.
"""
import Ecto.Query, warn: false
alias Api.Repo
alias NotificationDispatcher.Schema.NotificationMessage
def get_notification_message!(id), do: Repo.get!(NotificationMessage, id)
def get_one_notification_message!(channel) do
NotificationMessage.query_main()
|> NotificationMessage.where_channel(channel)
|> NotificationMessage.limit(1)
|> Repo.one()
end
def get_by_type_and_language(type, language) do
NotificationMessage.query_main()
|> NotificationMessage.where_type(type)
|> NotificationMessage.where_locale(language)
|> NotificationMessage.limit(1)
|> Repo.one()
end
def get_by_type(type) do
NotificationMessage.query_main()
|> NotificationMessage.where_type(type)
|> NotificationMessage.limit(1)
|> Repo.one()
end
def create_notification_message(attrs \\ %{}) do
%NotificationMessage{}
|> NotificationMessage.changeset(attrs)
|> Repo.insert()
end
def delete_notification_message(%NotificationMessage{} = notification_message) do
Repo.delete(notification_message)
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment