@@ -58,7 +58,8 @@ module Data.Query (
5858 deactivateToken,
5959 searchUsers,
6060 searchTags,
61− updateUser
61+ updateUser,
62+ UserUpdateRow(..)
6263 ) where
6364
6465import Squeal.PostgreSQL
@@ -287,7 +288,7 @@ getChannelForUserQ = selectStar $
287288 from (table #channels) &
288289 where_ (#namedChannelFullOwner .== param @1 .&& #namedChannelFullId .== param @2)
289290
290−updateUserQ :: Manipulation Schema (TuplePG (User FacultyUrl)) (RowPG (Only UserId))
291+updateUserQ :: Manipulation Schema (TuplePG (UserUpdateRow)) (RowPG (Only UserId))
291292updateUserQ = update #users (
292293 Same `as` #userRowId :*
293294 Set (param @2) `as` #userRowFirstName :*
@@ -296,7 +297,7 @@ updateUserQ = update #users (
296297 Set (param @5) `as` #userRowFacultyUrl :*
297298 Same `as` #userRowEmail :*
298299 Same `as` #userRowIsValidated)
299− (#userRowId .== param @1 .&& #userRowEmail .== param @6)
300+ (#userRowId .== param @1)
300301 (Returning $ #userRowId `as` #fromOnly)
301302
302303getAllChannelsForUserQ :: Query Schema (TuplePG (Only UserId)) (RowPG NamedChannelFull)
@@ -745,9 +746,18 @@ instance ToJSON UserCreation where
745746 ]
746747
747748instance FromJSON UserCreation where
748− parseJSON = withObject "named channel" $ \e ->
749+ parseJSON = withObject "user creation" $ \e ->
749750 UserCreation <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
750751
752+data UserUpdateRow = UserUpdateRow {
753+ userUpdateRowId :: UserId,
754+ userUpdateRowFirstName :: Text,
755+ userUpdateRowMiddleName :: Text,
756+ userUpdateRowLastName :: Text,
757+ userUpdateRowUserFaculty :: FacultyUrl
758+} deriving (GHC.Generic, SOP.Generic, SOP.HasDatatypeInfo)
759+
760+
751761data NamedChannelCreation = NamedChannelCreation {
752762 namedChannelCreationOwner :: UserId,
753763 namedChannelCreationName :: Text,
@@ -1055,19 +1065,18 @@ deactivateToken uId dData = fmap fromOnly <$> (manipulateParams deactivateTokenQ
10551065getVerifiedToken :: UserId -> ByteString -> StaticPQ (Maybe Token)
10561066getVerifiedToken uId tokenData = runQueryParams getVerifiedTokenQ (uId, hash tokenData) >>= firstRow
10571067
1058−updateUser :: (User FacultyUrl) -> StaticPQ (Maybe UserId)
1068+updateUser :: (UserUpdateRow) -> StaticPQ (Maybe UserId)
10591069updateUser user = fmap fromOnly <$> (manipulateParams updateUserQ (normalizeUser user) >>= firstRow)
10601070
10611071-- MARK: Utils
10621072
1063−normalizeUser :: User FacultyUrl -> User FacultyUrl
1064−normalizeUser User{..} = User {
1065− userId = userId,
1066− firstName = T.strip $ firstName,
1067− middleName = T.strip $ middleName,
1068− lastName = T.strip $ lastName,
1069− userFaculty = T.toLower . T.strip $ userFaculty,
1070− userEmail = T.toLower . T.strip $ userEmail
1073+normalizeUser :: UserUpdateRow -> UserUpdateRow
1074+normalizeUser UserUpdateRow{..} = UserUpdateRow {
1075+ userUpdateRowId = userUpdateRowId,
1076+ userUpdateRowFirstName = T.strip $ userUpdateRowFirstName,
1077+ userUpdateRowMiddleName = T.strip $ userUpdateRowMiddleName,
1078+ userUpdateRowLastName = T.strip $ userUpdateRowLastName,
1079+ userUpdateRowUserFaculty = T.toLower . T.strip $ userUpdateRowUserFaculty
10711080}
10721081
10731082data UserRow = UserRow {