Skip to content

Commit 82423ce

Browse files
authored
fix: team api fixes for creating and deleting a team
1 parent cc012e2 commit 82423ce

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/models/team.model.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ class Team {
2626
@JoinColumn()
2727
members: Array<Hacker>;
2828

29-
@Column({ nullable: true })
30-
@IsString()
31-
submission?: string;
29+
@Column({ type: String, nullable: true })
30+
submission?: string | null;
3231

33-
@Column({ nullable: true })
34-
@IsString()
35-
project?: string;
32+
@Column({ type: String, nullable: true })
33+
project?: string | null;
3634
}
3735

3836
export default Team;

src/services/team.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,26 @@ export class TeamService {
5656
}
5757

5858
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+
5965
await this.teamRepository
6066
.createQueryBuilder("team")
6167
.relation(Hacker, "team")
6268
.of(hacker)
6369
.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+
}
6479
}
6580

6681
public async update(

0 commit comments

Comments
 (0)