#How to extend the payload object with custom methods?

1 messages · Page 1 of 1 (latest)

hot pulsarBOT
stark idol
#

What are you trying to do? Why not just functional programming?

muted ice
#

I'm trying to extend the payload object with custom methods such as findOne (that wraps the default find method) and be able to retrieve it both from req.payload and from the payload object I get with import payload from 'payload', so then I can do req.payload.findOne({}) and payload.findOne({})

stark idol
#

Yeah, a popular piece of advice when programming in general is to not extend an object you don't own.
If I were you, I'd do findOne(payload, {}) or findOne(req.payload, {}).
On the other hand, if the collection is obtained by id, remember that you have payload.findById. Finally, if the method has a good reason for being, you can justify it as a feature request and we can consider adding it.