Created
October 20, 2020 21:15
-
-
Save rlubke/277118b07e703160066a9e03f37cd464 to your computer and use it in GitHub Desktop.
PUT /api/tasks/:id implementation
This file contains 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
api.put('/api/tasks/:id', (req, res, next) => { | |
const description = req.body.description | |
const completed = req.body.completed | |
let processor = null | |
if (description) { | |
processor = Processors.update('description', description) | |
} | |
if (typeof(completed) !== 'undefined') { | |
const compProcessor = Processors.update('completed', completed) | |
processor = processor ? processor.andThen(compProcessor) : compProcessor | |
} | |
tasks.invoke(req.params.id, processor) | |
.then(result => res.send(result)) | |
.catch(err => next(err)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment