feat: add unlimited option to tier limits

Use -1 as a sentinel meaning "no cap" in tier_definitions numeric
columns. checkAndIncrementTierLimit skips the usage-cap WHERE clause
when the limit is -1. Admin tier UI gets an Unlimited switch per
field that disables the input and sends -1.
This commit is contained in:
Arnaud
2026-07-03 20:19:43 +02:00
parent 487e7755be
commit 9412529120
3 changed files with 58 additions and 17 deletions
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import { requireAdmin } from "@/lib/api-auth";
import { db, tierDefinitions, auditLogs, eq } from "@epicure/db";
import { randomUUID } from "crypto";
import { UNLIMITED } from "@/lib/tiers";
interface RouteContext {
params: Promise<{ tier: string }>;
@@ -25,7 +26,7 @@ export async function PATCH(req: NextRequest, { params }: RouteContext) {
for (const field of NUMERIC_FIELDS) {
const value = body[field];
if (value === undefined) continue;
if (!Number.isInteger(value) || value < 0) {
if (!Number.isInteger(value) || (value < 0 && value !== UNLIMITED)) {
return NextResponse.json({ error: `Invalid value for ${field}` }, { status: 400 });
}
updateData[field] = value;