Skip to content

Instantly share code, notes, and snippets.

@hieunguyendut hieunguyendut/request.js
Last active Jan 25, 2018

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Jan 25, 2018

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
You can’t perform that action at this time.