Fix joining team dupe. Add loading to team member remove. Fix messages.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user