Created
August 6, 2015 13:48
-
-
Save dsauerbrun/fdbcabeba7814a7650d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user.checkValidUser(userId).then(function(userInfo){ | |
10 if(userInfo.docs.length==1) | |
11 db.insert({type:'message',message:messageText,userId:userInfo }, function(err,body){ | |
12 if(!err) | |
13 console.log(body) | |
14 }); | |
15 else | |
16 console.log('error, more than 1 user returned') | |
17 }).fail(function(err){ | |
18 console.log(err); | |
19 }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkValidUser(userId){ | |
7 var deferred = Q.defer(); | |
8 db.find({"selector":{"documentType":"user","_id":userId}},function(err,body){ | |
9 if(!err){ | |
10 deferred.resolve(body) | |
11 } | |
12 else{ | |
13 deferred.reject(err) | |
14 } | |
15 }); | |
16 return deferred.promise; | |
17 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment