View Source Lightning.Auditing.Audit behaviour (Lightning v2.10.4)

Macro module to add common model behaviour to a given Ecto model

Summary

Callbacks

Callback to update changes before saving to the database.

Functions

Creates a changeset for the event identified by item_id and caused by actor.

Saves the event to the Repo.

Callbacks

@callback update_changes(changes :: map()) :: map()

Callback to update changes before saving to the database.

Functions

Link to this function

event(item_type, event, item_id, actor, changes \\ %{}, metadata \\ %{}, update_fun \\ fn x -> x end)

View Source

Creates a changeset for the event identified by item_id and caused by actor.

The given changes can be either nil, Ecto.Changeset, struct or map.

It returns :no_changes in case of an Ecto.Changeset changes that changed nothing or an Ecto.Changeset with the event ready to be inserted.

@spec save(Ecto.Changeset.t() | :no_changes, Ecto.Repo.t()) ::
  {:ok, :no_changes} | {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Saves the event to the Repo.

In case of nothing changes, do nothing.

It returns {:ok, :no_changes} if nothing changed, {:ok, struct} if the log has been successfully saved or {:error, changeset} in case of error.