Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@

var params = {
type: execMethodType,
dataType: 'json',
contentType: 'application/json',
processData: false
dataType: 'json'
};

// Ensure that we have a URL and add method name to it
Expand All @@ -60,7 +58,15 @@
}

// stringify data to json
if (options.data && _.isObject(options.data)) {
if (
options.data &&
_.isObject(options.data) &&
_([
'post', 'patch', 'put'
]).contains((options.type || params.type).toLowerCase())

@artzhookov artzhookov Mar 23, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good practice to split such huge constructions to smaller pieces to prevent unreadable if conditions.
In this case I'd define a type variable var type = (options.type || params.type).toLowerCase(); above and change this line to

_(['post', 'patch', 'put']).contains(type)

) {
params.processData = false;
params.contentType = 'application/json';
options.data = JSON.stringify(options.data);
}

Expand Down