From fe5cd6ad6c61eb13ca99acd1b69cd09b84051404 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 15 Mar 2017 14:47:31 +0100 Subject: Support types --- Handler/UpdateItem.hs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'Handler/UpdateItem.hs') diff --git a/Handler/UpdateItem.hs b/Handler/UpdateItem.hs index a4a29c2..befbe99 100644 --- a/Handler/UpdateItem.hs +++ b/Handler/UpdateItem.hs @@ -11,21 +11,24 @@ postUpdateItemR fsUpdateId = do ((updateResult, fsUpdateForm), fsUpdateEncoding) <- runFormPost . itemForm . Just $ entityVal entity - mapM_ (addMessage "formError" . toHtml) =<< case updateResult of - FormSuccess Item{..} -> [] <$ runDB (update fsUpdateId [ ItemKind =. itemKind - , ItemNormKind =. normalizeKind itemKind - , ItemBought =. itemBought - , ItemExpires =. itemExpires - , ItemOpened =. itemOpened - ]) - FormFailure errors -> return errors - _ -> return [] + case updateResult of + FormSuccess (Item{..} `WithType` t) -> runDB $ do + upsertBy (UniqueKind itemNormKind) (Kind itemNormKind t) [ KindType =. t ] + update fsUpdateId [ ItemKind =. itemKind + , ItemNormKind =. itemNormKind + , ItemBought =. itemBought + , ItemExpires =. itemExpires + , ItemOpened =. itemOpened + ] + return () + FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors + _ -> return () selectRep $ do provideRep $ case updateResult of FormSuccess _ -> redirect $ InventoryListingR :#: fsUpdateId :: Handler Html _ -> do - (sortOn entityVal -> stock) <- runDB $ selectList [] [] + (sortOn (entityVal . typedVal) -> stock) <- runDB $ mapM withType =<< selectList [] [] defaultLayout $ inventoryListing InventoryState { invFormState = Just UpdateForm{..} , .. -- cgit v1.2.3