@@ -47,7 +47,7 @@ export default class TeamsService {
4747 * @param teamId a id of team to be updated
4848 * @param userIds a array of user Ids that replaces team's old members
4949 * @returns a updated team
50- * @throws if the team is not found, the submitter has no priviledge , or any user from the given userIds does not exist
50+ * @throws if the team is not found, the submitter has no privilege , or any user from the given userIds does not exist
5151 */
5252 static async setTeamMembers ( submitter : User , teamId : string , userIds : number [ ] ) : Promise < Team > {
5353 // find and verify the given teamId exist
@@ -56,9 +56,14 @@ export default class TeamsService {
5656 ...teamQueryArgs
5757 } ) ;
5858
59- if ( ! team ) throw new NotFoundException ( 'Team' , teamId ) ;
60- if ( ! isAdmin ( submitter . role ) && submitter . userId !== team . headId )
61- throw new AccessDeniedException ( 'you must be an admin or the team head to update the members!' ) ;
59+ if ( ! team ) {
60+ throw new NotFoundException ( 'Team' , teamId ) ;
61+ }
62+
63+ const isTeamLead = team . leads . some ( ( lead ) => lead . userId === submitter . userId ) ;
64+
65+ if ( ! isAdmin ( submitter . role ) && submitter . userId !== team . headId && ! isTeamLead )
66+ throw new AccessDeniedException ( 'you must be an admin, the team head, or a team lead to update the members!' ) ;
6267
6368 // this throws if any of the users aren't found
6469 const users = await getUsers ( userIds ) ;
0 commit comments