Skip to content

Instantly share code, notes, and snippets.

@bsommardahl
Last active May 17, 2017 14:19
Show Gist options
  • Save bsommardahl/f2cce74d0d6e8c7f3fdacb2a38311f73 to your computer and use it in GitHub Desktop.
Save bsommardahl/f2cce74d0d6e8c7f3fdacb2a38311f73 to your computer and use it in GitHub Desktop.
public updateTask(request: Hapi.Request, reply: Hapi.IReply) {
let userId = request.auth.credentials.id;
let id = request.params["id"];
let task: ITask = request.payload;
//the database needs to be wrapped in a Reader here.
this.database.taskModel.findByIdAndUpdate({ _id: id, userId: userId }, { $set: task }, { new: true })
.then((updatedTask: ITask) => {
//this if needs to be replaced by a monad here.
if (updatedTask) {
reply(updatedTask);
} else {
reply(Boom.notFound());
}
}).catch((error) => {
reply(Boom.badImplementation(error));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment