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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user