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
|
||||
user
|
||||
|> cast(attrs, [
|
||||
:id,
|
||||
:email,
|
||||
:password,
|
||||
:privateKeyPem,
|
||||
:last_active_at,
|
||||
:actor_id
|
||||
:last_active_at
|
||||
])
|
||||
|> validate_required([
|
||||
:id,
|
||||
:email,
|
||||
:password,
|
||||
:privateKeyPem,
|
||||
:last_active_at,
|
||||
:actor_id
|
||||
:last_active_at
|
||||
])
|
||||
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_and_domain(username, domain) do
|
||||
from(u in User,
|
||||
where: u.username == ^username and u.domain == ^domain
|
||||
)
|
||||
|> Repo.one()
|
||||
def get_total_users_count() do
|
||||
Repo.aggregate(from(u in User), :count, :id)
|
||||
end
|
||||
|
||||
def get_total_users_count(domain) do
|
||||
Repo.aggregate(from(u in User, where: u.domain == ^domain), :count, :id)
|
||||
end
|
||||
|
||||
def get_active_users_count(domain, days) do
|
||||
def get_active_users_count(days) do
|
||||
cutoff = DateTime.add(DateTime.utc_now(), -days * 86400, :second)
|
||||
|
||||
from(u in User,
|
||||
where: u.domain == ^domain and u.last_active_at > ^cutoff
|
||||
)
|
||||
from(u in User, where: u.last_active_at > ^cutoff)
|
||||
|> Repo.aggregate(:count, :id)
|
||||
end
|
||||
|
||||
|
|
|
@ -13,11 +13,9 @@ defmodule NullaWeb.NodeinfoController do
|
|||
|
||||
def show(conn, _params) do
|
||||
version = Application.spec(:nulla, :vsn) |> to_string()
|
||||
instance_settings = InstanceSettings.get_instance_settings!()
|
||||
domain = instance_settings.domain
|
||||
total = User.get_total_users_count(domain)
|
||||
month = User.get_active_users_count(domain, 30)
|
||||
halfyear = User.get_active_users_count(domain, 180)
|
||||
total = User.get_total_users_count()
|
||||
month = User.get_active_users_count(30)
|
||||
halfyear = User.get_active_users_count(180)
|
||||
|
||||
users = %{
|
||||
total: total,
|
||||
|
|
|
@ -9,12 +9,7 @@ defmodule Nulla.Repo.Migrations.CreateUsers do
|
|||
add :privateKeyPem, :string
|
||||
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)
|
||||
end
|
||||
|
||||
create unique_index(:users, [:actor_id])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue