View Source Zoonk.Organizations (Zoonk v0.3.0-alpha)
Organizations context.
Link to this section Summary
Functions
Approves a school user.
Returns an %Ecto.Changeset{}
for tracking school changes.
Creates a school.
Adds a user to a school.
Deletes a school.
Deletes a school user.
Gets the number of courses a school has.
Gets the parent school of a school.
Gets a single school.
Gets a single school based on the host
value.
Gets a single school based on their username.
Get a user from a school given their usernames.
Gets the number of users in a school based on their role.
Gets the number of schools a parent school has.
Returns true
if a school has any child schools.
Returns a list of public schools.
List all users for a school.
List all users for a school according to their role.
List all schools a user belongs to.
Updates a school.
Link to this section Types
@type school_changeset() :: {:ok, Zoonk.Organizations.School.t()} | {:error, Ecto.Changeset.t()} | {:error, String.t()}
@type school_user_changeset() :: {:ok, Zoonk.Organizations.SchoolUser.t()} | {:error, Ecto.Changeset.t()}
Link to this section Functions
@spec approve_school_user(integer(), integer()) :: school_user_changeset()
Approves a school user.
examples
Examples
iex> approve_school_user(school_user_id)
{:ok, %SchoolUser{}}
iex> approve_school_user(school_user_id)
{:error, %Ecto.Changeset{}}
@spec change_school(Zoonk.Organizations.School.t(), map()) :: Ecto.Changeset.t()
Returns an %Ecto.Changeset{}
for tracking school changes.
examples
Examples
iex> change_school(school)
%Ecto.Changeset{data: %School{}}
@spec create_school(Zoonk.Accounts.User.t(), map()) :: school_changeset()
Creates a school.
examples
Examples
iex> create_school(user, %{field: value})
{:ok, %School{}}
iex> create_school(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
@spec create_school_user( Zoonk.Organizations.School.t(), Zoonk.Accounts.User.t(), map(), list() ) :: school_user_changeset()
Adds a user to a school.
examples
Examples
iex> create_school_user(school, user, %{role: :student})
{:ok, %SchoolUser{}}
iex> create_school_user(school, user, %{role: :invalid})
{:error, %Ecto.Changeset{}}
@spec delete_school(Zoonk.Organizations.School.t()) :: school_changeset()
Deletes a school.
examples
Examples
iex> delete_school(school, school_user)
{:ok, %School{}}
iex> delete_school(school, school_user)
{:error, %Ecto.Changeset{}}
@spec delete_school_user(integer()) :: school_user_changeset()
Deletes a school user.
examples
Examples
iex> delete_school_user(school_user_id)
{:ok, %SchoolUser{}}
iex> delete_school_user(school_user_id)
{:error, %Ecto.Changeset{}}
@spec get_courses_count(Zoonk.Organizations.School.t()) :: non_neg_integer()
Gets the number of courses a school has.
It includes courses from child schools.
examples
Examples
iex> get_courses_count(school)
10
@spec get_parent_school(Zoonk.Organizations.School.t()) :: Zoonk.Organizations.School.t() | nil
Gets the parent school of a school.
examples
Examples
iex> get_parent_school(school)
%School{}
@spec get_school!(non_neg_integer()) :: Zoonk.Organizations.School.t()
Gets a single school.
Raises Ecto.NoResultsError
if the School does not exist.
examples
Examples
iex> get_school!(123)
%School{}
iex> get_school!(456)
** (Ecto.NoResultsError)
@spec get_school_by_host!(String.t()) :: Zoonk.Organizations.School.t() | nil
Gets a single school based on the host
value.
examples
Examples
iex> get_school_by_host!("unisc.zoonk.org")
%School{}
iex> get_school_by_host!("interactive.rug.nl")
%School{}
iex> get_school_by_host!("nonexisting.com")
nil
@spec get_school_by_username!(String.t()) :: Zoonk.Organizations.School.t()
Gets a single school based on their username.
examples
Examples
iex> get_school_by_username!("unisc")
%School{}
iex> get_school_by_username!("nonexisting")
** (Ecto.NoResultsError)
@spec get_school_user(String.t(), String.t(), list()) :: Zoonk.Organizations.SchoolUser.t() | nil
Get a user from a school given their usernames.
examples
Examples
iex> get_school_user("zoonk", "will")
%SchoolUser{}
iex> get_school_user("zoonk", "invalid")
nil
@spec get_school_users_count(Zoonk.Organizations.School.t(), atom()) :: non_neg_integer()
Gets the number of users in a school based on their role.
examples
Examples
iex> get_school_users_count(school, :manager)
10
@spec get_schools_count(Zoonk.Organizations.School.t()) :: non_neg_integer()
Gets the number of schools a parent school has.
examples
Examples
iex> get_schools_count(school)
10
@spec has_child_schools?(Zoonk.Organizations.School.t() | nil) :: boolean()
Returns true
if a school has any child schools.
examples
Examples
iex> has_child_schools?(school)
true
@spec list_public_schools(list()) :: [Zoonk.Organizations.SchoolData.t()]
Returns a list of public schools.
If you want to list schools specific to a user, you should use list_schools_by_user/1
instead.
examples
Examples
iex> list_public_schools()
[%SchoolData{}, ...]
@spec list_school_users(Zoonk.Organizations.School.t()) :: [Zoonk.Accounts.User.t()]
List all users for a school.
examples
Examples
iex> list_school_users(school)
[%User{}, ...]
@spec list_school_users_by_role(Zoonk.Organizations.School.t(), atom()) :: [ Zoonk.Organizations.SchoolUser.t() ]
List all users for a school according to their role.
examples
Examples
iex> list_school_users_by_role(school, :manager)
[%SchoolUser{}, ...]
@spec list_schools_by_user(Zoonk.Accounts.User.t(), list()) :: [ Zoonk.Organizations.SchoolUser.t() ]
List all schools a user belongs to.
examples
Examples
iex> list_schools_by_user(%User{})
[%SchoolUser{}, ...]
@spec update_school(Zoonk.Organizations.School.t(), map()) :: school_changeset()
Updates a school.
examples
Examples
iex> update_school(school, %{field: new_value})
{:ok, %School{}}
iex> update_school(school, %{field: bad_value})
{:error, %Ecto.Changeset{}}