Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 10c33513eb | |||
| 6045024150 | |||
| df5e413930 | |||
| 7cb5fda3e3 | |||
| 76540cea0d | |||
| d83210e7e2 | |||
| 5c9cac7a28 | |||
| fad99dc032 | |||
| 247570abc8 | |||
| 4f5ec60961 | |||
| 39ffdccac7 | |||
| 1ff0d4230c | |||
| be5e9d8fc7 |
@@ -2,7 +2,6 @@ import { describe, it, expect, vi, beforeEach } from "vitest";
|
|||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import type { AppEnv, StaffRow } from "../middleware/rbac.js";
|
import type { AppEnv, StaffRow } from "../middleware/rbac.js";
|
||||||
import { petsRouter } from "../routes/pets.js";
|
import { petsRouter } from "../routes/pets.js";
|
||||||
import { and, eq, exists, or } from "../db/index.js";
|
|
||||||
|
|
||||||
// ─── Mock staff fixtures ──────────────────────────────────────────────────────
|
// ─── Mock staff fixtures ──────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -165,10 +164,10 @@ vi.mock("../db", async (importOriginal) => {
|
|||||||
}),
|
}),
|
||||||
pets,
|
pets,
|
||||||
appointments,
|
appointments,
|
||||||
and: db.and,
|
and: (...conds: unknown[]) => conds,
|
||||||
eq: db.eq,
|
eq: (col: unknown, val: unknown) => ({ col, val }),
|
||||||
exists: db.exists,
|
exists: (q: unknown) => q,
|
||||||
or: db.or,
|
or: (...conds: unknown[]) => conds,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import { getDb, businessSettings, eq, staff } from "./db/index.js";
|
|||||||
import { authMiddleware } from "./middleware/auth.js";
|
import { authMiddleware } from "./middleware/auth.js";
|
||||||
import { resolveStaffMiddleware, requireRole, requireRoleOrSuperUser, requireSuperUser } from "./middleware/rbac.js";
|
import { resolveStaffMiddleware, requireRole, requireRoleOrSuperUser, requireSuperUser } from "./middleware/rbac.js";
|
||||||
import { devRouter } from "./routes/dev.js";
|
import { devRouter } from "./routes/dev.js";
|
||||||
import { bufferRulesRouter } from "./routes/buffer-rules.js";
|
|
||||||
import { adminSeedRouter } from "./routes/admin/seed.js";
|
import { adminSeedRouter } from "./routes/admin/seed.js";
|
||||||
import { startReminderScheduler } from "./services/reminders.js";
|
import { startReminderScheduler } from "./services/reminders.js";
|
||||||
import { webhooksRouter } from "./routes/stripe-webhooks.js";
|
import { webhooksRouter } from "./routes/stripe-webhooks.js";
|
||||||
@@ -212,7 +211,6 @@ api.on(["GET"], "/staff/*", requireRole("manager", "receptionist", "groomer"));
|
|||||||
// Staff write routes: manager OR super-user (combined guard — avoids AND stacking)
|
// Staff write routes: manager OR super-user (combined guard — avoids AND stacking)
|
||||||
api.on(["POST", "PATCH", "DELETE"], "/staff/*", requireRoleOrSuperUser("manager"));
|
api.on(["POST", "PATCH", "DELETE"], "/staff/*", requireRoleOrSuperUser("manager"));
|
||||||
api.use("/admin/*", requireRoleOrSuperUser("manager"));
|
api.use("/admin/*", requireRoleOrSuperUser("manager"));
|
||||||
api.use("/buffer-rules/*", requireRole("manager"));
|
|
||||||
api.use("/admin/settings/*", requireSuperUser());
|
api.use("/admin/settings/*", requireSuperUser());
|
||||||
api.use("/reports/*", requireRole("manager"));
|
api.use("/reports/*", requireRole("manager"));
|
||||||
api.use("/invoices/*", requireRole("manager", "groomer"));
|
api.use("/invoices/*", requireRole("manager", "groomer"));
|
||||||
@@ -270,7 +268,6 @@ api.route("/impersonation", impersonationRouter);
|
|||||||
api.route("/admin/settings", settingsRouter);
|
api.route("/admin/settings", settingsRouter);
|
||||||
api.route("/admin/auth-provider", authProviderRouter);
|
api.route("/admin/auth-provider", authProviderRouter);
|
||||||
api.route("/admin/seed", adminSeedRouter);
|
api.route("/admin/seed", adminSeedRouter);
|
||||||
api.route("/buffer-rules", bufferRulesRouter);
|
|
||||||
api.route("/search", searchRouter);
|
api.route("/search", searchRouter);
|
||||||
|
|
||||||
const port = Number(process.env.PORT ?? 3000);
|
const port = Number(process.env.PORT ?? 3000);
|
||||||
|
|||||||
@@ -1,124 +0,0 @@
|
|||||||
import { Hono } from "hono";
|
|
||||||
import { zValidator } from "@hono/zod-validator";
|
|
||||||
import { z } from "zod/v3";
|
|
||||||
import { and, eq, getDb, isNull } from "../db/index.js";
|
|
||||||
import type { AppEnv } from "../middleware/rbac.js";
|
|
||||||
import { bufferRules, services } from "../db/index.js";
|
|
||||||
|
|
||||||
export const bufferRulesRouter = new Hono<AppEnv>();
|
|
||||||
|
|
||||||
const createBufferRuleSchema = z.object({
|
|
||||||
serviceId: z.string().uuid(),
|
|
||||||
sizeCategory: z
|
|
||||||
.enum(["small", "medium", "large", "extra_large"])
|
|
||||||
.optional(),
|
|
||||||
coatType: z
|
|
||||||
.enum(["short", "medium", "long", "double", "wire", "silky", "curly", "hairless"])
|
|
||||||
.optional(),
|
|
||||||
bufferMinutes: z.number().int().positive(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const updateBufferRuleSchema = z.object({
|
|
||||||
bufferMinutes: z.number().int().positive(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// GET / — list all buffer rules, optionally filtered by serviceId
|
|
||||||
bufferRulesRouter.get("/", async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const serviceId = c.req.query("serviceId");
|
|
||||||
|
|
||||||
const conditions = [];
|
|
||||||
if (serviceId) conditions.push(eq(bufferRules.serviceId, serviceId));
|
|
||||||
|
|
||||||
const rows = await db
|
|
||||||
.select({
|
|
||||||
id: bufferRules.id,
|
|
||||||
serviceId: bufferRules.serviceId,
|
|
||||||
sizeCategory: bufferRules.sizeCategory,
|
|
||||||
coatType: bufferRules.coatType,
|
|
||||||
bufferMinutes: bufferRules.bufferMinutes,
|
|
||||||
createdAt: bufferRules.createdAt,
|
|
||||||
updatedAt: bufferRules.updatedAt,
|
|
||||||
serviceName: services.name,
|
|
||||||
})
|
|
||||||
.from(bufferRules)
|
|
||||||
.innerJoin(services, eq(bufferRules.serviceId, services.id))
|
|
||||||
.where(conditions.length > 0 ? and(...conditions) : undefined)
|
|
||||||
.orderBy(bufferRules.createdAt);
|
|
||||||
|
|
||||||
return c.json(rows);
|
|
||||||
});
|
|
||||||
|
|
||||||
// POST / — create a buffer rule
|
|
||||||
bufferRulesRouter.post(
|
|
||||||
"/",
|
|
||||||
zValidator("json", createBufferRuleSchema),
|
|
||||||
async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const body = c.req.valid("json");
|
|
||||||
|
|
||||||
// Validate serviceId exists
|
|
||||||
const [svc] = await db
|
|
||||||
.select({ id: services.id })
|
|
||||||
.from(services)
|
|
||||||
.where(eq(services.id, body.serviceId));
|
|
||||||
if (!svc) return c.json({ error: "Service not found" }, 404);
|
|
||||||
|
|
||||||
// Check for duplicate (service + size + coat)
|
|
||||||
const [existing] = await db
|
|
||||||
.select({ id: bufferRules.id })
|
|
||||||
.from(bufferRules)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(bufferRules.serviceId, body.serviceId),
|
|
||||||
body.sizeCategory !== undefined
|
|
||||||
? eq(bufferRules.sizeCategory, body.sizeCategory)
|
|
||||||
: isNull(bufferRules.sizeCategory),
|
|
||||||
body.coatType !== undefined
|
|
||||||
? eq(bufferRules.coatType, body.coatType)
|
|
||||||
: isNull(bufferRules.coatType)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (existing) return c.json({ error: "Duplicate rule for this service+size+coat combination" }, 409);
|
|
||||||
|
|
||||||
const [row] = await db
|
|
||||||
.insert(bufferRules)
|
|
||||||
.values({
|
|
||||||
serviceId: body.serviceId,
|
|
||||||
sizeCategory: body.sizeCategory ?? null,
|
|
||||||
coatType: body.coatType ?? null,
|
|
||||||
bufferMinutes: body.bufferMinutes,
|
|
||||||
})
|
|
||||||
.returning();
|
|
||||||
|
|
||||||
return c.json(row, 201);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// PATCH /:id — update bufferMinutes only
|
|
||||||
bufferRulesRouter.patch(
|
|
||||||
"/:id",
|
|
||||||
zValidator("json", updateBufferRuleSchema),
|
|
||||||
async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const body = c.req.valid("json");
|
|
||||||
const [row] = await db
|
|
||||||
.update(bufferRules)
|
|
||||||
.set({ bufferMinutes: body.bufferMinutes, updatedAt: new Date() })
|
|
||||||
.where(eq(bufferRules.id, c.req.param("id")))
|
|
||||||
.returning();
|
|
||||||
if (!row) return c.json({ error: "Not found" }, 404);
|
|
||||||
return c.json(row);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// DELETE /:id — delete a buffer rule
|
|
||||||
bufferRulesRouter.delete("/:id", async (c) => {
|
|
||||||
const db = getDb();
|
|
||||||
const [row] = await db
|
|
||||||
.delete(bufferRules)
|
|
||||||
.where(eq(bufferRules.id, c.req.param("id")))
|
|
||||||
.returning();
|
|
||||||
if (!row) return c.json({ error: "Not found" }, 404);
|
|
||||||
return c.json({ ok: true });
|
|
||||||
});
|
|
||||||
@@ -24,7 +24,6 @@ const createPetSchema = z.object({
|
|||||||
shampooPreference: z.string().max(500).optional(),
|
shampooPreference: z.string().max(500).optional(),
|
||||||
specialCareNotes: z.string().max(2000).optional(),
|
specialCareNotes: z.string().max(2000).optional(),
|
||||||
customFields: z.record(z.string(), z.string()).optional(),
|
customFields: z.record(z.string(), z.string()).optional(),
|
||||||
sizeCategory: z.enum(["small", "medium", "large", "extra_large"]).optional(),
|
|
||||||
coatType: z.enum(["short", "medium", "long", "double", "wire", "silky", "curly", "hairless"]).optional(),
|
coatType: z.enum(["short", "medium", "long", "double", "wire", "silky", "curly", "hairless"]).optional(),
|
||||||
temperamentScore: z.number().int().min(1).max(5).optional(),
|
temperamentScore: z.number().int().min(1).max(5).optional(),
|
||||||
temperamentFlags: z.array(z.string().max(100)).max(20).optional(),
|
temperamentFlags: z.array(z.string().max(100)).max(20).optional(),
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ const createServiceSchema = z.object({
|
|||||||
active: z.boolean().default(true),
|
active: z.boolean().default(true),
|
||||||
});
|
});
|
||||||
|
|
||||||
const updateServiceSchema = createServiceSchema.partial().extend({
|
const updateServiceSchema = createServiceSchema.partial();
|
||||||
defaultBufferMinutes: z.number().int().min(0).optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
servicesRouter.get("/", async (c) => {
|
servicesRouter.get("/", async (c) => {
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
|
|||||||
@@ -26,19 +26,6 @@ export interface Client {
|
|||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Medical Alerts ────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export type AlertSeverity = "low" | "medium" | "high";
|
|
||||||
|
|
||||||
export interface MedicalAlert {
|
|
||||||
type: string;
|
|
||||||
description: string;
|
|
||||||
severity: AlertSeverity;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Pet Profile Summary ────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export type CoatType = "short" | "medium" | "long" | "double" | "wire" | "silky" | "curly" | "hairless";
|
|
||||||
export interface Pet {
|
export interface Pet {
|
||||||
id: string;
|
id: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
|
|||||||
@@ -116,26 +116,6 @@ export const verification = pgTable("verification", {
|
|||||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── Pet enums ─────────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export const petSizeCategoryEnum = pgEnum("pet_size_category", [
|
|
||||||
"small",
|
|
||||||
"medium",
|
|
||||||
"large",
|
|
||||||
"extra_large",
|
|
||||||
]);
|
|
||||||
|
|
||||||
export const coatTypeEnum = pgEnum("coat_type", [
|
|
||||||
"short",
|
|
||||||
"medium",
|
|
||||||
"long",
|
|
||||||
"double",
|
|
||||||
"wire",
|
|
||||||
"silky",
|
|
||||||
"curly",
|
|
||||||
"hairless",
|
|
||||||
]);
|
|
||||||
|
|
||||||
// ─── Tables ───────────────────────────────────────────────────────────────────
|
// ─── Tables ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const clients = pgTable(
|
export const clients = pgTable(
|
||||||
@@ -198,7 +178,6 @@ export const services = pgTable("services", {
|
|||||||
durationMinutes: integer("duration_minutes").notNull(),
|
durationMinutes: integer("duration_minutes").notNull(),
|
||||||
defaultBufferMinutes: integer("default_buffer_minutes"),
|
defaultBufferMinutes: integer("default_buffer_minutes"),
|
||||||
active: boolean("active").notNull().default(true),
|
active: boolean("active").notNull().default(true),
|
||||||
defaultBufferMinutes: integer("default_buffer_minutes").notNull().default(0),
|
|
||||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||||
});
|
});
|
||||||
@@ -661,34 +640,3 @@ export const authProviderConfig = pgTable("auth_provider_config", {
|
|||||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// ─── Buffer Rules ─────────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
// Buffer time rules per service + pet size/coat combination.
|
|
||||||
// Covers service-level defaults and pet-specific overrides.
|
|
||||||
export const bufferRules = pgTable(
|
|
||||||
"buffer_rules",
|
|
||||||
{
|
|
||||||
id: uuid("id").primaryKey().defaultRandom(),
|
|
||||||
serviceId: uuid("service_id")
|
|
||||||
.notNull()
|
|
||||||
.references(() => services.id, { onDelete: "cascade" }),
|
|
||||||
// null sizeCategory means "any size" (wildcard)
|
|
||||||
sizeCategory: petSizeCategoryEnum("size_category"),
|
|
||||||
// null coatType means "any coat type" (wildcard)
|
|
||||||
coatType: coatTypeEnum("coat_type"),
|
|
||||||
// minutes to add to the service duration for this size/coat combo
|
|
||||||
bufferMinutes: integer("buffer_minutes").notNull(),
|
|
||||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
||||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
||||||
},
|
|
||||||
(t) => [
|
|
||||||
// One rule per unique (service, size, coat) combination
|
|
||||||
unique("uq_buffer_rules_service_size_coat").on(
|
|
||||||
t.serviceId,
|
|
||||||
t.sizeCategory,
|
|
||||||
t.coatType
|
|
||||||
),
|
|
||||||
index("idx_buffer_rules_service_id").on(t.serviceId),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -251,6 +251,10 @@ export async function initAuth(): Promise<void> {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
account: {
|
account: {
|
||||||
|
accountLinking: {
|
||||||
|
enabled: true,
|
||||||
|
trustedProviders: ["authentik"],
|
||||||
|
},
|
||||||
storeStateStrategy: "cookie" as const,
|
storeStateStrategy: "cookie" as const,
|
||||||
},
|
},
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
|
|||||||
Reference in New Issue
Block a user