This repository has been archived on 2026-01-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
nextjs-auth0/app/api/protected/customer-form/[id]/route.ts
2024-07-07 22:52:00 +02:00

84 lines
1.8 KiB
TypeScript

import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0';
import { CustomerFormType } from '@prisma/client';
import prisma from '@prisma/prisma';
import { CustomerForm } from '@utils/types';
import { NextRequest, NextResponse } from 'next/server';
export const GET = withApiAuthRequired(async request => {
const session = await getSession();
const x = console.log('request', request);
const result = await prisma.customerForm.findUnique({
where: {
id: 'params.id',
createdBy: {
email: session?.user.email
}
}
});
if (!result) {
return NextResponse.json(
{ success: false, message: 'Something went wrong.' },
{ status: 500 }
);
}
return NextResponse.json({ success: true, data: [] });
});
export async function PUT(
request: NextRequest,
{ params }: { params: CustomerForm }
) {
const session = await getSession();
const result = await prisma.customerForm.update({
where: {
id: params.id,
createdBy: {
email: session?.user.email
}
},
data: {
type: params.type as CustomerFormType,
text: params.text
}
});
if (!result) {
return NextResponse.json(
{ success: false, message: 'Something went wrong.' },
{ status: 500 }
);
}
return NextResponse.json({ success: true, data: result });
}
export async function DELETE(
request: NextRequest,
{ params }: { params: { id: string } }
) {
const session = await getSession();
const result = await prisma.customerForm.delete({
where: {
id: params.id,
createdBy: {
email: session?.user.email
}
}
});
if (!result) {
return NextResponse.json(
{ success: false, message: 'Something went wrong.' },
{ status: 500 }
);
}
return NextResponse.json({ success: true });
}