feat(clients): reactivate an expired client review link
Deploy / deploy (push) Successful in 3m16s

Expired links on the client page get a Reactivate button (7-90 days).
PATCH /api/review-sessions pushes the expiry out and turns the link back
on with the same token, so the URL the client already has works again.
Staff roles only, as for creating a link.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-09-25 05:38:42 +02:00
parent 390d7a21ac
commit 824695ef30
2 changed files with 96 additions and 1 deletions
+34
View File
@@ -73,6 +73,40 @@ export async function POST(req: NextRequest) {
return NextResponse.json({ session: reviewSession, portalUrl }, { status: 201 });
}
/**
* Reactivate a review link: push its expiry `expiresInDays` from now and turn
* it back on. The token is unchanged, so a URL the client already has works
* again rather than a new one having to be sent.
*/
export async function PATCH(req: NextRequest) {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role as string)) {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}
const id = req.nextUrl.searchParams.get("id");
if (!id) return NextResponse.json({ error: "id required" }, { status: 400 });
const body = await req.json().catch(() => ({}));
const expiresInDays = Number(body.expiresInDays ?? 30);
if (!Number.isInteger(expiresInDays) || expiresInDays < 1 || expiresInDays > 365) {
return NextResponse.json({ error: "expiresInDays must be 1–365" }, { status: 400 });
}
const existing = await db.reviewSession.findUnique({ where: { id }, select: { id: true } });
if (!existing) return NextResponse.json({ error: "Review link not found" }, { status: 404 });
const reviewSession = await db.reviewSession.update({
where: { id },
data: { expiresAt: addDays(new Date(), expiresInDays), isActive: true },
});
return NextResponse.json({ session: reviewSession });
}
export async function DELETE(req: NextRequest) {
const session = await auth();
if (!session?.user) {