Voile.Schema.System (Voile v0.1.23)

Copy Markdown View Source

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 node.

Updates node loan rules specifically.

Updates a setting.

Updates a system_log.

Updates a visitor_log (e.g., for check-out).

Creates or updates a setting by name.

Verifies an API token and returns the associated user. Updates last_used_at timestamp.

Functions

change_collection_log(collection_log, attrs \\ %{})

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

Examples

iex> change_collection_log(collection_log)
%Ecto.Changeset{data: %CollectionLog{}}

change_node(node, attrs \\ %{})

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

Examples

iex> change_node(node)
%Ecto.Changeset{data: %Node{}}

change_setting(setting, attrs \\ %{})

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

Examples

iex> change_setting(setting)
%Ecto.Changeset{data: %Setting{}}

change_system_log(system_log, attrs \\ %{})

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

Examples

iex> change_system_log(system_log)
%Ecto.Changeset{data: %SystemLog{}}

change_visitor_log(visitor_log, attrs \\ %{})

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

change_visitor_survey(visitor_survey, attrs \\ %{})

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

cleanup_expired_tokens()

Cleans up expired tokens (run periodically via cron/quantum)

create_api_token(user, attrs \\ %{})

Creates a new API token for a user. Returns {:ok, token, plain_token} where plain_token should be shown to user once.

create_collection_log(attrs \\ %{})

Creates a collection_log.

Examples

iex> create_collection_log(%{field: value})
{:ok, %CollectionLog{}}

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

create_master_api_token(user, attrs \\ %{})

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.

create_node(attrs \\ %{})

Creates a node.

Examples

iex> create_node(%{field: value})
{:ok, %Node{}}

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

create_setting(attrs \\ %{})

Creates a setting.

Examples

iex> create_setting(%{field: value})
{:ok, %Setting{}}

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

create_system_log(attrs \\ %{})

Creates a system_log.

Examples

iex> create_system_log(%{field: value})
{:ok, %SystemLog{}}

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

create_visitor_log(attrs \\ %{})

Creates a visitor_log (check-in).

create_visitor_survey(attrs \\ %{})

Creates a visitor_survey.

delete_api_token(token)

Deletes an API token

delete_collection_log(collection_log)

Deletes a collection_log.

Examples

iex> delete_collection_log(collection_log)
{:ok, %CollectionLog{}}

iex> delete_collection_log(collection_log)
{:error, %Ecto.Changeset{}}

delete_node(node)

Deletes a node.

Examples

iex> delete_node(node)
{:ok, %Node{}}

iex> delete_node(node)
{:error, %Ecto.Changeset{}}

delete_setting(setting)

Deletes a setting.

Examples

iex> delete_setting(setting)
{:ok, %Setting{}}

iex> delete_setting(setting)
{:error, %Ecto.Changeset{}}

delete_system_log(system_log)

Deletes a system_log.

Examples

iex> delete_system_log(system_log)
{:ok, %SystemLog{}}

iex> delete_system_log(system_log)
{:error, %Ecto.Changeset{}}

delete_visitor_log(visitor_log)

Deletes a visitor_log.

delete_visitor_survey(visitor_survey)

Deletes a visitor_survey.

get_api_token(id)

Gets a single API token

get_collection_log!(id)

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)

get_default_node()

get_node!(id)

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)

get_node_basic(node_id)

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}

get_setting!(id)

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)

get_setting_by_name(name)

Gets a setting by its name.

Examples

iex> get_setting_by_name("reservation_notifications_enabled")
%Setting{}

iex> get_setting_by_name("nonexistent")
nil

get_setting_value(name, default \\ nil)

Gets a setting value by name, returns default if not found.

Examples

iex> get_setting_value("reservation_notifications_enabled", "false")
"true"

get_system_log!(id)

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)

get_visitor_log!(id, opts \\ [])

Gets a single visitor_log.

get_visitor_statistics(opts \\ [])

Returns visitor statistics for a given period and optional filters.

get_visitor_statistics_by_node_year(year, opts \\ [])

Returns visitor totals grouped by node for a given year.

get_visitor_survey!(id, opts \\ [])

Gets a single visitor_survey.

list_all_api_tokens()

Lists all API tokens (admin only)

list_collection_logs()

Returns the list of collection_logs.

Examples

iex> list_collection_logs()
[%CollectionLog{}, ...]

list_nodes()

Returns the list of nodes.

Examples

iex> list_nodes()
[%Node{}, ...]

list_settings()

Returns the list of settings.

Examples

iex> list_settings()
[%Setting{}, ...]

list_system_logs()

Returns the list of system_logs.

Examples

iex> list_system_logs()
[%SystemLog{}, ...]

list_user_api_tokens(user)

Lists all API tokens for a user

list_visitor_logs(opts \\ [])

Returns the list of visitor_logs with filtering and pagination.

list_visitor_logs_paginated(page \\ 1, per_page \\ 50, opts \\ [])

Returns the list of visitor_logs with filtering and pagination. Returns {[logs], total_pages, total_count}

list_visitor_surveys(opts \\ [])

Returns the list of visitor_surveys with filtering.

list_visitor_surveys_paginated(page \\ 1, per_page \\ 50, opts \\ [])

Returns the list of visitor_surveys with filtering and pagination. Returns {[surveys], total_pages, total_count}

revoke_api_token(token)

Revokes an API token

rotate_api_token(old_token)

Rotates an API token (revokes old, creates new with same settings)

update_api_token(token, attrs)

Updates an API token

update_collection_log(collection_log, attrs)

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{}}

update_node(node, attrs)

Updates a node.

Examples

iex> update_node(node, %{field: new_value})
{:ok, %Node{}}

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

update_node_rules(node, attrs)

Updates node loan rules specifically.

update_setting(setting, attrs)

Updates a setting.

Examples

iex> update_setting(setting, %{field: new_value})
{:ok, %Setting{}}

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

update_system_log(system_log, attrs)

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{}}

update_visitor_log(visitor_log, attrs)

Updates a visitor_log (e.g., for check-out).

update_visitor_survey(visitor_survey, attrs)

Updates a visitor_survey.

upsert_setting(name, value)

Creates or updates a setting by name.

Examples

iex> upsert_setting("reservation_notifications_enabled", "true")
{:ok, %Setting{}}

verify_api_token(plain_token, opts \\ [])

Verifies an API token and returns the associated user. Updates last_used_at timestamp.