Created
November 28, 2018 00:43
-
-
Save hhefesto/2faa34af00d421300ce90b9f62ae5193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data SupportData = SupportData | |
| { issues :: [Maybe (Entity Issue)] | |
| , customer :: Maybe (Entity Customer) | |
| , followUps :: [Entity FollowUp] | |
| , customerFollowUps :: [(Entity FollowUp, Entity Customer)] | |
| } | |
| getSupportRData :: CustomerId -> Handler SupportData | |
| getSupportRData customerId = do | |
| issue_mfollowUp_customer_list :: [(Entity Issue, Maybe (Entity FollowUp), Entity Customer)] <- runDB $ | |
| E.select $ | |
| E.from $ \(c `E.InnerJoin` i `E.LeftOuterJoin` f) -> do | |
| E.on (E.just (i ^. IssueId) ==. f ?. FollowUpIssueId) | |
| E.on (c ^. CustomerId ==. i ^. IssueCustomerId) | |
| E.where_ (i ^. IssueCustomerId ==. E.val customerId) | |
| return (i, f, c) | |
| let followUps :: [Entity FollowUp] = catMaybes . snd3 . unzip3 $ issue_mfollowUp_customer_list | |
| authors_followUps <- forM followUps $ \(followUp :: Entity FollowUp) -> do | |
| runDB $ | |
| E.select $ | |
| E.from $ \c -> do | |
| E.where_ (c ^. CustomerId ==. E.val (followUpFollowUpAuthor . entityVal $ followUp)) | |
| return c | |
| let customers_followUps = zip followUps (concat $ authors_followUps) | |
| let issues :: [Maybe (Entity Issue)] = map listToMaybe . group . sort . fst3 . unzip3 $ issue_mfollowUp_customer_list | |
| let customer = listToMaybe . thd3 . unzip3 $ issue_mfollowUp_customer_list | |
| return SupportData | |
| { issues = issues | |
| , customer = customer | |
| , followUps = followUps | |
| , customerFollowUps = customers_followUps | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment