Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why after upgrade feathersjs I receive error: MethodNotAllowed

I upgraded my feathersjs version from 2.x.x to 3.9.0 Now I have a problem with hooks (after)

this is my query:

app.service('duties').patch(id, { $set: { status: 0 }}, {});

I have below code in my hook after:

var query = { "duties._id": result._id }

hook.app.service('parents').patch(null, { $set: { "duties.$.status": 0 } }, { query });

With previously version this was work fine, now I receive an error in console:

error: MethodNotAllowed: Can not patch multiple entries

How can I resolve my problem?

like image 283
SeaDog Avatar asked Jan 02 '19 14:01

SeaDog


2 Answers

In order to improve out-of-the-box security, creating, removing and modifying multiple entries has been disabled by default and has to be enabled using the multi option (and secured explicitly). The migration instructions can be found at crow.docs.feathersjs.com/migrating.html#database-adapters:

const service = require('feathers-<database>');

// Allow multi create, patch and remove
service({
  multi: true
});

// Only allow create with an array
service({
  multi: [ 'create' ]
});

// Only allow multi patch and remove (with `id` set to `null`)
service({
  multi: [ 'patch', 'remove' ]
});

Keep in mind that when enabling multiple remove or patch requests the allowed query must be restricted (e.g. based on the authenticated user id), otherwise it could be possible to delete or patch every record in the database.

like image 72
Daff Avatar answered Nov 17 '22 05:11

Daff


It can be corrected/enabled (e.g for patch) here

\\ @Src/services/[name]/[name].service.js

.
.
.
module.exports = function(app) {
Const options = {
  Model: createModel(app),
  Paginate: app.get('paginate'),
  multi: ['patch']
};

.
.
.
},
like image 3
Ebena107 Avatar answered Nov 17 '22 06:11

Ebena107