The System context.
Summary
Functions
Returns an %Ecto.Changeset{} for tracking collection_log changes.
Returns an %Ecto.Changeset{} for tracking node changes.
Returns an %Ecto.Changeset{} for tracking setting changes.
Returns an %Ecto.Changeset{} for tracking system_log changes.
Returns an %Ecto.Changeset{} for tracking visitor_log changes.
Returns an %Ecto.Changeset{} for tracking visitor_survey changes.
Cleans up expired tokens (run periodically via cron/quantum)
Creates a new API token for a user. Returns {:ok, token, plain_token} where plain_token should be shown to user once.
Creates a collection_log.
Creates a master API token for a user (non-expiring with admin privileges). Returns {:ok, token, plain_token} where plain_token should be shown to user once. Only users with super_admin role can create master tokens.
Creates a node.
Creates a setting.
Creates a system_log.
Creates a visitor_log (check-in).
Creates a visitor_survey.
Deletes an API token
Deletes a collection_log.
Deletes a node.
Deletes a setting.
Deletes a system_log.
Deletes a visitor_log.
Deletes a visitor_survey.
Gets a single API token
Gets a single collection_log.
Gets a single node.
Fetches minimal node identity for cross-app token encoding.
Gets a single setting.
Gets a setting by its name.
Gets a setting value by name, returns default if not found.
Gets a single system_log.
Gets a single visitor_log.
Returns visitor statistics for a given period and optional filters.
Returns visitor totals grouped by node for a given year.
Gets a single visitor_survey.
Lists all API tokens (admin only)
Returns the list of collection_logs.
Returns the list of nodes.
Returns the list of settings.
Returns the list of system_logs.
Lists all API tokens for a user
Returns the list of visitor_logs with filtering and pagination.
Returns the list of visitor_logs with filtering and pagination. Returns {[logs], total_pages, total_count}
Returns the list of visitor_surveys with filtering.
Returns the list of visitor_surveys with filtering and pagination. Returns {[surveys], total_pages, total_count}
Revokes an API token
Rotates an API token (revokes old, creates new with same settings)
Updates an API token
Updates a collection_log.
Updates a node.
Updates node loan rules specifically.
Updates a setting.
Updates a system_log.
Updates a visitor_log (e.g., for check-out).
Updates a visitor_survey.
Creates or updates a setting by name.
Verifies an API token and returns the associated user. Updates last_used_at timestamp.
Functions
Returns an %Ecto.Changeset{} for tracking collection_log changes.
Examples
iex> change_collection_log(collection_log)
%Ecto.Changeset{data: %CollectionLog{}}
Returns an %Ecto.Changeset{} for tracking node changes.
Examples
iex> change_node(node)
%Ecto.Changeset{data: %Node{}}
Returns an %Ecto.Changeset{} for tracking setting changes.
Examples
iex> change_setting(setting)
%Ecto.Changeset{data: %Setting{}}
Returns an %Ecto.Changeset{} for tracking system_log changes.
Examples
iex> change_system_log(system_log)
%Ecto.Changeset{data: %SystemLog{}}
Returns an %Ecto.Changeset{} for tracking visitor_log changes.
Returns an %Ecto.Changeset{} for tracking visitor_survey changes.
Cleans up expired tokens (run periodically via cron/quantum)
Creates a new API token for a user. Returns {:ok, token, plain_token} where plain_token should be shown to user once.
Creates a collection_log.
Examples
iex> create_collection_log(%{field: value})
{:ok, %CollectionLog{}}
iex> create_collection_log(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Creates a master API token for a user (non-expiring with admin privileges). Returns {:ok, token, plain_token} where plain_token should be shown to user once. Only users with super_admin role can create master tokens.
Creates a node.
Examples
iex> create_node(%{field: value})
{:ok, %Node{}}
iex> create_node(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Creates a setting.
Examples
iex> create_setting(%{field: value})
{:ok, %Setting{}}
iex> create_setting(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Creates a system_log.
Examples
iex> create_system_log(%{field: value})
{:ok, %SystemLog{}}
iex> create_system_log(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Creates a visitor_log (check-in).
Creates a visitor_survey.
Deletes an API token
Deletes a collection_log.
Examples
iex> delete_collection_log(collection_log)
{:ok, %CollectionLog{}}
iex> delete_collection_log(collection_log)
{:error, %Ecto.Changeset{}}
Deletes a node.
Examples
iex> delete_node(node)
{:ok, %Node{}}
iex> delete_node(node)
{:error, %Ecto.Changeset{}}
Deletes a setting.
Examples
iex> delete_setting(setting)
{:ok, %Setting{}}
iex> delete_setting(setting)
{:error, %Ecto.Changeset{}}
Deletes a system_log.
Examples
iex> delete_system_log(system_log)
{:ok, %SystemLog{}}
iex> delete_system_log(system_log)
{:error, %Ecto.Changeset{}}
Deletes a visitor_log.
Deletes a visitor_survey.
Gets a single API token
Gets a single collection_log.
Raises Ecto.NoResultsError if the Collection log does not exist.
Examples
iex> get_collection_log!(123)
%CollectionLog{}
iex> get_collection_log!(456)
** (Ecto.NoResultsError)
Gets a single node.
Raises Ecto.NoResultsError if the Node does not exist.
Examples
iex> get_node!(123)
%Node{}
iex> get_node!(456)
** (Ecto.NoResultsError)
Fetches minimal node identity for cross-app token encoding.
Returns only display fields — no collections, no users, no heavy associations. Used by Curatorian when building cross-app tokens so Atrium can display the organization name without a separate Voile database call.
Returns
{:ok, %{
id: integer(),
name: String.t(), # display name, e.g. "SD Negeri 1 Bandung"
abbr: String.t() # abbreviation, e.g. "SDN1BDG"
}}
{:error, :not_found}Examples
iex> get_node_basic(1)
{:ok, %{id: 1, name: "SD Negeri 1 Bandung", abbr: "SDN1BDG"}}
iex> get_node_basic(999)
{:error, :not_found}
Gets a single setting.
Raises Ecto.NoResultsError if the Setting does not exist.
Examples
iex> get_setting!(123)
%Setting{}
iex> get_setting!(456)
** (Ecto.NoResultsError)
Gets a setting by its name.
Examples
iex> get_setting_by_name("reservation_notifications_enabled")
%Setting{}
iex> get_setting_by_name("nonexistent")
nil
Gets a setting value by name, returns default if not found.
Examples
iex> get_setting_value("reservation_notifications_enabled", "false")
"true"
Gets a single system_log.
Raises Ecto.NoResultsError if the System log does not exist.
Examples
iex> get_system_log!(123)
%SystemLog{}
iex> get_system_log!(456)
** (Ecto.NoResultsError)
Gets a single visitor_log.
Returns visitor statistics for a given period and optional filters.
Returns visitor totals grouped by node for a given year.
Gets a single visitor_survey.
Lists all API tokens (admin only)
Returns the list of collection_logs.
Examples
iex> list_collection_logs()
[%CollectionLog{}, ...]
Returns the list of nodes.
Examples
iex> list_nodes()
[%Node{}, ...]
Returns the list of settings.
Examples
iex> list_settings()
[%Setting{}, ...]
Returns the list of system_logs.
Examples
iex> list_system_logs()
[%SystemLog{}, ...]
Lists all API tokens for a user
Returns the list of visitor_logs with filtering and pagination.
Returns the list of visitor_logs with filtering and pagination. Returns {[logs], total_pages, total_count}
Returns the list of visitor_surveys with filtering.
Returns the list of visitor_surveys with filtering and pagination. Returns {[surveys], total_pages, total_count}
Revokes an API token
Rotates an API token (revokes old, creates new with same settings)
Updates an API token
Updates a collection_log.
Examples
iex> update_collection_log(collection_log, %{field: new_value})
{:ok, %CollectionLog{}}
iex> update_collection_log(collection_log, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Updates a node.
Examples
iex> update_node(node, %{field: new_value})
{:ok, %Node{}}
iex> update_node(node, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Updates node loan rules specifically.
Updates a setting.
Examples
iex> update_setting(setting, %{field: new_value})
{:ok, %Setting{}}
iex> update_setting(setting, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Updates a system_log.
Examples
iex> update_system_log(system_log, %{field: new_value})
{:ok, %SystemLog{}}
iex> update_system_log(system_log, %{field: bad_value})
{:error, %Ecto.Changeset{}}
Updates a visitor_log (e.g., for check-out).
Updates a visitor_survey.
Creates or updates a setting by name.
Examples
iex> upsert_setting("reservation_notifications_enabled", "true")
{:ok, %Setting{}}
Verifies an API token and returns the associated user. Updates last_used_at timestamp.