4
4
* See License-AGPL.txt in the project root for license information.
5
5
*/
6
6
7
+ import { Team , TeamMemberInfo , User } from "@gitpod/gitpod-protocol" ;
7
8
import { inject , injectable } from "inversify" ;
8
9
import { TypeORM } from "./typeorm" ;
9
10
import { Repository } from "typeorm" ;
10
11
import * as uuidv4 from 'uuid/v4' ;
11
12
import { TeamDB } from "../team-db" ;
12
13
import { DBTeam } from "./entity/db-team" ;
13
14
import { DBTeamMembership } from "./entity/db-team-membership" ;
14
- import { Team } from "@gitpod/gitpod-protocol " ;
15
+ import { DBUser } from "./entity/db-user " ;
15
16
16
17
@injectable ( )
17
18
export class TeamDBImpl implements TeamDB {
@@ -29,14 +30,27 @@ export class TeamDBImpl implements TeamDB {
29
30
return ( await this . getEntityManager ( ) ) . getRepository < DBTeamMembership > ( DBTeamMembership ) ;
30
31
}
31
32
33
+ protected async getUserRepo ( ) : Promise < Repository < DBUser > > {
34
+ return ( await this . getEntityManager ( ) ) . getRepository < DBUser > ( DBUser ) ;
35
+ }
36
+
32
37
public async findTeamById ( teamId : string ) : Promise < Team | undefined > {
33
38
const teamRepo = await this . getTeamRepo ( ) ;
34
39
return teamRepo . findOne ( { id : teamId } ) ;
35
40
}
36
41
37
- public async findMembershipsByTeam ( teamId : string ) : Promise < DBTeamMembership [ ] > {
42
+ public async findMembersByTeam ( teamId : string ) : Promise < TeamMemberInfo [ ] > {
38
43
const membershipRepo = await this . getMembershipRepo ( ) ;
39
- return membershipRepo . find ( { teamId } ) ;
44
+ const userRepo = await this . getUserRepo ( ) ;
45
+ const memberships = await membershipRepo . find ( { teamId } ) ;
46
+ const users = await userRepo . findByIds ( memberships . map ( m => m . userId ) ) ;
47
+ return users . map ( u => ( {
48
+ userId : u . id ,
49
+ fullName : u . fullName || u . name ,
50
+ primaryEmail : User . getPrimaryEmail ( u ) ,
51
+ avatarUrl : u . avatarUrl ,
52
+ memberSince : u . creationDate ,
53
+ } ) ) ;
40
54
}
41
55
42
56
public async findTeamsByUser ( userId : string ) : Promise < Team [ ] > {
0 commit comments