Skip to content

Instantly share code, notes, and snippets.

@hieunguyendut
Last active January 25, 2018 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieunguyendut/91bb793b26d3b2f4f21b158b06b03ff0 to your computer and use it in GitHub Desktop.
Save hieunguyendut/91bb793b26d3b2f4f21b158b06b03ff0 to your computer and use it in GitHub Desktop.
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);
});
};
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
Copy link

function getUsers(req, res) {
    Role
        .findOne({
            name: 'admin'
        })
        .then(role => {
            return 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
            });
        });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment