View Source Glific.Tags (Glific v5.1.6)

The Tags Context, which encapsulates and manages tags and the related join tables.

Link to this section Summary

Functions

Returns an %Ecto.Changeset{} for tracking contact changes.

Returns an %Ecto.Changeset{} for tracking message changes.

Returns an %Ecto.Changeset{} for tracking tag changes.

Return the count of tags, using the same filter as list_tags

Creates a contact.

Creates a message tag

Creates a tag.

Creates a template tag.

Deletes a list of contact tags, each tag attached to the same contact

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids. We will generalize this function and move it to Repo.ex when we get a better handle on how to do so :)

Deletes a tag.

Deletes a list of template tags, each tag attached to the same template

Given a shortcode of tag, retrieve all the children for the tag

Gets a single contact.

Gets a single message.

Gets a single tag.

Given a tag id or a list of tag ids, retrieve all the ancestors for the list_tags

Converts all tag kewords into the map where keyword is the key and tag id is the value

Returns the list of tags.

Filter all the status tag and returns as a map

Updates a tag.

Link to this section Functions

Link to this function

change_contact_tag(contact_tag, attrs \\ %{})

View Source
@spec change_contact_tag(Glific.Tags.ContactTag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking contact changes.

examples

Examples

iex> change_contact_tag(contact_tag)
%Ecto.Changeset{data: %ContactTag{}}
Link to this function

change_message_tag(message_tag, attrs \\ %{})

View Source
@spec change_message_tag(Glific.Tags.MessageTag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking message changes.

examples

Examples

iex> change_message_tag(message_tag)
%Ecto.Changeset{data: %MessageTag{}}
Link to this function

change_tag(tag, attrs \\ %{})

View Source
@spec change_tag(Glific.Tags.Tag.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking tag changes.

examples

Examples

iex> change_tag(tag)
%Ecto.Changeset{data: %Tag{}}
@spec count_tags(map()) :: integer()

Return the count of tags, using the same filter as list_tags

Link to this function

create_contact_tag(attrs)

View Source
@spec create_contact_tag(map()) ::
  {:ok, Glific.Tags.ContactTag.t()} | {:error, Ecto.Changeset.t()}

Creates a contact.

examples

Examples

iex> create_contact_tag(%{field: value})
{:ok, %Contact{}}

iex> create_contact_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_message_tag(attrs)

View Source
@spec create_message_tag(map()) ::
  {:ok, Glific.Tags.MessageTag.t()} | {:error, Ecto.Changeset.t()}

Creates a message tag

examples

Examples

iex> create_message_tag(%{field: value}) {:ok, %Message{}}

iex> create_message_tag(%{field: bad_value}) {:error, %Ecto.Changeset{}}

@spec create_tag(map()) :: {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Creates a tag.

examples

Examples

iex> create_tag(%{field: value})
{:ok, %Tag{}}

iex> create_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_template_tag(attrs \\ %{})

View Source
@spec create_template_tag(map()) ::
  {:ok, Glific.Tags.TemplateTag.t()} | {:error, Ecto.Changeset.t()}

Creates a template tag.

examples

Examples

iex> create_template_tag(%{field: value})
{:ok, %Contact{}}

iex> create_template_tag(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

delete_contact_tag_by_ids(contact_id, tag_ids)

View Source
@spec delete_contact_tag_by_ids(integer(), []) :: {integer(), nil | [term()]}

Deletes a list of contact tags, each tag attached to the same contact

Link to this function

delete_message_tag_by_ids(message_id, tag_ids, organization_id)

View Source
@spec delete_message_tag_by_ids(integer(), [], non_neg_integer()) ::
  {integer(), nil | [term()]}

In Join tables we rarely use the table id. We always know the object ids and hence more convenient to delete an entry via its object ids. We will generalize this function and move it to Repo.ex when we get a better handle on how to do so :)

@spec delete_tag(Glific.Tags.Tag.t()) ::
  {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Deletes a tag.

examples

Examples

iex> delete_tag(tag)
{:ok, %Tag{}}

iex> delete_tag(tag)
{:error, %Ecto.Changeset{}}
Link to this function

delete_template_tag_by_ids(template_id, tag_ids)

View Source
@spec delete_template_tag_by_ids(integer(), []) :: {integer(), nil | [term()]}

Deletes a list of template tags, each tag attached to the same template

Link to this function

get_all_children(shortcode, organization_id)

View Source
@spec get_all_children(String.t(), non_neg_integer()) :: [Glific.Tags.Tag.t()]

Given a shortcode of tag, retrieve all the children for the tag

@spec get_contact_tag!(integer()) :: Glific.Tags.ContactTag.t()

Gets a single contact.

Raises Ecto.NoResultsError if the Contact does not exist.

examples

Examples

iex> get_contact_tag!(123)
%Contact{}

iex> get_contact_tag!(456)
** (Ecto.NoResultsError)
@spec get_message_tag!(integer()) :: Glific.Tags.MessageTag.t()

Gets a single message.

Raises Ecto.NoResultsError if the Message does not exist.

examples

Examples

iex> get_message_tag!(123)
%Message{}

iex> get_message_tag!(456)
** (Ecto.NoResultsError)
@spec get_tag!(integer()) :: Glific.Tags.Tag.t()

Gets a single tag.

Raises Ecto.NoResultsError if the Tag does not exist.

examples

Examples

iex> get_tag!(123)
%Tag{}

iex> get_tag!(456)
** (Ecto.NoResultsError)
Link to this function

include_all_ancestors(tag_id)

View Source
@spec include_all_ancestors(non_neg_integer() | [non_neg_integer()]) :: [
  non_neg_integer()
]

Given a tag id or a list of tag ids, retrieve all the ancestors for the list_tags

@spec keyword_map(map()) :: map()

Converts all tag kewords into the map where keyword is the key and tag id is the value

@spec list_tags(map()) :: [Glific.Tags.Tag.t()]

Returns the list of tags.

examples

Examples

iex> list_tags()
[%Tag{}, ...]
Link to this function

remove_tag_from_all_message(contact_id, tag_shortcode, organization_id, publish \\ true)

View Source
@spec remove_tag_from_all_message(integer(), String.t(), non_neg_integer(), boolean()) ::
  list()
@spec remove_tag_from_all_message(
  integer(),
  [String.t()],
  non_neg_integer(),
  boolean()
) :: list()

Remove a specific tag from contact messages

@spec status_map(map()) :: %{required(String.t()) => integer()}

Filter all the status tag and returns as a map

Link to this function

update_contact_tag(contact_tag, attrs)

View Source
@spec update_contact_tag(Glific.Tags.ContactTag.t(), map()) ::
  {:ok, Glific.Tags.ContactTag.t()} | {:error, Ecto.Changeset.t()}

Updates a contact tag.

examples

Examples

iex> update_contact_tag(contact_tag, %{field: new_value})
{:ok, %ContactTag{}}

iex> update_contact_tag(contact_tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

update_message_tag(message_tag, attrs)

View Source
@spec update_message_tag(Glific.Tags.MessageTag.t(), map()) ::
  {:ok, Glific.Tags.MessageTag.t()} | {:error, Ecto.Changeset.t()}

Updates a message tag.

examples

Examples

iex> update_message_tag(message_tag, %{field: new_value})
{:ok, %MessageTag{}}

iex> update_message_tag(message_tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec update_tag(Glific.Tags.Tag.t(), map()) ::
  {:ok, Glific.Tags.Tag.t()} | {:error, Ecto.Changeset.t()}

Updates a tag.

examples

Examples

iex> update_tag(tag, %{field: new_value})
{:ok, %Tag{}}

iex> update_tag(tag, %{field: bad_value})
{:error, %Ecto.Changeset{}}