Add smoothie update action.

This commit is contained in:
Dillon Kearns 2022-06-13 12:55:03 -07:00
parent d2b794bfa5
commit ec64c146d8
2 changed files with 51 additions and 2 deletions

View File

@ -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

View File

@ -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