feat: add index and create customer form
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
import { getSession, withApiAuthRequired } from '@auth0/nextjs-auth0';
|
||||
import { CustomerForm } from '@prisma/client';
|
||||
import prisma from '@prisma/prisma';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export const GET = withApiAuthRequired(async () => {
|
||||
const session = await getSession();
|
||||
|
||||
try {
|
||||
const userModules = await prisma.user.findUniqueOrThrow({
|
||||
const userCustomerForms = await prisma.user.findUniqueOrThrow({
|
||||
where: {
|
||||
email: session?.user.email
|
||||
},
|
||||
@@ -17,7 +16,7 @@ export const GET = withApiAuthRequired(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
const customerForms: CustomerForm[] = userModules.CustomerForm;
|
||||
const customerForms: CustomerForm[] = userCustomerForms.CustomerForm;
|
||||
|
||||
return NextResponse.json({ success: true, data: customerForms });
|
||||
} catch (error) {
|
||||
@@ -40,10 +39,16 @@ export const POST = withApiAuthRequired(async request => {
|
||||
text: body.text,
|
||||
createdBy: {
|
||||
connect: {
|
||||
id: randomUUID(),
|
||||
email: session?.user.email
|
||||
}
|
||||
}
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
type: true,
|
||||
text: true,
|
||||
createdAt: true,
|
||||
updatedAt: true
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user