February 2019
Intermediate to advanced
204 pages
4h 52m
English
We need an endpoint to get user information by some identifier. To create the endpoint we need, follow these steps:
routerAuth.get('/users/:id', User.show);
show: (req, res) => { Model.users .getBy(req.params.id) .then(user => handleSuccess(res, { user: user.toJson() })) .catch(errors => handleFailure(res, { errors, message: errors.message })); },
Schema.statics.getBy = function(id) { return new Promise((resolve, reject) => { try { this.findOne({ _id: id }) .then(user => resolve(user)) .catch(error => reject(error)); } catch (e) { reject(e); } }); };
As part of the ...
Read now
Unlock full access