import { db } from "@/lib/mastoauth/kysely";
import { NextRequest } from "next/server";

export async function GET(request: NextRequest) {
  const until = parseInt(request.nextUrl.searchParams.get("until") || Date.now().toString());
  let users = await db
    .selectFrom('users')
    .where('users.joined', '<', until)
    .limit(20)
    .orderBy('users.joined', 'desc')
    .selectAll()
    .execute();

  if (users == null) return new Response('', {
    status: 500
  });

  return Response.json(users);
}