Skip to content

Commit

Permalink
fix: do not validate param existence for patch requests (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba committed Aug 28, 2017
1 parent ea2b8f9 commit 6c22bdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/packages/router/route/params/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function paramsFor({
if (method === 'POST' || method === 'PATCH') {
params = [
...params,
getDataParams(controller, true)
getDataParams(controller, method, true)
];
}
} else if (type === 'collection') {
Expand All @@ -45,7 +45,7 @@ export function paramsFor({
if (method === 'POST' || method === 'PATCH') {
params = [
...params,
getDataParams(controller, false)
getDataParams(controller, method, false)
];
}
} else if (type === 'custom') {
Expand Down
14 changes: 8 additions & 6 deletions src/packages/router/route/params/utils/get-data-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ function getTypeParam({
/**
* @private
*/
function getAttributesParam({
model,
params
}: Controller): [string, ParameterLike] {
function getAttributesParam(
{ model, params }: Controller,
method: 'PATCH' | 'POST',
): [string, ParameterLike] {
return ['attributes', new ParameterGroup(params.reduce((group, param) => {
const col = model.columnFor(param);
if (col) {
const type = typeForColumn(col);
const path = `data.attributes.${param}`;
const required = !col.nullable && isNull(col.defaultValue);
const required =
method !== 'PATCH' && !col.nullable && isNull(col.defaultValue);
return [
...group,
Expand Down Expand Up @@ -140,13 +141,14 @@ function getRelationshipsParam({
*/
export default function getDataParams(
controller: Controller,
method: 'PATCH' | 'POST',
includeID: boolean
): [string, ParameterLike] {
let params = [getTypeParam(controller)];
if (controller.hasModel) {
params = [
getAttributesParam(controller),
getAttributesParam(controller, method),
getRelationshipsParam(controller),
...params
];
Expand Down

0 comments on commit 6c22bdf

Please sign in to comment.