enter image description here

I can not replace the repetition of the code (which commented out).

module.exports = function(Product) { /*Product.disableRemoteMethod('createChangeStream', true); Product.disableRemoteMethod('upsert', true); Product.disableRemoteMethod('upsert', true); Product.disableRemoteMethod('updateAll', true); Product.disableRemoteMethod('replaceOrCreate', true); Product.disableRemoteMethod('replaceById', true); Product.disableRemoteMethod('exists', true); Product.disableRemoteMethod('count', true); Product.disableRemoteMethod('findOne', true);*/ var array = ['createChangeStream', 'upsert', 'updateAll', 'replaceOrCreate', 'replaceById', 'exists', 'count', 'findOne']; array.forEach(function(item, i, array) { Product.disableRemoteMethod( i + item + array ); }); }; 
  • paste code with text - Grundy
  • Well, and create some kind of horror, you just had to item and true transfer, and not add it to i and array - Grundy
  • I'm just a beginner here and create "horror") - Garry Daam
  • one
    Product.disableRemoteMethod(item, true); - Igor
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

You just need to compare the commented calls with the one inside the loop.

 Product.disableRemoteMethod('upsert', true); Product.disableRemoteMethod('replaceById', true); Product.disableRemoteMethod( i + item + array ); 

You can see two differences: inside the loop, one parameter is passed to the function, instead of two. Only the value from the array should be transferred to where the changing parameters are delivered.

 Product.disableRemoteMethod( item, true );