mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 11:05:46 +03:00
Add a login helper function.
This commit is contained in:
parent
2328cf3dee
commit
944b78bce4
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user