// parsing JSON safely
function parseJSON(str, fallback) {
    try {
        return JSON.parse(str ?? '{}');
    } catch (e) {
        console.error('Error parsing JSON:', e);
        return fallback;
    }
}
export default function (route, param) {
    // catch route query params
    const params = parseJSON(route?.query?.params, {});

    // extract and parse filter from params
    const { filter: filterStr = '{}' } = params;
    const where = parseJSON(filterStr, {})?.where;
    if (where && where[param] !== undefined) {
        return where[param];
    }
    return null;
}
