changing notification behaviour: multiple recipients, but only one mail

This commit is contained in:
nek0 2017-08-04 07:28:34 +02:00
parent 671eab1697
commit 722d794996
4 changed files with 14 additions and 13 deletions

View File

@ -50,7 +50,7 @@ postBuyR uId bId = do
update uId [UserBalance -=. price]
update bId [BeverageAmount -=. quant]
update bId [BeverageTotalBought +=. 1]
checkAlert bId
checkAlert bId (beverageAmount bev)
master <- getYesod
liftIO $ notifyUser user bev quant price master
case sw of
@ -128,7 +128,7 @@ postBuyCashR bId =
let price = quant * (beveragePrice bev + appCashCharge (appSettings master))
runDB $ update bId [BeverageAmount -=. quant]
updateCashier price "Barzahlung"
checkAlert bId
checkAlert bId (beverageAmount bev)
let currency = appCurrency $ appSettings master
setMessageI $ MsgPurchaseSuccessCash price currency
redirect HomeR

View File

@ -183,13 +183,14 @@ amountField = Field
showVal = either id (pack . showI)
showI x = show (fromIntegral x :: Integer)
checkAlert :: BeverageId -> Handler ()
checkAlert bId = do
checkAlert :: BeverageId -> Int -> Handler ()
checkAlert bId oldamount = do
bev <- runDB $ getJust bId
if beverageAmount bev < beverageAlertAmount bev
then do
master <- getYesod
let to = appEmail $ appSettings master
let alert = beverageAlertAmount bev
when (beverageAmount bev < alert && oldamount > alert) $ do
master <- getYesod
let tos = appEmail $ appSettings master
mapM_ (\to ->
liftIO $ sendMail to "Niedriger Bestand"
[stext|
Hallo,
@ -199,10 +200,9 @@ Der momentane Bestand ist bei #{beverageAmount bev} Artikeln.
Viele Grüße,
der Matemat
Dein Matemat
|]
else
return () -- do nothing
) tos
sendMail :: MonadIO m => Text -> Text -> TL.Text -> m ()
sendMail to subject body =

View File

@ -67,7 +67,7 @@ data AppSettings = AppSettings
-- ^ Copyright text to appear in the footer of the page
, appAnalytics :: Maybe Text
-- ^ Google Analytics code
, appEmail :: Text
, appEmail :: [Text]
-- ^ notification address
, appCurrency :: Text
-- ^ Currency character

View File

@ -26,7 +26,8 @@ database:
poolsize: "_env:PGPOOLSIZE:10"
#analytics: UA-YOURCODE
email: "nek0@momen"
email:
- "nek0@momen"
currency: "€"
cash_charge: 50