feat(api): tokens on all routes; items expose claims/claimedQuantity/remainingQuantity

This commit is contained in:
belisards
2026-05-03 16:25:19 -03:00
parent 844951c832
commit e518e28957
12 changed files with 139 additions and 214 deletions

View File

@@ -1,12 +1,19 @@
import { NextRequest, NextResponse } from 'next/server';
import { eq } from 'drizzle-orm';
import { db, wishlists } from '@/lib/db';
import { getGuestFromRequest, verifyAdminToken } from '@/lib/auth/tokens';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ slug: string }> }
) {
try {
const isAdmin = verifyAdminToken(request);
const guest = await getGuestFromRequest(request);
if (!isAdmin && !guest) {
return NextResponse.json({ error: 'Convite necessário' }, { status: 401 });
}
const { slug } = await params;
const wishlist = await db
@@ -22,8 +29,8 @@ export async function GET(
);
}
// Only return public wishlists
if (!wishlist[0].isPublic) {
// Only return public wishlists (admin can see all)
if (!wishlist[0].isPublic && !isAdmin) {
return NextResponse.json(
{ error: 'Wishlist not found' },
{ status: 404 }