var User = require('./../../database/models/user_schema.js');
var db = require('./../../database/config.js');

var exportObj = {};

exportObj.addUser = function(linkHash, senderID, receiverID) {
  new User({
    linkHash: linkHash,
    senderID: senderID,
    receiverIDArray: receiverID
  }).save(function(err, addedUser) {
    if(err) {
      console.log('error trying to save user to DB:', err);
    } else {
      console.log('addedUser:', addedUser);
    }
  });
};

exportObj.addReceiver = function(senderID, receiverID) {
  User.findOneAndUpdate(
    {senderID: senderID},
    {$push: {receiverIDArray: receiverID}},
    {safe: true, upsert: true},
    function(err, model) {
      console.log(err);
    }
  );
};

exportObj.deleteUser = function(senderID) {
  User.find({senderID: senderID}).remove(function(err) {
    if (err) {
      console.log('could not delete', senderID, ':', err);
    } else {
      console.log('deleted', senderID);
    }
  }).exec();
};

@@ -961,12 +961,323 @@
 .exec();%0A%7D;%0A
+%0AexportObj.getUser = function(linkHash) %7B%0A  User.findOne(%7BlinkHash: linkHash%7D, function(err, user) %7B%0A    if (err) %7B%0A      console.log('could not get user', user, ':', err);%0A    %7D else %7B%0A      console.log('retrieved senderID:', user.senderID, 'from linkHash', linkHash);%0A      return user.senderID;%0A    %7D%0A  %7D)%0A%7D;

Add helper function to get senderID from linkHash with kcvan in database_queries.js