Sunday, 17 February 2019

SailsJS V1 - Blueprint query not working correctly

I'm trying to create a blueprint query for a sailsjs v1 model.

The model is a BlogPost which has 2 "options". One is the target and the other one is Status.

If the target is Site and the status is Published, the query should return, otherwise nope. I'm using the default REST routes provided by Sails (blueprints) and everything works fine if i try to find all of them, however if i try to find one by ID...i can event get back those that have a status of 'Unpublished'.

This is my code in blueprint.js parseBlueprintOptions ->

parseBlueprintOptions: function (req) {

    var queryOptions = req._sails.hooks.blueprints.parseBlueprintOptions(req);
    if (queryOptions.using === 'blogpost') {
      if (req.options.blueprintAction === 'create') {
        queryOptions.newRecord.user_id = req.session.user.id;
        return queryOptions;
      } else if (req.options.blueprintAction === 'update') {
        queryOptions.criteria.where.user_id = req.session.user.id;
        queryOptions.valuesToSet.user_id = req.session.user.id;
        return queryOptions;
      } else {
        if (req.session.administrator) {
          return queryOptions;
        } else {
          queryOptions.criteria.where.blogpost_target = 'Site';
          queryOptions.criteria.where.blogpost_status = 'Published';

          console.log(queryOptions);
          return queryOptions;
        }
      }
    }
  }
};

Any tips on why the query does not get triggered for findOne ? As i said, it returns regardless of status/target.



from SailsJS V1 - Blueprint query not working correctly

No comments:

Post a Comment