templates2.Landing.Nuxt/server/utils/leads.ts
w4c-templates b41099ee06
Some checks failed
CI / quality (push) Has been cancelled
chore(template): publish Landing.Nuxt
2026-10-11 23:24:06 +03:00

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 });
}