project setup
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export type ContactRecord = {
|
||||
id: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
companyName: string;
|
||||
address: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
industry: string;
|
||||
notes?: string;
|
||||
subscribe: boolean;
|
||||
createdAt: Date;
|
||||
};
|
||||
|
||||
export async function saveContact({
|
||||
firstName,
|
||||
lastName,
|
||||
companyName,
|
||||
address,
|
||||
email,
|
||||
phone,
|
||||
industry,
|
||||
notes,
|
||||
subscribe,
|
||||
}: Omit<ContactRecord, "id" | "createdAt">): Promise<ContactRecord> {
|
||||
const { id, createdAt } = await prisma.contact.create({
|
||||
data: {
|
||||
firstName,
|
||||
lastName,
|
||||
companyName,
|
||||
address,
|
||||
email,
|
||||
phone,
|
||||
industry,
|
||||
notes,
|
||||
subscribe,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
id,
|
||||
firstName,
|
||||
lastName,
|
||||
companyName,
|
||||
address,
|
||||
email,
|
||||
phone,
|
||||
industry,
|
||||
notes,
|
||||
subscribe,
|
||||
createdAt,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ??
|
||||
new PrismaClient({
|
||||
log: ["error", "warn"],
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
||||
|
||||
export default prisma;
|
||||
Reference in New Issue
Block a user