mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
fix response error return type
This commit is contained in:
parent
460200dfef
commit
8083482ba8
12 changed files with 23 additions and 25 deletions
2
pnpm-lock.yaml
generated
2
pnpm-lock.yaml
generated
|
|
@ -364,8 +364,6 @@ importers:
|
|||
specifier: ^5.9.2
|
||||
version: 5.9.2
|
||||
|
||||
dist: {}
|
||||
|
||||
packages:
|
||||
|
||||
'@ampproject/remapping@2.3.0':
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ lin
|
|||
return Response.json(result);
|
||||
} catch (e: any) {
|
||||
if (e.message.toLowerCase().includes('unique constraint') && e.message.includes('slug')) {
|
||||
return badRequest('That slug is already taken.');
|
||||
return badRequest({ message: 'That slug is already taken.' });
|
||||
}
|
||||
|
||||
return serverError(e);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { checkPassword, hashPassword } from '@/lib/auth';
|
||||
import { checkPassword, hashPassword } from '@/lib/password';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { json, badRequest } from '@/lib/response';
|
||||
import { getUser, updateUser } from '@/queries/prisma/user';
|
||||
|
|
@ -22,7 +22,7 @@ export async function POST(request: Request) {
|
|||
const user = await getUser(userId, { includePassword: true });
|
||||
|
||||
if (!checkPassword(currentPassword, user.password)) {
|
||||
return badRequest('Current password is incorrect');
|
||||
return badRequest({ message: 'Current password is incorrect' });
|
||||
}
|
||||
|
||||
const password = hashPassword(newPassword);
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ pix
|
|||
return Response.json(pixel);
|
||||
} catch (e: any) {
|
||||
if (e.message.toLowerCase().includes('unique constraint') && e.message.includes('slug')) {
|
||||
return badRequest('That slug is already taken.');
|
||||
return badRequest({ message: 'That slug is already taken.' });
|
||||
}
|
||||
|
||||
return serverError(e);
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ export async function POST(request: Request) {
|
|||
const website = await fetchWebsite(websiteId);
|
||||
|
||||
if (!website) {
|
||||
return badRequest('Website not found.');
|
||||
return badRequest({ message: 'Website not found.' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ team
|
|||
const team = await getTeam(teamId, { includeMembers: true });
|
||||
|
||||
if (!team) {
|
||||
return notFound('Team not found.');
|
||||
return notFound({ message: 'Team not found.' });
|
||||
}
|
||||
|
||||
return json(team);
|
||||
|
|
@ -41,7 +41,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ tea
|
|||
const { teamId } = await params;
|
||||
|
||||
if (!(await canUpdateTeam(auth, teamId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
const team = await updateTeam(teamId, body);
|
||||
|
|
@ -62,7 +62,7 @@ export async function DELETE(
|
|||
const { teamId } = await params;
|
||||
|
||||
if (!(await canDeleteTeam(auth, teamId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
await deleteTeam(teamId);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export async function GET(
|
|||
const { teamId, userId } = await params;
|
||||
|
||||
if (!(await canUpdateTeam(auth, teamId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
const teamUser = await getTeamUser(teamId, userId);
|
||||
|
|
@ -42,13 +42,13 @@ export async function POST(
|
|||
const { teamId, userId } = await params;
|
||||
|
||||
if (!(await canUpdateTeam(auth, teamId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
const teamUser = await getTeamUser(teamId, userId);
|
||||
|
||||
if (!teamUser) {
|
||||
return badRequest('The User does not exists on this team.');
|
||||
return badRequest({ message: 'The User does not exists on this team.' });
|
||||
}
|
||||
|
||||
const user = await updateTeamUser(teamUser.id, body);
|
||||
|
|
@ -69,13 +69,13 @@ export async function DELETE(
|
|||
const { teamId, userId } = await params;
|
||||
|
||||
if (!(await canDeleteTeamUser(auth, teamId, userId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
const teamUser = await getTeamUser(teamId, userId);
|
||||
|
||||
if (!teamUser) {
|
||||
return badRequest('The User does not exists on this team.');
|
||||
return badRequest({ message: 'The User does not exists on this team.' });
|
||||
}
|
||||
|
||||
await deleteTeamUser(teamId, userId);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ team
|
|||
const { teamId } = await params;
|
||||
|
||||
if (!(await canViewTeam(auth, teamId))) {
|
||||
return unauthorized('You must be the owner of this team.');
|
||||
return unauthorized({ message: 'You must be the owner of this team.' });
|
||||
}
|
||||
|
||||
const filters = await getQueryFilters(query);
|
||||
|
|
@ -71,7 +71,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ tea
|
|||
const teamUser = await getTeamUser(teamId, userId);
|
||||
|
||||
if (teamUser) {
|
||||
return badRequest('User is already a member of the Team.');
|
||||
return badRequest({ message: 'User is already a member of the Team.' });
|
||||
}
|
||||
|
||||
const users = await createTeamUser(userId, teamId, role);
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ export async function POST(request: Request) {
|
|||
});
|
||||
|
||||
if (!team) {
|
||||
return notFound('Team not found.');
|
||||
return notFound({ message: 'Team not found.' });
|
||||
}
|
||||
|
||||
const teamUser = await getTeamUser(team.id, auth.user.id);
|
||||
|
||||
if (teamUser) {
|
||||
return badRequest('User is already a team member.');
|
||||
return badRequest({ message: 'User is already a team member.' });
|
||||
}
|
||||
|
||||
const user = await createTeamUser(auth.user.id, team.id, ROLES.teamMember);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { z } from 'zod';
|
|||
import { canUpdateUser, canViewUser, canDeleteUser } from '@/permissions';
|
||||
import { getUser, getUserByUsername, updateUser, deleteUser } from '@/queries';
|
||||
import { json, unauthorized, badRequest, ok } from '@/lib/response';
|
||||
import { hashPassword } from '@/lib/auth';
|
||||
import { hashPassword } from '@/lib/password';
|
||||
import { parseRequest } from '@/lib/request';
|
||||
import { userRoleParam } from '@/lib/schema';
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ use
|
|||
const user = await getUserByUsername(username);
|
||||
|
||||
if (user) {
|
||||
return badRequest('User already exists');
|
||||
return badRequest({ message: 'User already exists' });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ export async function DELETE(
|
|||
}
|
||||
|
||||
if (userId === auth.user.id) {
|
||||
return badRequest('You cannot delete yourself.');
|
||||
return badRequest({ message: 'You cannot delete yourself.' });
|
||||
}
|
||||
|
||||
await deleteUser(userId);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { z } from 'zod';
|
||||
import { hashPassword } from '@/lib/auth';
|
||||
import { hashPassword } from '@/lib/password';
|
||||
import { canCreateUser } from '@/permissions';
|
||||
import { ROLES } from '@/lib/constants';
|
||||
import { uuid } from '@/lib/crypto';
|
||||
|
|
@ -30,7 +30,7 @@ export async function POST(request: Request) {
|
|||
const existingUser = await getUserByUsername(username, { showDeleted: true });
|
||||
|
||||
if (existingUser) {
|
||||
return badRequest('User already exists');
|
||||
return badRequest({ message: 'User already exists' });
|
||||
}
|
||||
|
||||
const user = await createUser({
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ export async function POST(
|
|||
return Response.json(website);
|
||||
} catch (e: any) {
|
||||
if (e.message.toLowerCase().includes('unique constraint') && e.message.includes('share_id')) {
|
||||
return badRequest('That share ID is already taken.');
|
||||
return badRequest({ message: 'That share ID is already taken.' });
|
||||
}
|
||||
|
||||
return serverError(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue