changing notification behaviour: multiple recipients, but only one mail
This commit is contained in:
parent
671eab1697
commit
722d794996
4 changed files with 14 additions and 13 deletions
|
@ -50,7 +50,7 @@ postBuyR uId bId = do
|
||||||
update uId [UserBalance -=. price]
|
update uId [UserBalance -=. price]
|
||||||
update bId [BeverageAmount -=. quant]
|
update bId [BeverageAmount -=. quant]
|
||||||
update bId [BeverageTotalBought +=. 1]
|
update bId [BeverageTotalBought +=. 1]
|
||||||
checkAlert bId
|
checkAlert bId (beverageAmount bev)
|
||||||
master <- getYesod
|
master <- getYesod
|
||||||
liftIO $ notifyUser user bev quant price master
|
liftIO $ notifyUser user bev quant price master
|
||||||
case sw of
|
case sw of
|
||||||
|
@ -128,7 +128,7 @@ postBuyCashR bId =
|
||||||
let price = quant * (beveragePrice bev + appCashCharge (appSettings master))
|
let price = quant * (beveragePrice bev + appCashCharge (appSettings master))
|
||||||
runDB $ update bId [BeverageAmount -=. quant]
|
runDB $ update bId [BeverageAmount -=. quant]
|
||||||
updateCashier price "Barzahlung"
|
updateCashier price "Barzahlung"
|
||||||
checkAlert bId
|
checkAlert bId (beverageAmount bev)
|
||||||
let currency = appCurrency $ appSettings master
|
let currency = appCurrency $ appSettings master
|
||||||
setMessageI $ MsgPurchaseSuccessCash price currency
|
setMessageI $ MsgPurchaseSuccessCash price currency
|
||||||
redirect HomeR
|
redirect HomeR
|
||||||
|
|
|
@ -183,13 +183,14 @@ amountField = Field
|
||||||
showVal = either id (pack . showI)
|
showVal = either id (pack . showI)
|
||||||
showI x = show (fromIntegral x :: Integer)
|
showI x = show (fromIntegral x :: Integer)
|
||||||
|
|
||||||
checkAlert :: BeverageId -> Handler ()
|
checkAlert :: BeverageId -> Int -> Handler ()
|
||||||
checkAlert bId = do
|
checkAlert bId oldamount = do
|
||||||
bev <- runDB $ getJust bId
|
bev <- runDB $ getJust bId
|
||||||
if beverageAmount bev < beverageAlertAmount bev
|
let alert = beverageAlertAmount bev
|
||||||
then do
|
when (beverageAmount bev < alert && oldamount > alert) $ do
|
||||||
master <- getYesod
|
master <- getYesod
|
||||||
let to = appEmail $ appSettings master
|
let tos = appEmail $ appSettings master
|
||||||
|
mapM_ (\to ->
|
||||||
liftIO $ sendMail to "Niedriger Bestand"
|
liftIO $ sendMail to "Niedriger Bestand"
|
||||||
[stext|
|
[stext|
|
||||||
Hallo,
|
Hallo,
|
||||||
|
@ -199,10 +200,9 @@ Der momentane Bestand ist bei #{beverageAmount bev} Artikeln.
|
||||||
|
|
||||||
Viele Grüße,
|
Viele Grüße,
|
||||||
|
|
||||||
der Matemat
|
Dein Matemat
|
||||||
|]
|
|]
|
||||||
else
|
) tos
|
||||||
return () -- do nothing
|
|
||||||
|
|
||||||
sendMail :: MonadIO m => Text -> Text -> TL.Text -> m ()
|
sendMail :: MonadIO m => Text -> Text -> TL.Text -> m ()
|
||||||
sendMail to subject body =
|
sendMail to subject body =
|
||||||
|
|
|
@ -67,7 +67,7 @@ data AppSettings = AppSettings
|
||||||
-- ^ Copyright text to appear in the footer of the page
|
-- ^ Copyright text to appear in the footer of the page
|
||||||
, appAnalytics :: Maybe Text
|
, appAnalytics :: Maybe Text
|
||||||
-- ^ Google Analytics code
|
-- ^ Google Analytics code
|
||||||
, appEmail :: Text
|
, appEmail :: [Text]
|
||||||
-- ^ notification address
|
-- ^ notification address
|
||||||
, appCurrency :: Text
|
, appCurrency :: Text
|
||||||
-- ^ Currency character
|
-- ^ Currency character
|
||||||
|
|
|
@ -26,7 +26,8 @@ database:
|
||||||
poolsize: "_env:PGPOOLSIZE:10"
|
poolsize: "_env:PGPOOLSIZE:10"
|
||||||
|
|
||||||
#analytics: UA-YOURCODE
|
#analytics: UA-YOURCODE
|
||||||
email: "nek0@momen"
|
email:
|
||||||
|
- "nek0@momen"
|
||||||
currency: "€"
|
currency: "€"
|
||||||
cash_charge: 50
|
cash_charge: 50
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue