-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed query params handling to accept query params matching
- Loading branch information
groyoh
committed
Sep 2, 2015
1 parent
4b7f7f2
commit bfb2c69
Showing
9 changed files
with
238 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,38 @@ | ||
var _ = require('lodash'); | ||
|
||
exports.noParamComparator = function(a, b){ | ||
return (a.parsedUrl.queryParams.length - b.parsedUrl.queryParams.length); | ||
return (Object.keys(a.parsedUrl.queryParams).length - Object.keys(b.parsedUrl.queryParams).length); | ||
}; | ||
|
||
exports.queryParameterComparator = function(a, b){ | ||
if (b.matchingQueryParams === a.matchingQueryParams){ | ||
return (a.nonMatchingQueryParams - b.nonMatchingQueryParams); | ||
if (b.exactMatchingQueryParams === a.exactMatchingQueryParams){ | ||
return (a.nonMatchingQueryParams - b.nonMatchingQueryParams); | ||
} | ||
return (b.exactMatchingQueryParams - a.exactMatchingQueryParams); | ||
} | ||
return (b.matchingQueryParams - a.matchingQueryParams); | ||
}; | ||
|
||
exports.countMatchingQueryParms = function (handlers, reqQueryParams){ | ||
handlers.forEach(function(handler){ | ||
handler.matchingQueryParams = 0; | ||
handler.exactMatchingQueryParams = 0; | ||
handler.nonMatchingQueryParams = 0; | ||
handler.parsedUrl.queryParams.forEach(function(templateQueryParam){ | ||
if (reqQueryParams.indexOf(templateQueryParam)>-1){ | ||
handler.matchingQueryParams +=1; | ||
} else { | ||
var specQueryParams = handler.parsedUrl.queryParams; | ||
for(var param in specQueryParams){ | ||
var value = specQueryParams[param]; | ||
if (reqQueryParams.hasOwnProperty(param)){ | ||
var reqValue = reqQueryParams[param]; | ||
if (_.isEqual(value, reqValue)){ | ||
handler.matchingQueryParams += 1; | ||
handler.exactMatchingQueryParams += 1; | ||
}else if (value === ''){ | ||
handler.matchingQueryParams += 1; | ||
} | ||
}else{ | ||
handler.nonMatchingQueryParams +=1; | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.