Files
petvity/lib/domain/email-queue.ts
T
g-butandClaude Sonnet 4.6 ddfb647149 feat: scaffold Petvity — global pet care platform
Full Phase 1 scaffold:
- Next.js 16 + TypeScript strict + Tailwind 4 + Neon/Drizzle + NextAuth 5
- 9-language i18n (EN DE FR ES JA ZH KO TR AR) with RTL support for Arabic
- SSOT config: species (10 types), health metrics (7 KPIs), pet signal system
- DB schema: pets, healthMetrics (unique per pet+day), vaccinations, medications,
  healthRecords, emailQueue
- Numeric storage: weight=grams, temperature=centidegrees (no float drift)
- computePetSignal() — pure domain function, 9 unit tests passing
- API routes: auth, account, pets CRUD, health metrics (upsert), records,
  vaccinations, medications, public pet profiles (no auth)
- Cron: health-alerts, vaccination-reminders, email queue (all Bearer-protected)
- Portal UI: dashboard, pet list, add pet, health tracking, log page, vaccinations
- Public influencer pet profiles at /[locale]/pets/[handle]
- Email templates: welcome sequence, health alert, vaccination reminder

pnpm build ✓  pnpm test ✓ (9/9)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-20 19:19:52 +02:00

43 lines
1.0 KiB
TypeScript

import { getInstance } from "@/lib/db";
import { emailQueue } from "@/lib/db/schema";
import { WELCOME_SEQUENCE } from "@/lib/config/email-sequences";
/**
* Enqueue the welcome email sequence for a new pet owner.
* Emails are scheduled relative to now using WELCOME_SEQUENCE delays.
*/
export async function enqueueWelcomeSequence(
userId: string,
payload: { name: string; email: string },
): Promise<void> {
const db = getInstance();
const now = Date.now();
await db.insert(emailQueue).values([
{
userId,
templateKey: "owner_welcome",
sendAt: new Date(now + WELCOME_SEQUENCE.welcome),
payload,
},
{
userId,
templateKey: "owner_add_pet",
sendAt: new Date(now + WELCOME_SEQUENCE.addPet),
payload,
},
{
userId,
templateKey: "owner_health_tracking",
sendAt: new Date(now + WELCOME_SEQUENCE.healthTracking),
payload,
},
{
userId,
templateKey: "owner_week_one",
sendAt: new Date(now + WELCOME_SEQUENCE.weekOne),
payload,
},
]);
}