defmodule NotificationDispatcher.Schema.NotificationMessage do use Ecto.Schema import Ecto.Changeset import Ecto.Query alias NotificationDispatcher.Schema.NotificationMessage @primary_key {:id, :binary_id, autogenerate: true} schema "notification_messages" do field :title, :string field :message, :string # 0 - Password Reset field :notification_type, :integer # 0 - Notification / 1 - Email field :channel, :integer field :locale, :string field :dispatch_offsets, :string timestamps() end @doc false def changeset(notification_message, attrs) do notification_message |> cast(attrs, [:title, :message, :notification_type, :channel, :locale, :dispatch_offsets]) |> validate_required([:title, :message, :notification_type, :channel, :locale, :dispatch_offsets]) end def query_main, do: from(notification in NotificationMessage, as: :notification) def where(query, id), do: from([notification: n] in query, where: n.id == ^id) def where_channel(query, channel), do: from([notification: n] in query, where: n.channel == ^channel) def where_type(query, type), do: from([notification: n] in query, where: n.notification_type == ^type) def where_locale(query, locale), do: from([notification: n] in query, where: n.locale == ^locale) def limit(query, limit), do: from([notification: n] in query, limit: ^limit) end