style: linting and formatting

This commit is contained in:
Riccardo
2023-11-29 19:44:39 +01:00
parent 74ec709155
commit 77a9d50927
23 changed files with 1452 additions and 127 deletions

View File

@@ -1,4 +1,5 @@
import { z } from 'zod';
import { fromZodError } from 'zod-validation-error';
import prisma from '../../../prisma/prisma';
import { ResponseSchema, SubscribeFormSchema } from '../../utils/types';
@@ -7,7 +8,8 @@ export async function POST(request: Request) {
const body = await request.json();
const validation = SubscribeFormSchema.safeParse(body);
if (!validation.success) {
return new Response('Bad request', { status: 400 });
const message = fromZodError(validation.error);
return new Response(message.message, { status: 400 });
}
const { email, targetingAllowed } = validation.data;
@@ -15,18 +17,18 @@ export async function POST(request: Request) {
await prisma.user.upsert({
create: {
email,
targetingAllowed,
targetingAllowed
},
update: {
targetingAllowed,
targetingAllowed
},
where: {
email,
},
email
}
});
const message: z.infer<typeof ResponseSchema> = {
message: `${email} subscribed!`,
message: `${email} subscribed!`
};
return new Response(JSON.stringify(message), { status: 200 });
}