<commit_before>import Shipment from '../models/shipment';
import sanitizeHtml from 'sanitize-html';

export default {
    getShipments: function (req, res) {
        const rq = req.query,
              query = {};
        if (rq.company) query.company = rq.company;
        if (rq.dept) query.dept = rq.dept;
        
        if (rq.year && !rq.month) {
            query.date = {
                "$gte": new Date(rq.year, 0, 1),
                "$lt": new Date(rq.year, 12, 1)
            }
        } else if (rq.year && rq.month) {
            query.date = {
                "$gte": new Date(rq.year, rq.month, 1),
                "$lt": new Date(rq.year, Number(rq.month) + 1, 1)
            }
        }

        Shipment.find(query).sort('-date').limit(Number(rq.limit))
            .exec((err, shipments) => {
                if (err) {
                    return res.status(500).send(err);
                }
                res.json({
                    shipments
                });
            });
    },
    
    shipmentsPDF: function (req, res) {
        if (!("company" in req.query && "start" in req.query && "end" in req.query)) {
            res.status(400).send({error: "'start' and 'end' dates are required."});
        }
        const company = req.query.company,
              start = new Date(req.query.start),
              end = new Date(req.query.end);
        if (!company) {
            res.status(400).send({error: "Error in company name."});
        }
        if (isNaN(start.getDate()) || isNaN(end.getDate())) {
            res.status(400).send({error: "Malformed dates. Check format is YYYY/MM/DD."});
        }
        
        const query = {
            company: company,
            date: {<commit_msg>BUG FIX: $lte date needs a time value<commit_after>import Shipment from '../models/shipment';
import sanitizeHtml from 'sanitize-html';

export default {
    getShipments: function (req, res) {
        const rq = req.query,
              query = {};
        if (rq.company) query.company = rq.company;
        if (rq.dept) query.dept = rq.dept;
        
        if (rq.year && !rq.month) {
            query.date = {
                "$gte": new Date(rq.year, 0, 1),
                "$lt": new Date(rq.year, 12, 1)
            }
        } else if (rq.year && rq.month) {
            query.date = {
                "$gte": new Date(rq.year, rq.month, 1),
                "$lt": new Date(rq.year, Number(rq.month) + 1, 1)
            }
        }

        Shipment.find(query).sort('-date').limit(Number(rq.limit))
            .exec((err, shipments) => {
                if (err) {
                    return res.status(500).send(err);
                }
                res.json({
                    shipments
                });
            });
    },
    
    shipmentsPDF: function (req, res) {
        if (!("company" in req.query && "start" in req.query && "end" in req.query)) {
            res.status(400).send({error: "'start' and 'end' dates are required."});
        }
        const company = req.query.company,
              start = new Date(req.query.start),
              end = new Date(req.query.end + " 23:59");
        if (!company) {
            res.status(400).send({error: "Error in company name."});
        }
        if (isNaN(start.getDate()) || isNaN(end.getDate())) {
            res.status(400).send({error: "Malformed dates. Check format is YYYY/MM/DD."});
        }
        
        const query = {
            company: company,
            date: {
{'fraction_non_alphanumeric': 0.15445996010259333, 'fraction_numerical': 0.012539184952978056, 'mean_word_length': 1.4391938846421126, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2877378', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1061, 'n_words': 242}