chore(AVS): (WIP) implement user avs update to primary company
This commit is contained in:
parent
7a5917131c
commit
d213c8e4a1
@ -517,23 +517,17 @@ updateAvsUserByIds apids = do
|
|||||||
oldCompanyEnt <- getAvsCompany `traverseJoin` oldAvsFirmInfo
|
oldCompanyEnt <- getAvsCompany `traverseJoin` oldAvsFirmInfo
|
||||||
let oldCompanyId = entityKey <$> oldCompanyEnt
|
let oldCompanyId = entityKey <$> oldCompanyEnt
|
||||||
oldCompanyMb = entityVal <$> oldCompanyEnt
|
oldCompanyMb = entityVal <$> oldCompanyEnt
|
||||||
pst_up = mkUpdate usr newCompany oldCompanyMb $ CheckAvsUpdate UserPrefersPostal _companyPrefersPostal -- possibly change postal preference TODO: only if needed
|
pst_up = mkUpdate usr newCompany oldCompanyMb $ CheckAvsUpdate UserPrefersPostal _companyPrefersPostal -- possibly change postal preference
|
||||||
superReasonComDef = tshow SupervisorReasonCompanyDefault
|
superReasonComDef = tshow SupervisorReasonCompanyDefault
|
||||||
_primaryCompanyId <- getUserPrimaryCompany usrId (Just . CompanyKey . companyShorthand)
|
newUserComp = UserCompany usrId newCompanyId False False 1 True -- default value for new company insertion, if no update can be done
|
||||||
|
primaryCompanyId <- getUserPrimaryCompany usrId (Just . CompanyKey . companyShorthand)
|
||||||
|
|
||||||
usr_ups <- case oldAvsFirmInfo of
|
usr_ups <- case oldAvsFirmInfo of
|
||||||
_ | oldCompanyId == Just newCompanyId -- company unchanged entirely
|
_ | Just newCompanyId == oldCompanyId -- company unchanged entirely
|
||||||
-> return usr_up0 -- => do nothing
|
-> return usr_up0 -- => do nothing
|
||||||
(Just oafi) | ((==) `on` view _avsFirmPostAddressSimple) oafi newAvsFirmInfo -- company address unchanged OR
|
(Just oafi) | ((==) `on` view _avsFirmPostAddressSimple) oafi newAvsFirmInfo -- company address unchanged OR
|
||||||
|| ((==) `on` view _avsFirmPrimaryEmail) oafi newAvsFirmInfo -- company primary email unchanged
|
|| ((==) `on` view _avsFirmPrimaryEmail) oafi newAvsFirmInfo -- company primary email unchanged
|
||||||
-> do -- => just update user company association, keeping supervision privileges
|
-> do -- => just update user company association, keeping supervision privileges
|
||||||
-- newUC <- getBy (UniqueUserCompany usrId oldCompanyId) >>= \case
|
|
||||||
-- Nothing -> return $ UserCompany usrId newCompanyId False False 1 True
|
|
||||||
-- Just Entity{entityVal=oldUCid, entityVal=oldUC} -> do
|
|
||||||
-- delete oldUCid
|
|
||||||
-- return $ oldUC & _userCompanyCompany .~ newCompanyId
|
|
||||||
-- void $ insertUnique newUC
|
|
||||||
let newUserComp = UserCompany usrId newCompanyId False False 1 True
|
|
||||||
case oldCompanyId of
|
case oldCompanyId of
|
||||||
Nothing -> void $ insertUnique newUserComp -- it's ok if this already exists
|
Nothing -> void $ insertUnique newUserComp -- it's ok if this already exists
|
||||||
Just ocid -> do
|
Just ocid -> do
|
||||||
@ -543,15 +537,16 @@ updateAvsUserByIds apids = do
|
|||||||
, UserSupervisorReason ==. Just superReasonComDef] -- to we want this last condition?
|
, UserSupervisorReason ==. Just superReasonComDef] -- to we want this last condition?
|
||||||
[ UserSupervisorCompany =. Just newCompanyId]
|
[ UserSupervisorCompany =. Just newCompanyId]
|
||||||
return usr_up0
|
return usr_up0
|
||||||
-- _ | newCompanyId == primaryCompanyId -- Wechsel der AVS-Firma zur FRADrive-Primärfirma
|
_ | Just newCompanyId == primaryCompanyId -- Wechsel der AVS-Firma zur FRADrive-Primärfirma
|
||||||
-- alte CompanyUser entfernen
|
-> do
|
||||||
-- keep Supervision unchanged
|
whenIsJust oldCompanyId $ deleteBy . UniqueUserCompany usrId
|
||||||
-- keep postal preference
|
when (isJust oldCompanyId) $ deleteWhere $ (UserSupervisorUser ==. usrId):(UserSupervisorCompany ==. oldCompanyId):(UserSupervisorReason ~=. superReasonComDef)
|
||||||
|
return usr_up0
|
||||||
_ -- company changed completely
|
_ -- company changed completely
|
||||||
-> do -- switch company
|
-> do -- switch company, keeping priority
|
||||||
(getBy . UniqueUserCompany usrId) `traverseJoin` oldCompanyId >>= \case
|
(getBy . UniqueUserCompany usrId) `traverseJoin` oldCompanyId >>= \case
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
void $ insertUnique $ UserCompany usrId newCompanyId False False 1 True
|
void $ insertUnique newUserComp
|
||||||
Just Entity{entityKey=ucidOld, entityVal=UserCompany{userCompanyCompany, userCompanySupervisor, userCompanySupervisorReroute, userCompanyPriority}} -> do
|
Just Entity{entityKey=ucidOld, entityVal=UserCompany{userCompanyCompany, userCompanySupervisor, userCompanySupervisorReroute, userCompanyPriority}} -> do
|
||||||
when userCompanySupervisor $ reportAdminProblem $ AdminProblemSupervisorNewCompany usrId userCompanyCompany newCompanyId userCompanySupervisorReroute
|
when userCompanySupervisor $ reportAdminProblem $ AdminProblemSupervisorNewCompany usrId userCompanyCompany newCompanyId userCompanySupervisorReroute
|
||||||
delete ucidOld
|
delete ucidOld
|
||||||
|
|||||||
Reference in New Issue
Block a user