<commit_before>/*jslint eqeq: true, indent: 2, node: true, plusplus: true, regexp: true, unparam: true, vars: true, nomen: true */
'use strict';

var router = module.exports = require('express').Router();

router.route('/create').get(function (req, res) {
}).post(function (req, res) {
});

router.route('/update/:article').all(function (req, res) {
}).get(function (req, res) {
}).post(function (req, res) {
});

router.route('/delete/:article').get(function (req, res) {
});

router.route('/browse').all(function (req, res) {
});<commit_msg>Implement catalog routing.<commit_after>/*jslint eqeq: true, indent: 2, node: true, plusplus: true, regexp: true, unparam: true, vars: true, nomen: true */
'use strict';

var router = module.exports = require('express').Router();
var mw = require('./middleware');
var model = require('neuola-data');

router.route('/create').get(mw.toPage('catalog-create')).post(function (req, res) {
  var rawCatalog = req.param('catalog');
  if (rawCatalog) {
    var catalog = new model.Catalog(rawCatalog);
    catalog.save(function (err, doc) {
      if (err) {
        res.render('error', err);
      } else {
        res.render('catalog-create-done', doc);
      }
    });
  } else {
    res.render('invalid');
  }
});

router.route('/update/:id').get(mw.toPage('catalog-update')).post(function (req, res) {
  var id = req.param('id');
  var rawCatalog = req.param('catalog');
  if (rawCatalog) {
    var q = model.Catalog.findByIdAndUpdate(id, rawCatalog);
    q.exec().then(function (doc) {
      res.render('catalog-update-done', doc);
    }, res.render.bind(res, 'error'));
  } else {
    res.render('invalid');
  }
});

router.route('/delete/:id').get(function (req, res) {
  var id = req.param('id');
  if (id) {
    var q = model.Catalog.findByIdAndRemove(id);
    q.exec().then(function (doc) {
      res.render('catalog-delete-done', doc);
    }, res.render.bind(res, 'error'));
  } else {
    res.render('invalid');
  }
});

router.route('/browse').all(function (req, res) {
  var q = model.Catalog.find();
  q.exec().then(function (docs) {
    res.render('catalog-list-latest', {catalogs: docs});
  }, res.render.bind(res, 'error'));
});
{'fraction_non_alphanumeric': 0.21264894592117323, 'fraction_numerical': 0.0009165902841429881, 'mean_word_length': 3.950113378684807, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2445246', 'n_tokens_mistral': 746, 'n_tokens_neox': 754, 'n_words': 154}