feat(GRO-1171): add Admin API — Buffer Rules CRUD + service/pet updates
- Add buffer_rules table with serviceId/sizeCategory/coatType/bufferMinutes
- Add petSizeCategoryEnum (small/medium/large/extra_large) and coatTypeEnum
to schema; update pets table columns to use the typed enums
- Add defaultBufferMinutes to services table
- Add apps/api/src/routes/buffer-rules.ts with GET/POST/PATCH/DELETE,
all manager-only via requireRole("manager")
- Register /api/buffer-rules router in index.ts
- PATCH /api/services/:id accepts optional defaultBufferMinutes
- POST/PATCH /api/pets accepts optional sizeCategory and coatType
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -116,6 +116,26 @@ export const verification = pgTable("verification", {
|
||||
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 ───────────────────────────────────────────────────────────────────
|
||||
|
||||
export const clients = pgTable(
|
||||
@@ -178,6 +198,7 @@ export const services = pgTable("services", {
|
||||
durationMinutes: integer("duration_minutes").notNull(),
|
||||
defaultBufferMinutes: integer("default_buffer_minutes"),
|
||||
active: boolean("active").notNull().default(true),
|
||||
defaultBufferMinutes: integer("default_buffer_minutes").notNull().default(0),
|
||||
createdAt: timestamp("created_at").notNull().defaultNow(),
|
||||
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
||||
});
|
||||
@@ -640,3 +661,34 @@ export const authProviderConfig = pgTable("auth_provider_config", {
|
||||
createdAt: timestamp("created_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),
|
||||
]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user