how to optimize code like reduce code with same functionality

    let response = {}
    var filters = {
        topfeaturedandotherfields: req.body.topfeaturedandotherfields
    }

    if(req.body.minprice && req.body.maxprice && req.body.brandName)
    {

        var filters = {
            
            $and :[
                {"brandName" : { "$in": req.body.brandName }}, 
                {topfeaturedandotherfields: req.body.topfeaturedandotherfields },
                {salePrice:{ $gte: req.body.minprice, $lte: req.body.maxprice }}]
            
             }
 

         var result = await productService.getAllProductofhomepage(filters,req.body.ordername,req.body.orderby)


    }
    else{
    if (req.body.minprice && req.body.maxprice) {
        
        var filters = {
           $and: [{topfeaturedandotherfields: req.body.topfeaturedandotherfields},{salePrice:{ $gte: req.body.minprice, $lte: req.body.maxprice }}]
        }

       
        
        
        var result = await productService.getAllProductofhomepage(filters,req.body.ordername,req.body.orderby)
    }
    if (req.body.brandName) {
        
        var filters = {
            
           $and :[
               {"brandName" : { "$in": req.body.brandName }}, 
               {topfeaturedandotherfields: req.body.topfeaturedandotherfields }]
           
            }


        var result = await productService.getAllProductofhomepage(
            filters,req.body.ordername,req.body.orderby
        )
    }
}

    if (req.body.limit == true)
        var result = await productService.getAllProductofhomepagewithlimit(
            filters
        )
   else if (req.body.minprice || req.body.maxprice || req.body.brandName)
    {}
    else
    {
        var result = await productService.getAllProductofhomepage(filters,req.body.ordername,req.body.orderby)
    }

    if (result.length > 0) {
        response = {
            message: 'Home page products successfully retrieved',
            error: false,
            data: result,
        }
    } else {
        response = {
            message: 'Faild to get products',
            error: true,
            data: {},
        }
    }

    res.status(200).json(response)

This code is used to filter like to see top feature and bestseller or min and max price and the brand name also in this code sort by order name which could be price or brand name or category also in ascending and descending order so now you can see this code is like if and else but I want to optimize and reduce code