Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 473868579b | |||
| 4a0dd5ed2a | |||
| bf064b3ada | |||
| 4df7d96020 |
+4
-9
@@ -1,7 +1,5 @@
|
|||||||
FROM node:22-alpine AS base
|
FROM node:22-alpine AS base
|
||||||
RUN corepack enable && corepack install -g pnpm@9.15.4
|
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
|
||||||
ENV COREPACK_ENABLE_STRICT=0
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Install deps
|
# Install deps
|
||||||
@@ -13,6 +11,7 @@ RUN pnpm install --frozen-lockfile
|
|||||||
|
|
||||||
# Build
|
# Build
|
||||||
FROM deps AS builder
|
FROM deps AS builder
|
||||||
|
RUN mkdir -p /home/node/.cache/node/corepack
|
||||||
COPY packages/ packages/
|
COPY packages/ packages/
|
||||||
COPY src/ src/
|
COPY src/ src/
|
||||||
COPY tsconfig.json ./
|
COPY tsconfig.json ./
|
||||||
@@ -22,9 +21,7 @@ RUN pnpm --filter @groombook/types build && \
|
|||||||
|
|
||||||
# Runtime
|
# Runtime
|
||||||
FROM node:22-alpine AS runner
|
FROM node:22-alpine AS runner
|
||||||
RUN corepack enable && corepack install -g pnpm@9.15.4
|
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
|
||||||
ENV COREPACK_ENABLE_STRICT=0
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
@@ -53,7 +50,5 @@ CMD ["pnpm", "--filter", "@groombook/db", "seed"]
|
|||||||
|
|
||||||
# Reset stage — drops all tables, re-runs migrations, and re-seeds
|
# Reset stage — drops all tables, re-runs migrations, and re-seeds
|
||||||
FROM builder AS reset
|
FROM builder AS reset
|
||||||
RUN corepack enable && corepack install -g pnpm@9.15.4
|
RUN corepack enable && corepack prepare pnpm@9.15.4 --activate
|
||||||
ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
|
||||||
ENV COREPACK_ENABLE_STRICT=0
|
|
||||||
CMD ["pnpm", "--filter", "@groombook/db", "reset"]
|
CMD ["pnpm", "--filter", "@groombook/db", "reset"]
|
||||||
|
|||||||
+1
-113
@@ -1,19 +1,7 @@
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { zValidator } from "@hono/zod-validator";
|
import { zValidator } from "@hono/zod-validator";
|
||||||
import { z } from "zod/v3";
|
import { z } from "zod/v3";
|
||||||
import {
|
import { and, eq, exists, getDb, or, pets, appointments } from "@groombook/db";
|
||||||
and,
|
|
||||||
desc,
|
|
||||||
eq,
|
|
||||||
exists,
|
|
||||||
getDb,
|
|
||||||
or,
|
|
||||||
pets,
|
|
||||||
appointments,
|
|
||||||
staff,
|
|
||||||
services,
|
|
||||||
sql,
|
|
||||||
} from "@groombook/db";
|
|
||||||
import type { AppEnv } from "../middleware/rbac.js";
|
import type { AppEnv } from "../middleware/rbac.js";
|
||||||
import {
|
import {
|
||||||
getPresignedUploadUrl,
|
getPresignedUploadUrl,
|
||||||
@@ -109,106 +97,6 @@ petsRouter.get("/:id", async (c) => {
|
|||||||
return c.json(row);
|
return c.json(row);
|
||||||
});
|
});
|
||||||
|
|
||||||
petsRouter.get("/:id/profile-summary", async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const petId = c.req.param("id");
|
|
||||||
const staffRow = c.get("staff");
|
|
||||||
const isGroomer = staffRow?.role === "groomer";
|
|
||||||
|
|
||||||
// Fetch the pet
|
|
||||||
const [pet] = await db.select().from(pets).where(eq(pets.id, petId));
|
|
||||||
if (!pet) return c.json({ error: "Not found" }, 404);
|
|
||||||
|
|
||||||
// Groomer RBAC: check appointment linkage to this pet's client
|
|
||||||
if (isGroomer) {
|
|
||||||
const [linkage] = await db
|
|
||||||
.select({ id: appointments.id })
|
|
||||||
.from(appointments)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(appointments.clientId, pet.clientId),
|
|
||||||
or(
|
|
||||||
eq(appointments.staffId, staffRow.id),
|
|
||||||
eq(appointments.batherStaffId, staffRow.id)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
if (!linkage) return c.json({ error: "Forbidden" }, 403);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recent grooming history — last 10 completed appointments
|
|
||||||
const recentHistory = await db
|
|
||||||
.select({
|
|
||||||
id: appointments.id,
|
|
||||||
startTime: appointments.startTime,
|
|
||||||
notes: appointments.notes,
|
|
||||||
serviceName: services.name,
|
|
||||||
staffName: staff.name,
|
|
||||||
})
|
|
||||||
.from(appointments)
|
|
||||||
.innerJoin(services, eq(appointments.serviceId, services.id))
|
|
||||||
.leftJoin(staff, eq(appointments.staffId, staff.id))
|
|
||||||
.where(and(eq(appointments.petId, petId), eq(appointments.status, "completed")))
|
|
||||||
.orderBy(desc(appointments.startTime))
|
|
||||||
.limit(10);
|
|
||||||
|
|
||||||
// Visit count (completed appointments)
|
|
||||||
const [countRow] = await db
|
|
||||||
.select({ count: sql<number>`count(*)::int` })
|
|
||||||
.from(appointments)
|
|
||||||
.where(and(eq(appointments.petId, petId), eq(appointments.status, "completed")));
|
|
||||||
const visitCount = countRow?.count ?? 0;
|
|
||||||
|
|
||||||
// Upcoming appointment (next scheduled or confirmed)
|
|
||||||
const [upcoming] = await db
|
|
||||||
.select({
|
|
||||||
id: appointments.id,
|
|
||||||
startTime: appointments.startTime,
|
|
||||||
notes: appointments.notes,
|
|
||||||
confirmationStatus: appointments.confirmationStatus,
|
|
||||||
serviceName: services.name,
|
|
||||||
})
|
|
||||||
.from(appointments)
|
|
||||||
.innerJoin(services, eq(appointments.serviceId, services.id))
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(appointments.petId, petId),
|
|
||||||
or(eq(appointments.status, "scheduled"), eq(appointments.status, "confirmed"))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.orderBy(appointments.startTime)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
return c.json({
|
|
||||||
id: pet.id,
|
|
||||||
name: pet.name,
|
|
||||||
species: pet.species,
|
|
||||||
breed: pet.breed,
|
|
||||||
coatType: pet.coatType,
|
|
||||||
petSizeCategory: pet.petSizeCategory,
|
|
||||||
weightKg: pet.weightKg,
|
|
||||||
dateOfBirth: pet.dateOfBirth,
|
|
||||||
recentGroomingHistory: recentHistory.map((h) => ({
|
|
||||||
id: h.id,
|
|
||||||
startTime: h.startTime,
|
|
||||||
notes: h.notes,
|
|
||||||
serviceName: h.serviceName,
|
|
||||||
staffName: h.staffName,
|
|
||||||
})),
|
|
||||||
visitCount,
|
|
||||||
upcomingAppointment: upcoming
|
|
||||||
? {
|
|
||||||
id: upcoming.id,
|
|
||||||
startTime: upcoming.startTime,
|
|
||||||
notes: upcoming.notes,
|
|
||||||
confirmationStatus: upcoming.confirmationStatus,
|
|
||||||
serviceName: upcoming.serviceName,
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
petsRouter.post("/", zValidator("json", createPetSchema), async (c) => {
|
petsRouter.post("/", zValidator("json", createPetSchema), async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const { weightKg, dateOfBirth, customFields, ...rest } = c.req.valid("json");
|
const { weightKg, dateOfBirth, customFields, ...rest } = c.req.valid("json");
|
||||||
|
|||||||
Reference in New Issue
Block a user