All files / src/controllers/statistics-controllers registerOrderStatistics.js

80% Statements 8/10
100% Branches 0/0
100% Functions 2/2
77.77% Lines 7/9

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 17 18 19        2x   2x 2x   2x 2x 2x   2x          
import idParser from "../../utilities/idParser.js";
import { getCurrentDate } from "../../utilities/dateMaker.js";
 
export default function registerOrderStatistics({ products, totalPrice }, currentYearStatistics) {
    try {
        const
            { monthIndex } = getCurrentDate(),
            productsCount = products.reduce((acc, curr) => acc + idParser(curr).count, 0)
 
        currentYearStatistics.monthes[monthIndex].totalOrders++
        currentYearStatistics.monthes[monthIndex].totalEarnings += totalPrice
        currentYearStatistics.monthes[monthIndex].productsSold += productsCount
 
        return true
    } catch (error) {
        console.log(error)
        return false
    }
}