View Source Zoonk.Organizations (Zoonk v0.3.0-alpha)

Organizations context.

Link to this section Summary

Functions

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

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()}
Link to this type

school_user_changeset()

View Source
@type school_user_changeset() ::
  {:ok, Zoonk.Organizations.SchoolUser.t()} | {:error, Ecto.Changeset.t()}

Link to this section Functions

Link to this function

approve_school_user(school_user_id, approved_by_id)

View Source
@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{}}
Link to this function

change_school(school, attrs \\ %{})

View Source
@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{}}
Link to this function

create_school(user, attrs \\ %{})

View Source
@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{}}
Link to this function

create_school_user(school, user, attrs \\ %{}, opts \\ [])

View Source

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{}}
Link to this function

delete_school_user(school_user_id)

View Source
@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{}}
Link to this function

get_courses_count(school)

View Source
@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
Link to this function

get_parent_school(school)

View Source
@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)
Link to this function

get_school_by_host!(host)

View Source
@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
Link to this function

get_school_by_username!(username)

View Source
@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)
Link to this function

get_school_user(school_username, user_username, opts \\ [])

View Source
@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
Link to this function

get_school_users_count(school, role)

View Source
@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
Link to this function

get_schools_count(school)

View Source
@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
Link to this function

has_child_schools?(school)

View Source
@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
Link to this function

list_public_schools(opts \\ [])

View Source
@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{}, ...]
Link to this function

list_school_users(school)

View Source
@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{}, ...]
Link to this function

list_school_users_by_role(school, role)

View Source
@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{}, ...]
Link to this function

list_schools_by_user(user, opts \\ [])

View Source
@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{}, ...]
Link to this function

update_school(school, attrs)

View Source
@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{}}