Last active
May 17, 2017 14:19
-
-
Save bsommardahl/f2cce74d0d6e8c7f3fdacb2a38311f73 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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