Thomas Bereczky
Thomas Bereczky

Reputation: 31

FeathersJS Getting record in before hook or saving the record in after hook

I'm trying to figure out how to get the records which are existing in a "before" "patch" hook or how to save records in an "after" "patch" hook, either solution would work for me however I could not find a way around it. Does anyone have any workarounds?

I was thinking on an approach like this -->

 module.exports = function() {
   return async function (context) {
     let why = await context.app.service('transactions').get(context.id);
     console.log(why);
     return context;
   };
 };

However, this solution returns this --> Cannot read property '_id' of undefined

I have been playing around with this since last night without sleep and I'm running low on ideas at this point.

The only way I could see myself at this point is calling an UPDATE hook from the patch after hook but I'm looking for a cleaner solution then that.

Upvotes: 1

Views: 698

Answers (1)

Thomas Bereczky
Thomas Bereczky

Reputation: 31

The issue was related to me calling my GET hook which had permissions already and it did not find it because of that. The solution // way around was to wrap it around commonHooks.isProvider('external').

get: [
  commonHooks.iff(
    commonHooks.isProvider('external'),
    checkPermissions({
      roles: ['admin'],
      field: 'permissions',
      entity: 'accounts',
      error: false
    }),
    context => {
      if(!context.params.permitted){
        context.params.query = {
          $or: [
            { 
              bidAccountId: context.params.accounts['_id']
            }, 
            {
              offerAccountId: context.params.accounts['_id']
            }
          ]
        };
      }
    }
  ),
],

Upvotes: 2

Related Questions