import { NextApiRequest } from "next";

export default function queryToURLSearchParams(req: NextApiRequest): URLSearchParams {
    const queryEntries = Object.entries(req.query);
    const searchParams = new URLSearchParams();
    for (const [key, value] of queryEntries) {
        if (Array.isArray(value)) {
            value.forEach(v => searchParams.append(key, v));
        } else if (value !== undefined) {
            searchParams.append(key, value as string);
        }
    }

    return searchParams;
}
