27 lines
742 B
TypeScript
27 lines
742 B
TypeScript
import { z } from 'zod';
|
|
import { db } from './db';
|
|
|
|
export const leadSchema = z.object({
|
|
email: z.string().email().max(200),
|
|
name: z.string().max(120).optional().or(z.literal('')),
|
|
message: z.string().max(2000).optional().or(z.literal('')),
|
|
source: z.string().max(60).optional().or(z.literal('')),
|
|
});
|
|
|
|
export type LeadInput = z.infer<typeof leadSchema>;
|
|
|
|
export async function createLead(input: LeadInput) {
|
|
return db.lead.create({
|
|
data: {
|
|
email: input.email.toLowerCase(),
|
|
name: input.name || null,
|
|
message: input.message || null,
|
|
source: input.source || 'contact',
|
|
},
|
|
});
|
|
}
|
|
|
|
export function listLeads(limit = 100) {
|
|
return db.lead.findMany({ orderBy: { createdAt: 'desc' }, take: limit });
|
|
}
|