<commit_before>var Comment = require('../models/comments');
var Idea = require('../models/ideas');
var User = require('../models/users');
var Vote = require('../models/votes');
var IFuncs = require('./idea-functions');
var VoteFuncs = require('./vote-functions');
//var slackPost = require('./slackPost');
//var request = require('request');


// helper functions for querying data by userId and parentId with async callbacks
function findUser (un, callback){ 
  User.findOne({ sUserName: un }, function (err, user) {
    if (err) {
      callback(err, null);
    } else {
      callback(null, user);
    }
  });
}
function getIdeaId (pi, callback) {
  Idea.find({ shortId: pi }, function(err, idea){
    if(err) {
      callback(err, null);
    } else {
      callback(null, idea);
    }
  });
} 
function getCommId (pi, callback) {
  Comment.find({ shortId: pi }, function(err, comment){
    if(err) {
      callback(err, null);
    } else {
      callback(null, comment);
    }
  });
}// end helper db functions

function slackInt (req, res){

  // Parsing incoming request data
  // For ideas    : req.body.text = [ title | text | tags ];
  // For comments : req.body.text = [ shortId | text ];
  // For votes    : req.body.text = [ shortId ];

  var parsed = req.body.text.split("|").map(function(y){ return y.trim(); });
  
  // Set slackId to the user_id
  req.body.slackId = req.body.user_id;

  // Parsing data and directing idea / comment / vote to db insert functions
  switch(req.body.command){
    case '/idea':
      // TODO: create hyperlink for unique id
      req.body.shortId = String(parsed[0].split(" ").slice(0,3).join("_")+"_"+req.body.user_name).toLowerCase();
      req.body.title = parsed[0];
      req.body.body = parsed[1];<commit_msg>fixed db search<commit_after>var Comment = require('../models/comments');
var Idea = require('../models/ideas');
var User = require('../models/users');
var Vote = require('../models/votes');
var IFuncs = require('./idea-functions');
var VoteFuncs = require('./vote-functions');
//var slackPost = require('./slackPost');
//var request = require('request');


// helper functions for querying data by userId and parentId with async callbacks
function findUser (un, callback){ 
  User.findOne({ sUserName: un }, function (err, user) {
    if (err) {
      callback(err, null);
    } else {
      callback(null, user);
    }
  });
}
function getIdeaId (pi, callback) {
  Idea.find({ shortId: pi }, function(err, idea){
    if(err) {
      callback(err, null);
    } else {
      callback(null, idea);
    }
  });
} 
function getCommId (pi, callback) {
  Comment.find({ commShortId: pi }, function(err, comment){
    if(err) {
      callback(err, null);
    } else {
      callback(null, comment);
    }
  });
}// end helper db functions

function slackInt (req, res){

  // Parsing incoming request data
  // For ideas    : req.body.text = [ title | text | tags ];
  // For comments : req.body.text = [ shortId | text ];
  // For votes    : req.body.text = [ shortId ];

  var parsed = req.body.text.split("|").map(function(y){ return y.trim(); });
  
  // Set slackId to the user_id
  req.body.slackId = req.body.user_id;

  // Parsing data and directing idea / comment / vote to db insert functions
  switch(req.body.command){
    case '/idea':
      // TODO: create hyperlink for unique id
      req.body.shortId = String(parsed[0].split(" ").slice(0,3).join("_")+"_"+req.body.user_name).toLowerCase();
      req.body.title = parsed[0];
      req.body.body = parsed[1];
{'fraction_non_alphanumeric': 0.171671388101983, 'fraction_numerical': 0.0028328611898017, 'mean_word_length': 3.00794551645857, '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': '2193719', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1129, 'n_words': 299}