chore(users): allow multiple company-user associations at once
This commit is contained in:
parent
e188670478
commit
43ace1c6a0
@ -88,12 +88,12 @@ UserCompany
|
|||||||
user UserId
|
user UserId
|
||||||
company CompanyId OnDeleteCascade OnUpdateCascade
|
company CompanyId OnDeleteCascade OnUpdateCascade
|
||||||
supervisor Bool -- is this user a company supervisor?
|
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
|
deriving Generic
|
||||||
UserSupervisor
|
UserSupervisor
|
||||||
supervisor UserId -- multiple supervisor per trainee possible
|
supervisor UserId -- multiple supervisor per trainee possible
|
||||||
user UserId
|
user UserId
|
||||||
rerouteNotifications Bool -- User can be his own supervisor to receive notifications as well
|
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
|
deriving Generic
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,10 @@ import qualified Data.Text as Text
|
|||||||
upsertUserCompany :: UserId -> Maybe Text -> DB ()
|
upsertUserCompany :: UserId -> Maybe Text -> DB ()
|
||||||
upsertUserCompany uid (Just cName) | notNull cName = do
|
upsertUserCompany uid (Just cName) | notNull cName = do
|
||||||
cid <- upsertCompany cName
|
cid <- upsertCompany cName
|
||||||
void $ upsertBy (UniqueUserCompany uid)
|
void $ upsertBy (UniqueUserCompany uid cid)
|
||||||
(UserCompany uid cid False)
|
(UserCompany uid cid False)
|
||||||
[UserCompanyCompany =. cid, UserCompanySupervisor =. False]
|
[]
|
||||||
upsertUserCompany uid _ = deleteBy (UniqueUserCompany uid)
|
upsertUserCompany uid _ = deleteWhere [ UserCompanyUser ==. uid ]
|
||||||
|
|
||||||
upsertCompany :: Text -> DB CompanyId
|
upsertCompany :: Text -> DB CompanyId
|
||||||
upsertCompany cName =
|
upsertCompany cName =
|
||||||
|
|||||||
@ -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.
|
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
|
fraportAg <- insert' $ Company "Fraport AG" "Fraport" 1 False Nothing
|
||||||
_fraGround <- insert' $ Company "Fraport Ground Handling Professionals GmbH" "FraGround" 2 False Nothing -- TODO: better testcases
|
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
|
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
|
ffacil <- insert' $ Company "Fraport Facility Services GmbH" "GCS" 44 False Nothing
|
||||||
bpol <- insert' $ Company "Bundespolizeidirektion Flughafen Frankfurt am Main" "BPol" 5555 False Nothing
|
bpol <- insert' $ Company "Bundespolizeidirektion Flughafen Frankfurt am Main" "BPol" 5555 False Nothing
|
||||||
void . insert' $ UserCompany jost fraportAg True
|
void . insert' $ UserCompany jost fraportAg True
|
||||||
void . insert' $ UserCompany svaupel nice True
|
void . insert' $ UserCompany svaupel nice True
|
||||||
void . insert' $ UserCompany gkleen nice False
|
void . insert' $ UserCompany gkleen nice False
|
||||||
|
void . insert' $ UserCompany gkleen fraGround False
|
||||||
void . insert' $ UserCompany fhamann bpol 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 gkleen True
|
||||||
void . insert' $ UserSupervisor jost svaupel False
|
void . insert' $ UserSupervisor jost svaupel False
|
||||||
void . insert' $ UserSupervisor jost sbarth False
|
void . insert' $ UserSupervisor jost sbarth False
|
||||||
|
|||||||
Reference in New Issue
Block a user