            java.util.UUID)
   (:require [clojure.string :as str]
             [org.openforis.ceo.utils.type-conversion :as tc]
-            [org.openforis.ceo.database   :refer [call-sql sql-primitive]]
+            [org.openforis.ceo.database   :refer [call-sql
+                                                  call-sql-opts
+                                                  sql-primitive]]
             [org.openforis.ceo.utils.mail :refer [email?
                                                   send-mail
                                                   send-to-mailing-list


(defn login [{:keys [params]}]
  (let [{:keys [email password]} params]
    (if-let [user (first (call-sql "check_login" email password))]
      (data-response ""
                     {:session {:userId   (:user_id user)
                                :userName email


;; FIXME, remove this route and check if a user exists directly when adding
(defn get-all-users [_]
  (let [all-users (mapv (fn [{:keys [user_id email]}]
                          {:id    user_id
                           :email email})
                        (call-sql "get_all_users"))]
    (data-response all-users)))

;; FIXME: Update get_all_users_by_institution to remove unused values.
(defn get-institution-users [{:keys [params]}]
  (let [institution-id (tc/str->int (:institutionId params))
        all-users      (mapv (fn [{:keys [user_id email institution_role]}]
                               {:id              user_id
                                :email           email
                                :institutionRole institution_role})
                             (call-sql "get_all_users_by_institution_id" institution-id))]
    (data-response all-users)))
