#Hey, quick question: can I detect from WHERE it's a row added/edited?

4 messages · Page 1 of 1 (latest)

verbal raft
#

I have an images collection and I upload images from different places, and when I upload/edit from a specific collection I want to run some specific code via a hook, but ONLY when I edit from a specific collection.

Example
upload/edit image from images collection or from x collection -> don't do anything
upload/edit image from y collection -> run specific code via a hook

hoary gyroBOT
green star
#

There is no way to do that. But, what you can do, is use req.context + custom upload component for uploades where you need this specific job to do after create. And then your custom component can mimic payload core component with additional context on upload request , that will run your code via hook.

But, i'm not sure if context can be passed via REST api , so maybe you can switch context to separate hidden field, when creating, and run code based on this field.
Or with custom component you could even just add separate endpoint for your specific code, and call it after sucessfull upload

verbal raft
#

Thanks, i have finally decided to create an netire new collection and have a hook on that collection instead.