backend und frontent optimiert

This commit is contained in:
titver968
2025-04-16 14:34:11 +02:00
parent 5177bce04c
commit 5e7c0600a8
6 changed files with 48 additions and 31 deletions

View File

@@ -1,5 +1,6 @@
import { PrismaClient } from '@prisma/client';
import type { RequestHandler } from '@sveltejs/kit';
import { json, type RequestHandler } from '@sveltejs/kit';
import { Prisma } from '@prisma/client';
const prisma = new PrismaClient();
@@ -28,25 +29,15 @@ export const POST: RequestHandler = async ({ request }) => {
}
});
const exists = await prisma.anmeldung.findUnique({
where: { email: data.email }
});
if (exists) {
return new Response(JSON.stringify({ success: false, error: 'Diese E-Mail wurde bereits verwendet.' }), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
} else {
return new Response(JSON.stringify({ success: true }), {
headers: { 'Content-Type': 'application/json' }
});
}
return json({ success: true });
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2002') {
// Eindeutigkeit verletzt
return json({ error: 'Diese E-Mail-Adresse wurde bereits verwendet.' }, { status: 400 });
}
}
console.error(error);
return new Response(JSON.stringify({ success: false, error: 'Fehler bei Speicherung' }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
return json({ error: 'Ein Fehler ist aufgetreten.' }, { status: 500 });
}
};