From 1c2f2b7221d2bb237f3f1da61ca1cd9cde791506 Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Wed, 28 Aug 2019 14:18:36 +0200 Subject: [PATCH] feat(invitations): save expiresAt to DB --- models/invitations | 1 + src/Handler/Utils/Invitations.hs | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/models/invitations b/models/invitations index c1d15148c..c915d08e4 100644 --- a/models/invitations +++ b/models/invitations @@ -2,4 +2,5 @@ Invitation email UserEmail for Value data Value + expiresAt UTCTime Maybe UniqueInvitation email for \ No newline at end of file diff --git a/src/Handler/Utils/Invitations.hs b/src/Handler/Utils/Invitations.hs index 22b846c66..00b266b0f 100644 --- a/src/Handler/Utils/Invitations.hs +++ b/src/Handler/Utils/Invitations.hs @@ -220,7 +220,12 @@ sinkInvitations InvitationConfig{..} = determineExists .| sinkInvitations' jInvitationSubject <- fmap mr . mapReaderT liftHandlerT $ invitationSubject fEnt dat let jInvitationExplanation = invitationExplanation fEnt dat (toHtml . mr) ur - when (is _Nothing (ephemeralInvitation @junction)) $ insert_ $ Invitation jInvitee (invRef @junction fid) (toJSON $ dat ^. _invitationDBData) + when (is _Nothing (ephemeralInvitation @junction)) $ insert_ $ Invitation + { invitationEmail = jInvitee + , invitationFor = invRef @junction fid + , invitationData = toJSON $ dat ^. _invitationDBData + , invitationExpiresAt = tokenExpiresAt token + } queueDBJob JobInvitation{..} @@ -243,9 +248,9 @@ sourceInvitations :: forall junction. -> Source (YesodDB UniWorX) (UserEmail, InvitationDBData junction) sourceInvitations forKey = selectSource [InvitationFor ==. invRef @junction forKey] [] .| C.mapM decode where - decode (Entity _ (Invitation email _ invitationData)) + decode (Entity _ (Invitation{invitationEmail, invitationData})) = case fromJSON invitationData of - JSON.Success dbData -> return (email, dbData) + JSON.Success dbData -> return (invitationEmail, dbData) JSON.Error str -> fail $ "Could not decode invitationData: " <> str sourceInvitationsList :: forall junction.