Mafinar Khan • theScore • @mafinar
Note to self: Switch to the Dashboard!
defmodule KarmaWerks.Engine.Task do
@moduledoc """
Service functions for task management
"""
import ShorterMaps
def create_task(~m/name, description, owner, assignees, group/) do
Dlex.mutate(:karma_werks, ~s[
_:t <name> "#{name}" .
_:t <type> "Task" .
_:t <description> "#{description}" .
_:t <owner> <#{owner}> .
_:t <group> <#{group}> .
#{Enum.map(assignees, fn assignee ->
~s[_:t <asignees> <#{assignee}> .]
end) |> Enum.join("\n")}
])
end
end
@spec get_user_by(String.t(), String.t()) :: {:ok, [map()]} | {:error, any}
def get_user_by(attribute, value) do
query = ~s/{
result (func: eq(#{attribute}, "#{value}")) {
uid
name
email
bio
type
}
}/ |> String.replace("\n", "")
case Dlex.query(:karma_werks, query) do
{:ok, %{"result" => result}} -> {:ok, result}
error -> error
end
end