File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -26,13 +26,11 @@ class Team {
26
26
@JoinColumn ( )
27
27
members : Array < Hacker > ;
28
28
29
- @Column ( { nullable : true } )
30
- @IsString ( )
31
- submission ?: string ;
29
+ @Column ( { type : String , nullable : true } )
30
+ submission ?: string | null ;
32
31
33
- @Column ( { nullable : true } )
34
- @IsString ( )
35
- project ?: string ;
32
+ @Column ( { type : String , nullable : true } )
33
+ project ?: string | null ;
36
34
}
37
35
38
36
export default Team ;
Original file line number Diff line number Diff line change @@ -56,11 +56,26 @@ export class TeamService {
56
56
}
57
57
58
58
public async removeMember ( hacker : Hacker ) : Promise < void > {
59
+ // hacker.team does return a number (it's the identifier).
60
+ // However, the underlying model dictates that team attribute of Hacker should be Team.
61
+ // I'm not sure why? I didn't want to change that incase it breaked something else.
62
+ // This throws a parsing error. But it will work.
63
+ const team = await this . findByIdentifier ( hacker . team ) ;
64
+
59
65
await this . teamRepository
60
66
. createQueryBuilder ( "team" )
61
67
. relation ( Hacker , "team" )
62
68
. of ( hacker )
63
69
. set ( { team : null } ) ;
70
+
71
+ // If the person we're removing is the last one left on the team. Clean up teams as well.
72
+ if ( team && team . members . length == 1 ) {
73
+ await this . teamRepository
74
+ . createQueryBuilder ( "team" )
75
+ . delete ( )
76
+ . where ( "name = :name" , { name : team . name } )
77
+ . execute ( ) ;
78
+ }
64
79
}
65
80
66
81
public async update (
You can’t perform that action at this time.
0 commit comments