import type { APIRoute } from 'astro';
import { query } from '../../../lib/db';

export const GET: APIRoute = async ({ request, redirect }) => {
  const url = new URL(request.url);
  const uid = url.searchParams.get('uid');
  if (uid) {
    await query('UPDATE users SET unsubscribed = true WHERE id = $1', [uid]);
  }
  return redirect('/?unsubscribed=1');
};
