{"size": 1846, "ext": "js", "max_stars_repo_path": "lib/modules/clarium-server/server/controller/categories.controller.js", "max_stars_repo_name": "floresfactor/apostrophe-boilerplate", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "lib/modules/clarium-server/server/controller/categories.controller.js", "max_issues_repo_name": "floresfactor/apostrophe-boilerplate", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/modules/clarium-server/server/controller/categories.controller.js", "max_forks_repo_name": "floresfactor/apostrophe-boilerplate", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.9696969697, "max_line_length": 78, "alphanum_fraction": 0.6256771398}
const express  = require('express');
const DAO      = require('../dao/mongo.dao');
const COLLECTION = "categories";
const logger      = require('../config/logger');

module.exports = exports = {

  find: function(req, res){
    logger.info("[controller] find", req.query);
    DAO.find(COLLECTION, req.query).then(function(data){
			res.json(data);
    }).catch(function (error) {
      res.status(500).json(error);
    });
  },

  findById: function(req, res){
    logger.info("[controller] findByID", req.params.id);
    DAO.findById(COLLECTION, req.params.id).then(function(data){
      res.json(data);
    }).catch(function (error) {
      res.status(500).json(error);
    });
  },

  findByQuery: function(req, res){
    logger.info("[controller] findByQuery");
    DAO.findByQuery(COLLECTION, req.params.query).then(function(data){
			res.json(data);
    }).catch(function (error) {
      res.status(500).json(error);
    });
  },

  insertOne: function(req, res){
    logger.info("[controller] insertOne: ", req.body);
    DAO.insertOne(COLLECTION, req.body, req.decoded).then(function(data){
			res.json(data);
      logger.info(data);
    }).catch(function (error) {
      res.status(500).json(error);
    });
  },

  updateOne: function(req, res){
    logger.info("[controller] updateOne: body: ", req.body);
    DAO.updateOne(COLLECTION, req.body, req.decoded).then(function(data){
			res.json(data);
    }).catch(function (error) {
      logger.info("[controller] updateOne catch");
      res.status(500).json(error);
    });
  },

  deleteOne: function(req, res){
    logger.info("[controller] deleteOne: id: ", req.params.id);
    DAO.deleteOne(COLLECTION, req.params.id, req.decoded).then(function(data){
			res.json(data);
      logger.info(data);
    }).catch(function (error) {
      res.status(500).json(error);
    });
  }

}
