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.
Updates a contact field.
Link to this section Functions
@spec add_contact_field( Glific.Flows.FlowContext.t(), String.t(), String.t(), String.t(), String.t() ) :: Glific.Flows.FlowContext.t()
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
@spec create_contact_field(map()) :: {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}
Create contact field
@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{}}
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
@spec list_contacts_fields(map()) :: [Glific.Contacts.ContactsField.t()]
list contacts fields.
@spec maybe_create_contact_field(map()) :: {:ok, Glific.Contacts.ContactsField.t()} | {:error, Ecto.Changeset.t()}
Create or update contact field
@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
@spec parse_contact_field_value(Glific.Flows.FlowContext.t(), String.t()) :: String.t()
parse contact fields values with check if it has
@spec reset_contact_fields(Glific.Flows.FlowContext.t()) :: Glific.Flows.FlowContext.t()
Reset the fields for a contact.
@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{}}