chore(users): allow multiple company-user associations at once

This commit is contained in:
Steffen Jost 2023-01-27 11:48:37 +01:00
parent e188670478
commit 43ace1c6a0
3 changed files with 13 additions and 10 deletions

View File

@ -88,12 +88,12 @@ UserCompany
user UserId
company CompanyId OnDeleteCascade OnUpdateCascade
supervisor Bool -- is this user a company supervisor?
UniqueUserCompany user -- only one company per user is currently allowed
UniqueUserCompany user company -- a user may belong to multiple companies, but to each one only once
deriving Generic
UserSupervisor
supervisor UserId -- multiple supervisor per trainee possible
user UserId
rerouteNotifications Bool -- User can be his own supervisor to receive notifications as well
UniqueUserSupervisor supervisor user
UniqueUserSupervisor supervisor user -- each supervisor/user combination is unique (same supervisor can superviser the same user only once)
deriving Generic

View File

@ -17,10 +17,10 @@ import qualified Data.Text as Text
upsertUserCompany :: UserId -> Maybe Text -> DB ()
upsertUserCompany uid (Just cName) | notNull cName = do
cid <- upsertCompany cName
void $ upsertBy (UniqueUserCompany uid)
void $ upsertBy (UniqueUserCompany uid cid)
(UserCompany uid cid False)
[UserCompanyCompany =. cid, UserCompanySupervisor =. False]
upsertUserCompany uid _ = deleteBy (UniqueUserCompany uid)
[]
upsertUserCompany uid _ = deleteWhere [ UserCompanyUser ==. uid ]
upsertCompany :: Text -> DB CompanyId
upsertCompany cName =

View File

@ -475,15 +475,18 @@ fillDb = do
I am aware that violations in the form plagiarism or collaboration with third parties will lead to expulsion from the course.
|]
}
fraportAg <- insert' $ Company "Fraport AG" "Fraport" 1 False Nothing
_fraGround <- insert' $ Company "Fraport Ground Handling Professionals GmbH" "FraGround" 2 False Nothing -- TODO: better testcases
nice <- insert' $ Company "N*ICE Aircraft Services & Support GmbH" "N*ICE" 33 False Nothing
_ffacil <- insert' $ Company "Fraport Facility Services GmbH" "GCS" 44 False Nothing
bpol <- insert' $ Company "Bundespolizeidirektion Flughafen Frankfurt am Main" "BPol" 5555 False Nothing
fraportAg <- insert' $ Company "Fraport AG" "Fraport" 1 False Nothing
fraGround <- insert' $ Company "Fraport Ground Handling Professionals GmbH" "FraGround" 2 False Nothing -- TODO: better testcases
nice <- insert' $ Company "N*ICE Aircraft Services & Support GmbH" "N*ICE" 33 False Nothing
ffacil <- insert' $ Company "Fraport Facility Services GmbH" "GCS" 44 False Nothing
bpol <- insert' $ Company "Bundespolizeidirektion Flughafen Frankfurt am Main" "BPol" 5555 False Nothing
void . insert' $ UserCompany jost fraportAg True
void . insert' $ UserCompany svaupel nice True
void . insert' $ UserCompany gkleen nice False
void . insert' $ UserCompany gkleen fraGround False
void . insert' $ UserCompany fhamann bpol False
void . insert' $ UserCompany fhamann ffacil True
void . insert' $ UserCompany fhamann nice False
void . insert' $ UserSupervisor jost gkleen True
void . insert' $ UserSupervisor jost svaupel False
void . insert' $ UserSupervisor jost sbarth False