Skip to content

Instantly share code, notes, and snippets.

@chewtoys
Created November 3, 2019 21:47
Show Gist options
  • Save chewtoys/076c7ce2426a0d4d3969a0601dc34f5b to your computer and use it in GitHub Desktop.
Save chewtoys/076c7ce2426a0d4d3969a0601dc34f5b to your computer and use it in GitHub Desktop.
const {
omit,
} = require('lodash')
transform() {
const transformed = {}
const fields = ['id', 'name', 'stats']
fields.forEach((field) => {
transformed[field] = this[field]
})
return transformed
}
const omitS = req.body.stats
const updatedS = omit(req.body, omitS)
updatedS.save()
.then(savedS => res.json(savedS.transform()))
.catch(e => next(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment