I'm trying to pretty much make my code clean and pretty.
I have something like this
let {name, city, address} = param.allParams()
let attr = {}
if (name) {
attr.name = name
}
I wanted to see how I can condense even more. I tried this for example:
let {name, city, address} params.allParams()
let attr = {
... name,
... city,
... address
}
I'm not sure I know what I was doing with the above example, but I'm experimenting and exploring javascript as well. Is there a better method to this?
thanks.
update: solution based on @Pointy comments
async update(req, res) {
try {
const results = await Company.update({id: req.params.id}, req.allParams())
return res.ok(results)
} catch (e) {
return res.serverError(e)
}
}