diff --git a/apps/api/src/routes/admin/seed.ts b/apps/api/src/routes/admin/seed.ts index 1220991..4458811 100644 --- a/apps/api/src/routes/admin/seed.ts +++ b/apps/api/src/routes/admin/seed.ts @@ -36,6 +36,19 @@ const DEMO_PET = { weightKg: "30.00", }; +const UAT_CLIENT = { + name: "UAT Customer", + email: "uat-customer@groombook.dev", + phone: "555-0100", + address: "1 UAT Lane, Test City, CA 90210", + status: "active" as const, +}; + +const UAT_PETS = [ + { name: "Bella", species: "Dog", breed: "Poodle", coatType: "curly", weightKg: "20.00" }, + { name: "Max", species: "Dog", breed: "Labrador Retriever", coatType: "short", weightKg: "30.00" }, +]; + const DEMO_SERVICES = [ { id: "b0000001-0000-0000-0000-000000000001", name: "Bath & Brush", description: "Full bath, blow-dry, brush out, and ear cleaning", basePriceCents: 4500, durationMinutes: 45 }, { id: "b0000001-0000-0000-0000-000000000002", name: "Full Groom — Small", description: "Complete grooming for dogs under 25 lbs", basePriceCents: 6500, durationMinutes: 60 }, @@ -43,7 +56,7 @@ const DEMO_SERVICES = [ { id: "b0000001-0000-0000-0000-000000000004", name: "Nail Trim", description: "Nail clipping and filing", basePriceCents: 1500, durationMinutes: 15 }, ]; -adminSeedRouter.post("/seed", async (c) => { +adminSeedRouter.post("/", async (c) => { // Refuse to run when AUTH_DISABLED — dev environments use direct-DB seeding if (process.env.AUTH_DISABLED === "true") { return c.json( @@ -128,6 +141,51 @@ adminSeedRouter.post("/seed", async (c) => { results.push(`Created pet '${DEMO_PET.name}' for Demo Client (id: ${created!.id})`); } + // ── Client: UAT Customer ────────────────────────────────────────────────── + const [existingUatClient] = await db + .select() + .from(clients) + .where(eq(clients.email, UAT_CLIENT.email)); + + let uatClientId: string; + if (existingUatClient) { + uatClientId = existingUatClient.id; + results.push(`Client '${UAT_CLIENT.name}' already exists (id: ${uatClientId})`); + } else { + const [created] = await db.insert(clients).values(UAT_CLIENT).returning(); + uatClientId = created!.id; + results.push(`Created client '${UAT_CLIENT.name}' (id: ${uatClientId})`); + } + + // ── Pets: UAT Customer's Pets ───────────────────────────────────────────── + const existingUatPets = await db + .select() + .from(pets) + .where(eq(pets.clientId, uatClientId)); + + for (const uatPet of UAT_PETS) { + const existing = existingUatPets.find( + (p) => p.name === uatPet.name && p.species === uatPet.species + ); + if (existing) { + results.push(`Pet '${uatPet.name}' already exists for UAT Customer (id: ${existing.id})`); + } else { + const [created] = await db + .insert(pets) + .values({ + clientId: uatClientId, + name: uatPet.name, + species: uatPet.species, + breed: uatPet.breed, + coatType: uatPet.coatType as any, + weightKg: uatPet.weightKg, + dateOfBirth: new Date("2019-01-01T00:00:00Z"), + }) + .returning(); + results.push(`Created pet '${uatPet.name}' for UAT Customer (id: ${created!.id})`); + } + } + return c.json({ message: "Seed complete", details: results, diff --git a/src/routes/admin/seed.ts b/src/routes/admin/seed.ts index efd461e..114461f 100644 --- a/src/routes/admin/seed.ts +++ b/src/routes/admin/seed.ts @@ -36,6 +36,19 @@ const DEMO_PET = { weightKg: "30.00", }; +const UAT_CLIENT = { + name: "UAT Customer", + email: "uat-customer@groombook.dev", + phone: "555-0100", + address: "1 UAT Lane, Test City, CA 90210", + status: "active" as const, +}; + +const UAT_PETS = [ + { name: "Bella", species: "Dog", breed: "Poodle", coatType: "curly", weightKg: "20.00" }, + { name: "Max", species: "Dog", breed: "Labrador Retriever", coatType: "short", weightKg: "30.00" }, +]; + const DEMO_SERVICES = [ { id: "b0000001-0000-0000-0000-000000000001", name: "Bath & Brush", description: "Full bath, blow-dry, brush out, and ear cleaning", basePriceCents: 4500, durationMinutes: 45 }, { id: "b0000001-0000-0000-0000-000000000002", name: "Full Groom — Small", description: "Complete grooming for dogs under 25 lbs", basePriceCents: 6500, durationMinutes: 60 }, @@ -43,7 +56,7 @@ const DEMO_SERVICES = [ { id: "b0000001-0000-0000-0000-000000000004", name: "Nail Trim", description: "Nail clipping and filing", basePriceCents: 1500, durationMinutes: 15 }, ]; -adminSeedRouter.post("/seed", async (c) => { +adminSeedRouter.post("/", async (c) => { // Refuse to run when AUTH_DISABLED — dev environments use direct-DB seeding if (process.env.AUTH_DISABLED === "true") { return c.json( @@ -128,6 +141,51 @@ adminSeedRouter.post("/seed", async (c) => { results.push(`Created pet '${DEMO_PET.name}' for Demo Client (id: ${created!.id})`); } + // ── Client: UAT Customer ────────────────────────────────────────────────── + const [existingUatClient] = await db + .select() + .from(clients) + .where(eq(clients.email, UAT_CLIENT.email)); + + let uatClientId: string; + if (existingUatClient) { + uatClientId = existingUatClient.id; + results.push(`Client '${UAT_CLIENT.name}' already exists (id: ${uatClientId})`); + } else { + const [created] = await db.insert(clients).values(UAT_CLIENT).returning(); + uatClientId = created!.id; + results.push(`Created client '${UAT_CLIENT.name}' (id: ${uatClientId})`); + } + + // ── Pets: UAT Customer's Pets ───────────────────────────────────────────── + const existingUatPets = await db + .select() + .from(pets) + .where(eq(pets.clientId, uatClientId)); + + for (const uatPet of UAT_PETS) { + const existing = existingUatPets.find( + (p) => p.name === uatPet.name && p.species === uatPet.species + ); + if (existing) { + results.push(`Pet '${uatPet.name}' already exists for UAT Customer (id: ${existing.id})`); + } else { + const [created] = await db + .insert(pets) + .values({ + clientId: uatClientId, + name: uatPet.name, + species: uatPet.species, + breed: uatPet.breed, + coatType: uatPet.coatType as any, + weightKg: uatPet.weightKg, + dateOfBirth: new Date("2019-01-01T00:00:00Z"), + }) + .returning(); + results.push(`Created pet '${uatPet.name}' for UAT Customer (id: ${created!.id})`); + } + } + return c.json({ message: "Seed complete", details: results,