<commit_before>'use strict';
const Router = require('express').Router;
const DrugSchema = require('../models/drugschema');
const HandleError = require('../controller/errhandler');
let interactionRouter = module.exports = exports = Router();
const unique = function(a) {
  return Array.from(new Set(a));
};

interactionRouter.get('/interactions/:userId/:drugName', function(req, res, next) {
  let drugName = req.params.drugName;
  DrugSchema.find({'userId': req.params.userId})
  .then((drugs) => {
    if (!drugs) return HandleError(404, next)(new Error('Drugs not found'));
    var drugArray = [];
    drugs.forEach(function(item) {
      item.interactions.forEach(function(q) {
        if (q.drugname === drugName){
          drugArray.push('Interaction between ' + item.drug + ' and ' + q.drugname + ': ' + q.interaction);
        }
      });
    });
    if (drugArray.length > 0) {
      let uniqueArr = unique(drugArray);
      res.json(uniqueArr.join(' ').toString());
      next();
    }
    return HandleError(404, next)(new Error('No interactions found'));
  });
});<commit_msg>added get request to pull list of all drug names that interact with users saved drugs<commit_after>'use strict';
const Router = require('express').Router;
const DrugSchema = require('../models/drugschema');
const HandleError = require('../controller/errhandler');
let interactionRouter = module.exports = exports = Router();
const unique = function(a) {
  return Array.from(new Set(a));
};

interactionRouter.get('/interactions/:userId/:drugName', function(req, res, next) {
  let drugName = req.params.drugName;
  DrugSchema.find({'userId': req.params.userId})
  .then((drugs) => {
    if (!drugs) return HandleError(404, next)(new Error('Drugs not found'));
    var drugArray = [];
    drugs.forEach(function(item) {
      item.interactions.forEach(function(q) {
        if (q.drugname === drugName){
          drugArray.push('Interaction between ' + item.drug + ' and ' + q.drugname + ': ' + q.interaction);
        }
      });
    });
    if (drugArray.length > 0) {
      let uniqueArr = unique(drugArray);
      res.json(uniqueArr.join(' ').toString());
      next();
    }
    return HandleError(404, next)(new Error('No interactions found'));
  });
});

interactionRouter.get('/interactions/:userId', function(req, res, next) {
  DrugSchema.find({'userId': req.params.userId})
  .then((drugs) => {
    if (!drugs) return HandleError(404, next)(new Error('Drugs not found'));
    var drugArray = [];
    drugs.forEach(function(item) {
      drugArray.push('DRUGS INTERACTING WITH ' + item.drug.toUpperCase() + ':');
      item.interactions.forEach(function(q) {
        drugArray.push(q.drugname);
      });
    });
    if (drugArray.length > 0) {
      let uniqueArr = unique(drugArray);
      res.json(uniqueArr);
      next();
    }
    return HandleError(404, next)(new Error('No interactions found'));
  });
});
{'fraction_non_alphanumeric': 0.17073170731707318, 'fraction_numerical': 0.007214015802129852, 'mean_word_length': 3.6003159557661926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4982387', 'n_tokens_mistral': 917, 'n_tokens_neox': 894, 'n_words': 189}