11import { Team , Task as Prisma_Task , WBS_Element } from '@prisma/client' ;
22import { UserWithSettings } from './auth.utils' ;
33import { HttpException } from './errors.utils' ;
4+ import { getTeamsFromUsers } from './teams.utils' ;
45
56export type UserWithTeams = UserWithSettings & {
67 teamAsHead : Team | null ;
@@ -28,7 +29,7 @@ export const getTeamFromTaskAssignees = (users: UserWithTeams[]): Team => {
2829 const usersTeams = getTeamsFromUsers ( users ) ;
2930
3031 firstUsersTeams: for ( const team of usersTeams [ 0 ] ) {
31- for ( let i = 0 ; i < usersTeams . length ; i ++ ) {
32+ for ( let i = 1 ; i < usersTeams . length ; i ++ ) {
3233 // If the team is not found in the current user's teams, continue to the next team
3334 if ( ! usersTeams [ i ] . some ( ( t ) => t . teamId === team . teamId ) ) continue firstUsersTeams;
3435 }
@@ -38,21 +39,6 @@ export const getTeamFromTaskAssignees = (users: UserWithTeams[]): Team => {
3839 throw new HttpException ( 400 , 'All of the users do not share a team!' ) ;
3940} ;
4041
41- /**
42- * Gets the teams from a list of users
43- * @param users the users to get the teams from
44- * @returns an array of the teams each user is in
45- */
46- export const getTeamsFromUsers = ( users : UserWithTeams [ ] ) : Team [ ] [ ] => {
47- return users . map ( ( user ) => {
48- const teams = [ ] ;
49- if ( user . teamAsHead ) teams . push ( user . teamAsHead ) ;
50- if ( user . teamsAsLead ) teams . push ( ...user . teamsAsLead ) ;
51- if ( user . teamsAsMember ) teams . push ( ...user . teamsAsMember ) ;
52- return teams ;
53- } ) ;
54- } ;
55-
5642/**
5743 * Gets the beginning of the day tomorrow
5844 * @returns the beginning of the day tomorrow (at 12am)
0 commit comments