KarimS
KarimS

Reputation: 3892

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.

Upvotes: 1

Views: 315

Answers (1)

Daff
Daff

Reputation: 44215

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
  }
})

Upvotes: 1

Related Questions