fix(avs): updateReceivers should not re-insert formerly known receivers

This commit is contained in:
Steffen Jost 2025-02-10 17:37:14 +01:00 committed by Sarah Vaupel
parent 5e0df28444
commit d1dcdcfe91

View File

@ -175,7 +175,7 @@ updateReceivers :: UserId -> Handler (Entity User, [Entity User], Bool)
updateReceivers uid = do
-- First perform AVS update for receiver
runDBRead (getBy (UniqueUserAvsUser uid)) >>= \case
Just Entity{entityVal=UserAvs{userAvsPersonId = apid}} -> catchAll2log $ upsertAvsUserById apid
Just Entity{entityVal=UserAvs{userAvsPersonId = apid}} -> catchAll2log $ runDB $ updateAvsUserById apid
Nothing -> return ()
-- Retrieve updated user and supervisors now
(underling :: Entity User, avsSupers :: [(E.Value UserId, E.Value (Maybe AvsPersonId))]) <- runDBRead $ (,)
@ -193,7 +193,7 @@ updateReceivers uid = do
receiverIDs :: [UserId] = E.unValue <$> superVs
toUpdate = Set.fromList $ mapMaybe E.unValue avsIds
directResult = return (underling, pure underling, True) -- already contains updated address
forM_ toUpdate (catchAll2log . upsertAvsUserById) -- attempt to update postaddress from AVS
runDB $ forM_ toUpdate (catchAll2log . updateAvsUserById) -- attempt to update postaddress from AVS
if null receiverIDs
then directResult
else do