spew only user summaries

This commit is contained in:
nek0 2019-09-09 12:54:56 +02:00
parent a01138e6e4
commit 3167a638df
3 changed files with 20 additions and 6 deletions

View file

@ -96,7 +96,7 @@ userTransfer (Just auid) (UserTransfer target amount) =
user <- userDetailsSelect auid conn user <- userDetailsSelect auid conn
if amount < userDetailsBalance user if amount < userDetailsBalance user
then do then do
mtarget <- filter (\u -> userId u == target) <$> userSelect (Just All) conn mtarget <- filter (\u -> userSummaryId u == target) <$> userSelect (Just All) conn
if not (null mtarget) if not (null mtarget)
then do then do
void $ addToUserBalance auid (-amount) conn void $ addToUserBalance auid (-amount) conn

View file

@ -78,17 +78,17 @@ userTable = table "user" (
) )
userSelect userSelect
:: Maybe Refine :: Maybe UserRefine
-> PGS.Connection -> PGS.Connection
-> MateHandler [User] -> MateHandler [UserSummary]
userSelect ref conn = do userSelect ref conn = do
today <- utctDay <$> (liftIO $ getCurrentTime) today <- utctDay <$> (liftIO $ getCurrentTime)
users <- liftIO $ runSelect conn (case ref of users <- liftIO $ runSelect conn (case ref of
Nothing -> keepWhen (\(_, _, _, ts, _, _, _, _, _) -> Nothing -> keepWhen (\(_, _, _, ts, _, _, _, _, _) ->
ts .>= C.constant (addDays (-30) today) ts .>= C.constant (addDays (-30) today)
) <<< queryTable userTable ) <<< queryTable userTable
Just All -> selectTable userTable Just AllUsers -> selectTable userTable
Just Old -> keepWhen (\(_, _, _, ts, _, _, _, _, _) -> Just OldUsers -> keepWhen (\(_, _, _, ts, _, _, _, _, _) ->
ts .<= C.constant (addDays (-30) today) ts .<= C.constant (addDays (-30) today)
) <<< queryTable userTable ) <<< queryTable userTable
) :: MateHandler ) :: MateHandler
@ -105,7 +105,8 @@ userSelect ref conn = do
] ]
mapM mapM
(\(i1, i2, i3, i4, i5, i6, i7, i8, i9) -> return $ (\(i1, i2, i3, i4, i5, i6, i7, i8, i9) -> return $
User i1 i2 i3 i4 i5 i6 (AuthSalt i7) (AuthHash <$> i8) (toEnum <$> i9) -- User i1 i2 i3 i4 i5 i6 (AuthSalt i7) (AuthHash <$> i8) (toEnum <$> i9)
UserSummary i1 i2 i6
) )
users users

View file

@ -39,6 +39,19 @@ instance ToJSON User where
instance FromJSON User instance FromJSON User
data UserSummary = UserSummary
{ userSummaryId :: Int
, userSummaryIdent :: T.Text
, userSummaryAvatar :: Maybe Int
}
deriving (Generic, Show)
instance ToJSON UserSummary where
toEncoding = genericToEncoding defaultOptions
instance FromJSON UserSummary
data UserSubmit = UserSubmit data UserSubmit = UserSubmit
{ userSubmitIdent :: T.Text { userSubmitIdent :: T.Text
, userSubmitEmail :: Maybe T.Text , userSubmitEmail :: Maybe T.Text