exports.PaginationParam = (req, extraFields = []) => {
    const page = parseInt(req.query.page) || 1;
    const limit = parseInt(req.query.limit) || 10;
    const search = req.query.search || '';
    const sortBy = req.query.sort_by || 'createdAt';
    const orderBy = req.query.order_by || (sortBy === 'name' ? 'asc' : 'desc');

    const extra = {};
    for (const field of extraFields) {
        extra[field] = req.query[field] ?? null;
    }

    return {
        page,
        limit,
        search,
        sortBy,
        orderBy,
        ...extra
    };
};