Search code examples
sequelize.jsfeathersjsfeathers-sequelize

Featherjs sequelize database adapter service methods


i want to know how it is possible to remove some service methods(endpoint) from a service while using sequelize database adapter( or any other one)

// Initializes the `society` service on path `/society`
const createService = require('feathers-sequelize');
const createModel = require('../../models/society.model');
const hooks = require('./society.hooks');

module.exports = function (app) {
  const Model = createModel(app);
  const paginate = app.get('paginate');

  const options = {
    name: 'society',
    Model,
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/societies', createService(options));

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('societies');

  service.hooks(hooks);
};

here, all the service method : get,patch,post,remove are available - i want to have only get and find

a way to do it is to stop the request using hooks but its a dirty way.


Solution

  • Hooks are how Feathers does control things like that. You can prevent external access by checking if params.provider is set:

    const { Forbidden } = require('@feathersjs/errors');
    
    const disable = context => {
      if(context.params.provider) {
        throw new Forbidden('You can not do this');
      }
    };
    
    app.service('societies').hooks({
      before: {
        get: disable,
        patch: disable,
        update: disable,
        remove: disable
      }
    })