<commit_before>/**
 * Uses Mongoose Models for db operations.
 */
import Shipment from '../models/barrelShipment.model'
import sanitizeHtml from 'sanitize-html'
import { Router } from 'express'
import * as utils from '../../shared/utils/utils'

const router = new Router()


router.get('/', function getShipments(req, res) {
    const rq = req.query,
          query = {};
    if (rq.company) query.company = rq.company;
    if (rq.year) query.shipYear = rq.year;
    if (rq.month) query.shipMonth = rq.month;


    Shipment.find(query, {__v: 0, dateAdded: 0})
    .sort('-shipYear -shipMonth -shipDate -dateAdded')
    .exec((err, docs) => {
        if (err) {
            console.log(err);
            return res.status(500).send(err);
        }

        res.json(docs);
    });
})


router.get('/latest/:company/:limit', function getLatest(req, res) {
    const company = req.params.company;
    const limit = Number(req.params.limit);
    Shipment.find({ company }, { _id: 0, __v: 0, dateAdded: 0 })
    .sort('-shipYear -shipMonth -shipDate -dateAdded')
    .limit(limit)
    .exec((err, docs) => {
        if (err) {
            console.log(err);
            return res.status(500).send(err);
        }

        docs.map(each => {
            each.rtCode = utils.getRoute(each);
            each.rtSeq = undefined;<commit_msg>Added api method for getting company name list<commit_after>/**
 * Uses Mongoose Models for db operations.
 */
import Shipment from '../models/barrelShipment.model'
import sanitizeHtml from 'sanitize-html'
import { Router } from 'express'
import * as utils from '../../shared/utils/utils'

const router = new Router()


router.get('/', function getShipments(req, res) {
    const rq = req.query,
          query = {};
    if (rq.company) query.company = rq.company;
    if (rq.year) query.shipYear = rq.year;
    if (rq.month) query.shipMonth = rq.month;


    Shipment.find(query, {__v: 0, dateAdded: 0})
    .sort('-shipYear -shipMonth -shipDate -dateAdded')
    .exec((err, docs) => {
        if (err) {
            console.log(err);
            return res.status(500).send(err);
        }

        res.json(docs);
    });
})


router.get('/companies', function getCompanyList(req, res) {
    Shipment.aggregate([
        { $match: {
            company: {
                $ne: null
            }
        } },
        { $group: {
            _id: '$company'
        } },
    ])
    .exec((err, docs) => {
        if (err) {
            console.log(err);
            return res.status(500).send(err);
        }

        res.json(docs.map(ea => ea._id));
    })
})


router.get('/latest/:company/:limit', function getLatest(req, res) {
    const company = req.params.company;
    const limit = Number(req.params.limit);
    
    Shipment.find({ company }, { _id: 0, __v: 0, dateAdded: 0 })
    .sort('-shipYear -shipMonth -shipDate -dateAdded')
    .limit(limit)
    .exec((err, docs) => {
        if (err) {
            console.log(err);
            return res.status(500).send(err);
        }

        docs.map(each => {
            each.rtCode = utils.getRoute(each);
            each.rtSeq = undefined;
{'fraction_non_alphanumeric': 0.15896782414781777, 'fraction_numerical': 0.00796431984708506, 'mean_word_length': 2.1462925851703405, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5028504', 'n_tokens_mistral': 1052, 'n_tokens_neox': 1025, 'n_words': 227}