Last active
January 25, 2018 11:11
-
-
Save hieunguyendut/91bb793b26d3b2f4f21b158b06b03ff0 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
function getUsers() { | |
var req = { | |
method: 'GET', | |
url: 'http://localhost:3000/api/getUsers', | |
headers: { | |
'app-key': 'CopyXwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT', | |
token: $cookies.get('token') | |
} | |
}; | |
$http(req).then(function(res) { | |
console.log('here: ', res.data.data); | |
$scope.users = res.data.data; | |
}, function(res) { | |
console.log('error', res); | |
}); | |
}; |
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 getUsers(req, res) { | |
return Role | |
.findOne({name: 'admin'}) | |
.then(role => { | |
User | |
.find() | |
.populate({ | |
path: 'roleId nationId', | |
select: '-__v -createdAt -updatedAt -role' | |
}) | |
.where('roleId') | |
.nin([role._id]) | |
.select('-__v -password -createdAt -updatedAt') | |
.then(users => { | |
return res.json({ | |
isSuccess: true, | |
data: users | |
}); | |
}) | |
.catch(err => { | |
return res.json({ | |
isSuccess: false, | |
errorText: err.message | |
}); | |
}); | |
}) | |
} |
nghuuquyen
commented
Jan 25, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment