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IITUCFOOJZU4OUJHBAC
EQXRXRZDYCM7BDAVBOXQYPG6C7IJT3OFGNIXCDAHJJBRKAXNGL7AC
SCXG6TJWYIPRUMT27KGKIIF6FYKTUTY74UNZ2FQTT63XZ6HIF3AAC
NEDDHXUK3GNFMOFO3KLU7NRIHCTYNWBT3D6HTKZAOXFDE6HMDZ6AC
7XN3I3QJHYMKU2DCUXX34WQMSJ4ZJOWW7FME34EANO3E5W4Q632AC
PBD7LZYQHXAA3KLH2ZUX5GW4UFML6BQ32KXZF4KZ6OYFASUYFJ5QC
BROSTG5KP3NUNLSYPVQID254TE47E5RKQAKLPIY7PGWETE6JNMTAC
GCVQD44VRPQVKPZEPIC4AOIXLJIG2ZMV3QI2Y7KALUT6NVUBSGSAC
ADMKQQGCGVSHHIMVQ4XFRDCG544SBJCYALSKZV45CQQBZ4ACUH2AC
Before t -> ["before=" <> t]
During (Interval x) -> ["after=" <> x.start, "before=" <> x.end]
After t -> ["after=" <> t]
Before t -> ["before=" <> t, "limit=100"]
During (Interval x) -> ["after=" <> x.start, "before=" <> x.end, "limit=100"]
After t -> ["after=" <> t, "limit=100"]
apiLatestEvent :: ProjectId -> Aff (Either TimelineError (Maybe Event))
apiLatestEvent pid = do
response <- get RF.json ("/api/user/projects/" <> pidStr pid <> "/events")
liftEffect
<<< runExceptT
<<< map head
<<< map decompose
<<< withExceptT LogFailure
$ parseDatedResponse response
H.modify_ (_ { selectedProject = Just p, history = hist })
latestEventResponse <- lift $ caps.getLatestEvent (unwrap p).projectId
now <- lift $ system.now
active <- lift $ case latestEventResponse of
Left err ->
(system.log $ "Error occurred retrieving the latest event: " <> show err) *>
pure Nothing
Right latestEvent -> do
let activeInterval :: TL.Event -> m (Maybe Interval)
activeInterval ev = case ev of
TL.StartEvent i ->
(system.log $ "Project has an open active interval starting " <> show i) *>
(Just <<< interval i <$> system.now)
TL.StopEvent _ ->
pure Nothing
join <$> traverse activeInterval latestEvent
WHERE project_id = ? AND user_id = ? AND event_time <= ? |]
(pid, uid, fromThyme e)
q (During s e) = pquery
WHERE project_id = ? AND user_id = ? AND event_time <= ?
ORDER BY event_time DESC
LIMIT ?
|]
(pid, uid, fromThyme e, limit)
(During s e) -> pquery
AND event_time >= ? AND event_time <= ? |]
(pid, uid, fromThyme s, fromThyme e)
q (After s) = pquery
AND event_time >= ? AND event_time <= ?
ORDER BY event_time DESC
LIMIT ?
|]
(pid, uid, fromThyme s, fromThyme e, limit)
(After s) -> pquery
WHERE project_id = ? AND user_id = ? AND event_time >= ? |]
(pid, uid, fromThyme s)
q ival
pgEval (FindLatestEvents (ProjectId pid) (UserId uid) i) = do
mode <- askNetworkMode
pquery
(logEntryParser mode)
[sql| SELECT credit_to_type,
credit_to_network, credit_to_address, credit_to_user_id, credit_to_project_id,
event_type, event_time, event_metadata
FROM work_events
WHERE project_id = ?
AND user_id = ?
ORDER BY event_time DESC
LIMIT ?|]
(pid, uid, i)
WHERE project_id = ? AND user_id = ? AND event_time >= ?
ORDER BY event_time DESC
LIMIT ?
|]
(pid, uid, fromThyme s, limit)
(Always) -> pquery
(logEntryParser mode)
[sql| SELECT credit_to_type,
credit_to_network, credit_to_address, credit_to_user_id, credit_to_project_id,
event_type, event_time,
event_metadata
FROM work_events
WHERE project_id = ? AND user_id = ?
ORDER BY event_time DESC
LIMIT ?
|]
(pid, uid, limit)
FindEvents ::ProjectId -> UserId -> Interval' -> DBOp [LogEntry BTCNet]
FindLatestEvents ::ProjectId -> UserId -> Int -> DBOp [LogEntry BTCNet]
FindEvents ::ProjectId -> UserId -> RangeQuery -> Word32 -> DBOp [LogEntry BTCNet]
:: (MonadDB m) => ProjectId -> UserId -> Interval' -> m [LogEntry BTCNet]
findEvents p u i = liftdb $ FindEvents p u i
:: (MonadDB m) => ProjectId -> UserId -> RangeQuery -> Word32 -> m [LogEntry BTCNet]
findEvents p u i l = liftdb $ FindEvents p u i l
data Interval' = Before { _end' :: C.UTCTime }
| During { _start' :: C.UTCTime, _end' :: C.UTCTime }
| After { _start' :: C.UTCTime }
makeLenses ''Interval
makeLenses ''Interval'
data RangeQuery
= Before { _end' :: C.UTCTime }
| During { _start' :: C.UTCTime, _end' :: C.UTCTime }
| After { _start' :: C.UTCTime }
| Always
makeLenses ''RangeQuery
#!/bin/bash
if [ -f ".env" ]; then
source .env
fi
if [ -z "${AFTOK_HOST}" ]; then
AFTOK_HOST="aftok.com"
fi
if [ -z "${USER}" ]; then
read -p "Username: " USER
echo
fi
if [ -z "${PID}" ]; then
read -p "Project UUID: " PID
echo
fi
curl --verbose --insecure --user $USER \
--request GET \
"https://$AFTOK_HOST/api/projects/$PID/events?after=2020-01-01T00:00:00Z"
ival <- case endpoints of
(Just s , Just e ) -> pure $ During s e
(Nothing, Just e ) -> pure $ Before e
(Just s , Nothing) -> pure $ After s
(Nothing, Nothing) -> snapError
400
"You must specify at least one of the \"after\" or \"before\" query parameters"
snapEval $ findEvents pid uid ival
userLatestEntries :: S.Handler App App [LogEntry (NetworkId, Address)]
userLatestEntries = do
uid <- requireUserId
pid <- requireProjectId
let ival = case endpoints of
(Just s , Just e ) -> During s e
(Nothing, Just e ) -> Before e
(Just s , Nothing) -> After s
(Nothing, Nothing) -> Always