All files / src/controllers/products-controllers getTopProducts.js

50% Statements 2/4
0% Branches 0/1
100% Functions 1/1
50% Lines 2/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16        3x 3x                    
import { productDataTypes } from "../../CONSTANT/projections.js";
import ProductsModel from "../../models/Products.js"
 
export default async function getTopProducts(limit = 10) {
    try {
        return await ProductsModel
            .find({}, productDataTypes.basic)
            .sort({ sold: -1, earnings: -1 })
            .limit(limit)
 
    } catch (error) {
        console.log(error)
        return null;
    }
}