Add checking and updating DeepL usage information
This commit is contained in:
@ -16,12 +16,10 @@ defmodule Outlook.Translators do
|
||||
|
||||
def get_deepl_account!(id), do: Repo.get!(DeeplAccount, id)
|
||||
|
||||
def get_deepl_auth_key(user_id) do
|
||||
query =
|
||||
from DeeplAccount,
|
||||
where: [user_id: ^user_id],
|
||||
select: [:auth_key]
|
||||
Repo.one!(query)
|
||||
def get_deepl_auth_key(user) do
|
||||
deepl_account_for_user(user)
|
||||
|> select([:auth_key])
|
||||
|> Repo.one()
|
||||
|> Map.get(:auth_key)
|
||||
end
|
||||
|
||||
@ -45,6 +43,10 @@ defmodule Outlook.Translators do
|
||||
DeeplAccount.changeset(deepl_account, attrs)
|
||||
end
|
||||
|
||||
def increase_our_character_count(user, billed_characters) do
|
||||
deepl_account_for_user(user)
|
||||
|> Repo.update_all([inc: [our_character_count: billed_characters]])
|
||||
end
|
||||
|
||||
def translate(translation, current_user) do
|
||||
%{lang: target_lang,
|
||||
@ -64,6 +66,11 @@ defmodule Outlook.Translators do
|
||||
Task.start_link(Deepl, :translate, args)
|
||||
end
|
||||
|
||||
defp deepl_account_for_user(user) when is_struct(user), do: deepl_account_for_user(user.id)
|
||||
defp deepl_account_for_user(user_id) do
|
||||
DeeplAccount |> where(user_id: ^user_id)
|
||||
end
|
||||
|
||||
defp prepare_article(tree) do
|
||||
# Logger.info "so far."
|
||||
HtmlDocComponent.render_doc(%{tree: tree})
|
||||
|
||||
Reference in New Issue
Block a user