Fix joining team dupe. Add loading to team member remove. Fix messages.

This commit is contained in:
Brian Cao 2023-03-29 16:02:14 -07:00
parent a22d50a597
commit 6d5aeb3bd1
7 changed files with 90 additions and 11 deletions

View file

@ -3,7 +3,7 @@ import { NextApiRequestQueryBody } from 'lib/types';
import { useAuth } from 'lib/middleware';
import { NextApiResponse } from 'next';
import { methodNotAllowed, ok, notFound } from 'next-basics';
import { createTeamUser, getTeam } from 'queries';
import { createTeamUser, getTeam, getTeamUser } from 'queries';
import { ROLES } from 'lib/constants';
export interface TeamsJoinRequestBody {
@ -25,6 +25,12 @@ export default async (
return notFound(res, 'message.team-not-found');
}
const teamUser = await getTeamUser(team.id, req.auth.user.id);
if (teamUser) {
return methodNotAllowed(res, 'message.team-already-member');
}
await createTeamUser(req.auth.user.id, team.id, ROLES.teamMember);
return ok(res, team);