View Source Glific.Flows.ContactField (Glific v5.1.6)

Since many of the functions set/update fields in contact and related tables, lets centralize all the code here for now

Link to this section Summary

Functions

Add a field {key, value} to a contact. For now, all preferences are stored under the settings map, with a sub-map of preferences. We expect to get more clarity on this soon

Return the count of contacts_fields, using the same filter as list_contacts_fields

Create contact field

Deletes a contact field.

Add contact field taking contact as parameter. We should change the name of this function for the consistency

list contacts fields.

Create or update contact field

Update profile field if there is an active profile id set

parse contact fields values with check if it has

Reset the fields for a contact.

Link to this section Functions

Link to this function

add_contact_field(context, field, label, value, type)

View Source

Add a field {key, value} to a contact. For now, all preferences are stored under the settings map, with a sub-map of preferences. We expect to get more clarity on this soon

Link to this function

count_contacts_fields(args)

View Source
@spec count_contacts_fields(map()) :: integer()

Return the count of contacts_fields, using the same filter as list_contacts_fields

Link to this function

create_contact_field(attrs)

View Source
@spec create_contact_field(map()) ::
  {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}

Create contact field

Link to this function

delete_contacts_field(contacts_field)

View Source
@spec delete_contacts_field(Glific.Contacts.ContactsField.t()) ::
  {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}

Deletes a contact field.

examples

Examples

iex> delete_contacts_field(contacts_field)
{:ok, %ContactsField{}}

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

do_add_contact_field(contact, field, label, value, type \\ "string")

View Source
@spec do_add_contact_field(
  Glific.Contacts.Contact.t(),
  String.t(),
  String.t(),
  any(),
  String.t()
) ::
  Glific.Contacts.Contact.t()

Add contact field taking contact as parameter. We should change the name of this function for the consistency

Link to this function

list_contacts_fields(args)

View Source
@spec list_contacts_fields(map()) :: [Glific.Contacts.ContactsField.t()]

list contacts fields.

Link to this function

maybe_create_contact_field(attrs)

View Source
@spec maybe_create_contact_field(map()) ::
  {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}

Create or update contact field

Link to this function

maybe_update_profile_field(contact, fields)

View Source
@spec maybe_update_profile_field(Glific.Contacts.Contact.t(), map()) ::
  Glific.Contacts.Contact.t()

Update profile field if there is an active profile id set

Link to this function

parse_contact_field_value(context, value)

View Source
@spec parse_contact_field_value(Glific.Flows.FlowContext.t(), String.t()) ::
  String.t()

parse contact fields values with check if it has

Link to this function

reset_contact_fields(context)

View Source
@spec reset_contact_fields(Glific.Flows.FlowContext.t()) ::
  Glific.Flows.FlowContext.t()

Reset the fields for a contact.

Link to this function

update_contacts_field(contacts_field, attrs)

View Source
@spec update_contacts_field(Glific.Contacts.ContactsField.t(), map()) ::
  {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}

Updates a contact field.

examples

Examples

iex> update_contacts_field(contacts_field, %{field: new_value})
{:ok, %ContactsField{}}

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