fix(avs): towards #169 - superiors are elevated to max priority for that company
this entails that users may have multiple equal priority companies
This commit is contained in:
parent
99f03078a1
commit
5bf85394d4
@ -676,9 +676,14 @@ upsertCompanySuperior (mbCid, newAfi) mbOldAfi = runMaybeT $ do
|
||||
oldSup = snd <$> oldChanges
|
||||
unless (supChange == Just False) $ do
|
||||
-- upsert new superior company supervisor
|
||||
mbMaxPrio <- E.selectOne $ do
|
||||
usrCmp <- E.from $ E.table @UserCompany
|
||||
E.where_ $ usrCmp E.^. UserCompanyUser E.==. E.val supid
|
||||
return . E.max_ $ usrCmp E.^. UserCompanyPriority
|
||||
let maxPrio = maybe 1 (fromMaybe 1 . E.unValue) mbMaxPrio
|
||||
suprEnt <- upsertBy (UniqueUserCompany supid cid)
|
||||
(UserCompany supid cid True False 1 True)
|
||||
[UserCompanySupervisor =. True]
|
||||
(UserCompany supid cid True False maxPrio True)
|
||||
[UserCompanySupervisor =. True, UserCompanyPriority =. maxPrio]
|
||||
E.insertSelectWithConflict UniqueUserSupervisor
|
||||
(do
|
||||
usr <- E.from $ E.table @UserCompany
|
||||
|
||||
Loading…
Reference in New Issue
Block a user