resource-router-middleware icon indicating copy to clipboard operation
resource-router-middleware copied to clipboard

Nested resource use

Open arifmahmudrana opened this issue 6 years ago • 1 comments

Can it be use for nested resource? e.g like Laravel https://laravel.com/docs/5.1/controllers#restful-nested-resources.

If I have route like photos/:photos/comments/:comments how will I use your package?

arifmahmudrana avatar Apr 07 '19 16:04 arifmahmudrana

app.use('/photos/:photo', resource({
    id: 'comment',
    mergeParams: true,
    load(req, id, callback) {
      const { photo } = req.params;
      comments.find({ id, photo_id:photo })
        .then(callback.bind(null,null))
        .catch(callback);
    },

    async list(req, res) {
      req.photo. // The photo ID
      res.json(await comments.find({photo_id:req.photo}));
    }
}));

developit avatar Apr 07 '19 17:04 developit