Add a login helper function.

This commit is contained in:
Dillon Kearns 2022-07-27 18:10:23 +02:00
parent 2328cf3dee
commit 944b78bce4

View File

@ -1,4 +1,4 @@
module Data.User exposing (User, selection, updateUser)
module Data.User exposing (User, login, selection, updateUser)
import Api.InputObject
import Api.Mutation
@ -26,6 +26,36 @@ selection userId =
|> SelectionSet.nonNullOrFail
type alias LoginInfo =
{ userId : String }
login : { username : String, expectedPasswordHash : String } -> SelectionSet (Maybe Uuid) RootQuery
login { username, expectedPasswordHash } =
Api.Query.users
(\opts ->
{ opts
| where_ =
Present
(Api.InputObject.buildUsers_bool_exp
(\opt2 ->
{ opt2
| username = Present (eq username)
, password_hash = Present (eq expectedPasswordHash)
}
)
)
}
)
Api.Object.Users.id
|> SelectionSet.map List.head
eq : String -> Api.InputObject.String_comparison_exp
eq str =
Api.InputObject.buildString_comparison_exp (\opt -> { opt | eq_ = Present str })
updateUser : { userId : Uuid, name : String } -> SelectionSet () Graphql.Operation.RootMutation
updateUser { userId, name } =
Api.Mutation.update_users_by_pk