mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
Fix deleteTeamUser route
This commit is contained in:
parent
08725505f4
commit
2b4ab8a723
1 changed files with 14 additions and 8 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
import { z } from 'zod';
|
import { canDeleteTeamUser, canUpdateTeam } from '@/lib/auth';
|
||||||
import { unauthorized, json, badRequest, ok } from '@/lib/response';
|
|
||||||
import { canDeleteTeam, canUpdateTeam } from '@/lib/auth';
|
|
||||||
import { parseRequest } from '@/lib/request';
|
import { parseRequest } from '@/lib/request';
|
||||||
import { deleteTeam, getTeamUser, updateTeamUser } from '@/queries';
|
import { badRequest, json, ok, unauthorized } from '@/lib/response';
|
||||||
|
import { deleteTeamUser, getTeamUser, updateTeamUser } from '@/queries';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
|
@ -58,7 +58,7 @@ export async function POST(
|
||||||
|
|
||||||
export async function DELETE(
|
export async function DELETE(
|
||||||
request: Request,
|
request: Request,
|
||||||
{ params }: { params: Promise<{ teamId: string }> },
|
{ params }: { params: Promise<{ teamId: string; userId: string }> },
|
||||||
) {
|
) {
|
||||||
const { auth, error } = await parseRequest(request);
|
const { auth, error } = await parseRequest(request);
|
||||||
|
|
||||||
|
|
@ -66,13 +66,19 @@ export async function DELETE(
|
||||||
return error();
|
return error();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { teamId } = await params;
|
const { teamId, userId } = await params;
|
||||||
|
|
||||||
if (!(await canDeleteTeam(auth, teamId))) {
|
if (!(await canDeleteTeamUser(auth, teamId, userId))) {
|
||||||
return unauthorized('You must be the owner of this team.');
|
return unauthorized('You must be the owner of this team.');
|
||||||
}
|
}
|
||||||
|
|
||||||
await deleteTeam(teamId);
|
const teamUser = await getTeamUser(teamId, userId);
|
||||||
|
|
||||||
|
if (!teamUser) {
|
||||||
|
return badRequest('The User does not exists on this team.');
|
||||||
|
}
|
||||||
|
|
||||||
|
await deleteTeamUser(teamId, userId);
|
||||||
|
|
||||||
return ok();
|
return ok();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue