mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-12-26 13:21:42 +03:00
Add smoothie update action.
This commit is contained in:
parent
d2b794bfa5
commit
ec64c146d8
@ -128,7 +128,27 @@ data routeParams =
|
||||
|
||||
action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
|
||||
action routeParams =
|
||||
Request.skip "No action."
|
||||
Request.map2 Tuple.pair
|
||||
(Request.formParserResultNew form)
|
||||
Request.requestTime
|
||||
|> MySession.expectSessionDataOrRedirect (Session.get "userId" >> Maybe.map Uuid)
|
||||
(\userId ( parsed, requestTime ) session ->
|
||||
case parsed of
|
||||
Ok okParsed ->
|
||||
Smoothies.update (Uuid routeParams.smoothieId) okParsed
|
||||
|> Request.Hasura.mutationDataSource requestTime
|
||||
|> DataSource.map
|
||||
(\_ ->
|
||||
( session
|
||||
, Route.redirectTo Route.Index
|
||||
)
|
||||
)
|
||||
|
||||
Err errors ->
|
||||
DataSource.succeed
|
||||
-- TODO need to render errors here
|
||||
( session, Response.render {} )
|
||||
)
|
||||
|
||||
|
||||
head : StaticPayload Data ActionData RouteParams -> List Head.Tag
|
||||
|
@ -1,4 +1,4 @@
|
||||
module Data.Smoothies exposing (Smoothie, create, find, selection)
|
||||
module Data.Smoothies exposing (Smoothie, create, find, selection, update)
|
||||
|
||||
import Api.InputObject
|
||||
import Api.Mutation
|
||||
@ -61,3 +61,32 @@ create item =
|
||||
}
|
||||
SelectionSet.empty
|
||||
|> SelectionSet.nonNullOrFail
|
||||
|
||||
|
||||
update :
|
||||
Uuid
|
||||
-> { name : String, description : String, price : Int, imageUrl : String }
|
||||
-> SelectionSet () RootMutation
|
||||
update id item =
|
||||
Api.Mutation.update_products_by_pk
|
||||
(\_ ->
|
||||
{ inc_ = Absent
|
||||
, set_ =
|
||||
Api.InputObject.buildProducts_set_input
|
||||
(\opts ->
|
||||
{ opts
|
||||
| name = Present item.name
|
||||
, description = Present item.description
|
||||
, price = Present item.price
|
||||
, unsplash_image_id = Present item.imageUrl
|
||||
}
|
||||
)
|
||||
|> Present
|
||||
}
|
||||
)
|
||||
{ pk_columns =
|
||||
Api.InputObject.buildProducts_pk_columns_input
|
||||
{ id = id }
|
||||
}
|
||||
SelectionSet.empty
|
||||
|> SelectionSet.nonNullOrFail
|
||||
|
Loading…
Reference in New Issue
Block a user