@@ -58,7 +58,8 @@ module Data.Query (
58 deactivateToken,
58 deactivateToken,
59 searchUsers,
59 searchUsers,
60 searchTags,
60 searchTags,
61− updateUser
61+ updateUser,
64import Squeal.PostgreSQL
65import Squeal.PostgreSQL
@@ -287,7 +288,7 @@ getChannelForUserQ = selectStar $
287 from (table #channels) &
288 from (table #channels) &
288 where_ (#namedChannelFullOwner .== param @1 .&& #namedChannelFullId .== param @2)
289 where_ (#namedChannelFullOwner .== param @1 .&& #namedChannelFullId .== param @2)
290−updateUserQ :: Manipulation Schema (TuplePG (User FacultyUrl)) (RowPG (Only UserId))
291+updateUserQ :: Manipulation Schema (TuplePG (UserUpdateRow)) (RowPG (Only UserId))
291updateUserQ = update #users (
292updateUserQ = update #users (
292 Same `as` #userRowId :*
293 Same `as` #userRowId :*
293 Set (param @2) `as` #userRowFirstName :*
294 Set (param @2) `as` #userRowFirstName :*
@@ -296,7 +297,7 @@ updateUserQ = update #users (
296 Set (param @5) `as` #userRowFacultyUrl :*
297 Set (param @5) `as` #userRowFacultyUrl :*
297 Same `as` #userRowEmail :*
298 Same `as` #userRowEmail :*
298 Same `as` #userRowIsValidated)
299 Same `as` #userRowIsValidated)
299− (#userRowId .== param @1 .&& #userRowEmail .== param @6)
300+ (#userRowId .== param @1)
300 (Returning $ #userRowId `as` #fromOnly)
301 (Returning $ #userRowId `as` #fromOnly)
302getAllChannelsForUserQ :: Query Schema (TuplePG (Only UserId)) (RowPG NamedChannelFull)
303getAllChannelsForUserQ :: Query Schema (TuplePG (Only UserId)) (RowPG NamedChannelFull)
@@ -745,9 +746,18 @@ instance ToJSON UserCreation where
747instance FromJSON UserCreation where
748instance FromJSON UserCreation where
748− parseJSON = withObject "named channel" $ \e ->
749+ parseJSON = withObject "user creation" $ \e ->
749 UserCreation <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
750 UserCreation <$> e .: "firstName" <*> e .: "middleName" <*> e .: "lastName" <*> e .: "faculty" <*> e .: "email"
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)
751data NamedChannelCreation = NamedChannelCreation {
761data NamedChannelCreation = NamedChannelCreation {
752 namedChannelCreationOwner :: UserId,
762 namedChannelCreationOwner :: UserId,
753 namedChannelCreationName :: Text,
763 namedChannelCreationName :: Text,
@@ -1055,19 +1065,18 @@ deactivateToken uId dData = fmap fromOnly <$> (manipulateParams deactivateTokenQ
1055getVerifiedToken :: UserId -> ByteString -> StaticPQ (Maybe Token)
1065getVerifiedToken :: UserId -> ByteString -> StaticPQ (Maybe Token)
1056getVerifiedToken uId tokenData = runQueryParams getVerifiedTokenQ (uId, hash tokenData) >>= firstRow
1066getVerifiedToken uId tokenData = runQueryParams getVerifiedTokenQ (uId, hash tokenData) >>= firstRow
1058−updateUser :: (User FacultyUrl) -> StaticPQ (Maybe UserId)
1068+updateUser :: (UserUpdateRow) -> StaticPQ (Maybe UserId)
1059updateUser user = fmap fromOnly <$> (manipulateParams updateUserQ (normalizeUser user) >>= firstRow)
1069updateUser user = fmap fromOnly <$> (manipulateParams updateUserQ (normalizeUser user) >>= firstRow)
1061-- MARK: Utils
1071-- MARK: Utils
1063−normalizeUser :: User FacultyUrl -> User FacultyUrl
1073+normalizeUser :: UserUpdateRow -> UserUpdateRow
1064−normalizeUser User{..} = User {
1074+normalizeUser UserUpdateRow{..} = UserUpdateRow {
1065− userId = userId,
1075+ userUpdateRowId = userUpdateRowId,
1066− firstName = T.strip $ firstName,
1076+ userUpdateRowFirstName = T.strip $ userUpdateRowFirstName,
1067− middleName = T.strip $ middleName,
1077+ userUpdateRowMiddleName = T.strip $ userUpdateRowMiddleName,
1068− lastName = T.strip $ lastName,
1078+ userUpdateRowLastName = T.strip $ userUpdateRowLastName,
1069− userFaculty = T.toLower . T.strip $ userFaculty,
1079+ userUpdateRowUserFaculty = T.toLower . T.strip $ userUpdateRowUserFaculty
1070− userEmail = T.toLower . T.strip $ userEmail
1073data UserRow = UserRow {
1082data UserRow = UserRow {