Skip to content

Commit 531e5ee

Browse files
[Penify]: Documentation for commit - fdcc926
1 parent 8bb0fcc commit 531e5ee

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

next-app/app/api/consent/route.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import { appendConsentEvent, exportConsent } from '@/lib/privacy/consentLedger';
33

44
export const runtime = 'nodejs';
55

6+
/**
7+
* Handles POST requests to process user consent actions.
8+
*
9+
* This function extracts the userId, sessionId, and action from the request body.
10+
* It validates the action against a predefined list and returns a 400 response for invalid actions.
11+
* If the action is valid, it appends a consent event using the appendConsentEvent function and returns the result as a JSON response.
12+
*
13+
* @param req - The NextRequest object containing the request data.
14+
*/
615
export async function POST(req: NextRequest) {
716
const { userId = 'demo', sessionId, action } = await req.json();
817
if (!['persist_on','persist_off','export'].includes(action)) return new Response('bad action', { status: 400 });
918
const ev = await appendConsentEvent({ userId, sessionId, action, ts: new Date().toISOString() as any });
1019
return Response.json(ev);
1120
}
1221

22+
/**
23+
* Handles GET requests and returns consent data for a user.
24+
*/
1325
export async function GET(req: NextRequest) {
1426
const { searchParams } = new URL(req.url);
1527
const userId = searchParams.get('userId') ?? 'demo';

0 commit comments

Comments
 (0)