Update user
This commit is contained in:
parent
9d72fb293b
commit
74514f02a1
3 changed files with 11 additions and 27 deletions
|
@ -24,18 +24,18 @@ defmodule Nulla.Models.User do
|
||||||
def changeset(user, attrs) do
|
def changeset(user, attrs) do
|
||||||
user
|
user
|
||||||
|> cast(attrs, [
|
|> cast(attrs, [
|
||||||
|
:id,
|
||||||
:email,
|
:email,
|
||||||
:password,
|
:password,
|
||||||
:privateKeyPem,
|
:privateKeyPem,
|
||||||
:last_active_at,
|
:last_active_at
|
||||||
:actor_id
|
|
||||||
])
|
])
|
||||||
|> validate_required([
|
|> validate_required([
|
||||||
|
:id,
|
||||||
:email,
|
:email,
|
||||||
:password,
|
:password,
|
||||||
:privateKeyPem,
|
:privateKeyPem,
|
||||||
:last_active_at,
|
:last_active_at
|
||||||
:actor_id
|
|
||||||
])
|
])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,23 +47,14 @@ defmodule Nulla.Models.User do
|
||||||
|
|
||||||
def get_user_by_username(username), do: Repo.get_by(User, username: username)
|
def get_user_by_username(username), do: Repo.get_by(User, username: username)
|
||||||
|
|
||||||
def get_user_by_username_and_domain(username, domain) do
|
def get_total_users_count() do
|
||||||
from(u in User,
|
Repo.aggregate(from(u in User), :count, :id)
|
||||||
where: u.username == ^username and u.domain == ^domain
|
|
||||||
)
|
|
||||||
|> Repo.one()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_total_users_count(domain) do
|
def get_active_users_count(days) do
|
||||||
Repo.aggregate(from(u in User, where: u.domain == ^domain), :count, :id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_active_users_count(domain, days) do
|
|
||||||
cutoff = DateTime.add(DateTime.utc_now(), -days * 86400, :second)
|
cutoff = DateTime.add(DateTime.utc_now(), -days * 86400, :second)
|
||||||
|
|
||||||
from(u in User,
|
from(u in User, where: u.last_active_at > ^cutoff)
|
||||||
where: u.domain == ^domain and u.last_active_at > ^cutoff
|
|
||||||
)
|
|
||||||
|> Repo.aggregate(:count, :id)
|
|> Repo.aggregate(:count, :id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,9 @@ defmodule NullaWeb.NodeinfoController do
|
||||||
|
|
||||||
def show(conn, _params) do
|
def show(conn, _params) do
|
||||||
version = Application.spec(:nulla, :vsn) |> to_string()
|
version = Application.spec(:nulla, :vsn) |> to_string()
|
||||||
instance_settings = InstanceSettings.get_instance_settings!()
|
total = User.get_total_users_count()
|
||||||
domain = instance_settings.domain
|
month = User.get_active_users_count(30)
|
||||||
total = User.get_total_users_count(domain)
|
halfyear = User.get_active_users_count(180)
|
||||||
month = User.get_active_users_count(domain, 30)
|
|
||||||
halfyear = User.get_active_users_count(domain, 180)
|
|
||||||
|
|
||||||
users = %{
|
users = %{
|
||||||
total: total,
|
total: total,
|
||||||
|
|
|
@ -9,12 +9,7 @@ defmodule Nulla.Repo.Migrations.CreateUsers do
|
||||||
add :privateKeyPem, :string
|
add :privateKeyPem, :string
|
||||||
add :last_active_at, :utc_datetime
|
add :last_active_at, :utc_datetime
|
||||||
|
|
||||||
add :actor_id, references(:actors, column: :id, type: :bigint, on_delete: :delete_all),
|
|
||||||
null: false
|
|
||||||
|
|
||||||
timestamps(type: :utc_datetime)
|
timestamps(type: :utc_datetime)
|
||||||
end
|
end
|
||||||
|
|
||||||
create unique_index(:users, [:actor_id])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue