fix: support async searchParams for Next.js 16 and bypass locking for admin users
This commit is contained in:
@@ -14,5 +14,6 @@ export async function GET(_: Request, context: { params: Promise<{ id: string }>
|
||||
});
|
||||
if (!ad) return NextResponse.json({ error: "NOT_FOUND" }, { status: 404 });
|
||||
const plan = planFromUser(user as any);
|
||||
return NextResponse.json({ data: maskAdForPlan(ad as any, plan?.code) });
|
||||
const isAdmin = user.role === "ADMIN";
|
||||
return NextResponse.json({ data: maskAdForPlan(ad as any, plan?.code, isAdmin) });
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ export async function GET(req: Request) {
|
||||
thumbnailUrl: ad.creatives[0]?.thumbnailUrl || ad.creatives[0]?.url,
|
||||
isSaved: savedIds.has(ad.id)
|
||||
},
|
||||
plan?.code
|
||||
plan?.code,
|
||||
user.role === "ADMIN"
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
@@ -6,18 +6,20 @@ import { maskAdForPlan } from "@/lib/locked-response";
|
||||
import { planFromUser } from "@/lib/plans";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export default async function AdsPage({ searchParams }: { searchParams: Record<string, string | undefined> }) {
|
||||
export default async function AdsPage({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
|
||||
const user = await requireUser();
|
||||
const plan = planFromUser(user as any);
|
||||
const q = searchParams.q?.trim();
|
||||
const niche = searchParams.niche;
|
||||
const mediaType = searchParams.mediaType;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const q = resolvedSearchParams.q?.trim();
|
||||
const niche = resolvedSearchParams.niche;
|
||||
const mediaType = resolvedSearchParams.mediaType;
|
||||
const where: Prisma.AdWhereInput = {};
|
||||
if (q) where.OR = [{ primaryText: { contains: q, mode: "insensitive" } }, { headline: { contains: q, mode: "insensitive" } }, { brandPage: { name: { contains: q, mode: "insensitive" } } }];
|
||||
if (niche) where.niche = niche;
|
||||
if (mediaType) where.mediaType = mediaType as any;
|
||||
const ads = await prisma.ad.findMany({ where, include: { brandPage: true, creatives: { take: 1 }, savedBy: { where: { userId: user.id } } }, orderBy: { rankPercentile: "asc" }, take: 48 });
|
||||
const masked = ads.map((ad) => maskAdForPlan({ ...ad, isSaved: ad.savedBy.length > 0 }, plan?.code));
|
||||
const isAdmin = user.role === "ADMIN";
|
||||
const masked = ads.map((ad) => maskAdForPlan({ ...ad, isSaved: ad.savedBy.length > 0 }, plan?.code, isAdmin));
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
@@ -4,10 +4,11 @@ import { prisma } from "@/lib/db";
|
||||
import { requireUser } from "@/lib/auth/current-user";
|
||||
import { Card } from "@/components/ui/card";
|
||||
|
||||
export default async function StoresPage({ searchParams }: { searchParams: Record<string, string | undefined> }) {
|
||||
export default async function StoresPage({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
|
||||
await requireUser();
|
||||
const q = searchParams.q?.trim();
|
||||
const niche = searchParams.niche;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const q = resolvedSearchParams.q?.trim();
|
||||
const niche = resolvedSearchParams.niche;
|
||||
const where: Prisma.StoreWhereInput = {};
|
||||
if (q) where.OR = [{ name: { contains: q, mode: "insensitive" } }, { domain: { contains: q, mode: "insensitive" } }];
|
||||
if (niche) where.niche = niche;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { PlanCode } from "@prisma/client";
|
||||
|
||||
export function maskAdForPlan<T extends Record<string, any>>(ad: T, planCode?: PlanCode): T & { isLocked: boolean } {
|
||||
if (planCode && planCode !== "FREE") return { ...ad, isLocked: false };
|
||||
export function maskAdForPlan<T extends Record<string, any>>(ad: T, planCode?: PlanCode, bypassLock?: boolean): T & { isLocked: boolean } {
|
||||
if (bypassLock || (planCode && planCode !== "FREE")) return { ...ad, isLocked: false };
|
||||
return {
|
||||
...ad,
|
||||
primaryText: ad.primaryText ? `${String(ad.primaryText).slice(0, 90)}...` : null,
|
||||
|
||||
Reference in New Issue
Block a user