Skip to content

Commit

Permalink
Don't delete teams (#83)
Browse files Browse the repository at this point in the history
* No deletey

* Add all member info
  • Loading branch information
ryanlyrl committed Jan 30, 2021
1 parent a1db6f0 commit 08387cc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
17 changes: 16 additions & 1 deletion src/controllers/dashboardController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const triggerUpdateTime = async (req: Request, res: Response): Promise<vo
export const getDashboardInfo = async (req: Request, res: Response): Promise<void> => {
// Grab currently logged in user
const eventRepository = getManager().getRepository(Event);
const userRepo = getManager().getRepository(User);
const currentTime = new Date();

const token = req.header('Authorization')?.split(' ')[1];
Expand All @@ -52,6 +53,19 @@ export const getDashboardInfo = async (req: Request, res: Response): Promise<voi
return;
}

let teamMembers = [];
if(user.team) {
for(const member of user.team.members) {
const memberUser = await userRepo.findOne({id: member.id}, {relations: ['application']});
teamMembers.push({
...member,
firstName: memberUser?.application?.firstName,
lastName: memberUser?.application?.lastName,
discordUsername: memberUser?.discordUsername
});
}
}

if(!user.application) {
res.status(403).send("User does not have an application");
return;
Expand All @@ -78,7 +92,8 @@ export const getDashboardInfo = async (req: Request, res: Response): Promise<voi
startTime: STARTTIME,
endTime: ENDTIME,
firstName: user.application.firstName,
lastName: user.application.lastName
lastName: user.application.lastName,
teamMembers: teamMembers
});

};
7 changes: 1 addition & 6 deletions src/controllers/teamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,7 @@ export const leaveTeam = async (req: Request, res: Response): Promise<void> => {
if(item.uuid == user.uuid) team.members.splice(index, 1);
});

// Team is empty, delete it
if(team.members.length == 0) {
await teamRepository.remove(team);
} else {
await teamRepository.save(team);
}
await teamRepository.save(team);

res.sendStatus(200);
}
Expand Down
4 changes: 2 additions & 2 deletions src/entity/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class Team {
@IsDefined()
name?: string;

@OneToMany(() => User, user => user.team, {cascade: true, eager: true, onDelete: 'SET NULL'})
@OneToMany(() => User, user => user.team, {cascade: true, eager: true})
members!: User[];

@OneToMany(() => TeamInvite, invite => invite.team, {cascade: true, onDelete: 'SET NULL'})
@OneToMany(() => TeamInvite, invite => invite.team, {cascade: true})
invites!: TeamInvite[];

@OneToOne(() => Submission, submission => submission.team)
Expand Down
2 changes: 1 addition & 1 deletion src/entity/TeamInvite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class TeamInvite {
@IsDefined()
uuid!: string;

@ManyToOne(() => Team, team => team.invites, {onDelete: 'SET NULL'})
@ManyToOne(() => Team, team => team.invites)
@IsDefined()
team!: Team;

Expand Down

0 comments on commit 08387cc

Please sign in to comment.