Skip to content

Commit 95a5d28

Browse files
author
Oliver Rumbelow
committed
Merge pull request #145 from holidayextras/patch-relationship-required
Unable to patch relationships on resources with required attributes
2 parents 5b0bb05 + ff44e18 commit 95a5d28

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

example/resources/comments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jsonApi.define({
88
handlers: commentHandler,
99
searchParams: { },
1010
attributes: {
11-
body: jsonApi.Joi.string()
11+
body: jsonApi.Joi.string().required()
1212
.description("The tag name")
1313
.example("Summer"),
1414
timestamp: jsonApi.Joi.string().regex(/^[12]\d\d\d-[01]\d-[0123]\d$/)

lib/routes/updateRelation.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var updateRelationRoute = module.exports = { };
44

55
var async = require("async");
66
var _ = {
7-
assign: require("lodash.assign")
7+
assign: require("lodash.assign"),
8+
pick: require("lodash.pick")
89
};
910
var helper = require("./helper.js");
1011
var router = require("../router.js");
@@ -38,7 +39,8 @@ updateRelationRoute.register = function() {
3839
type: request.params.type
3940
});
4041
theirResource[request.params.relation] = theirs;
41-
helper.validate(theirResource, resourceConfig.onCreate, callback);
42+
var validator = _.pick(resourceConfig.onCreate, [ "id", "type", request.params.relation]);
43+
helper.validate(theirResource, validator, callback);
4244
},
4345
function(callback) {
4446
resourceConfig.handlers.update(request, theirResource, callback);

test/patch-resource-id.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe("Testing jsonapi-server", function() {
6161
}
6262
})
6363
};
64-
helpers.request(data, function(err, res, json) {
64+
request(data, function(err, res, json) {
6565
assert.equal(err, null);
6666
json = helpers.validateError(json);
6767
assert.equal(res.statusCode, "403", "Expecting 403");
@@ -200,7 +200,7 @@ describe("Testing jsonapi-server", function() {
200200
}
201201
})
202202
};
203-
helpers.request(data, function(err, res, json) {
203+
request(data, function(err, res, json) {
204204
assert.equal(err, null);
205205
json = helpers.validateJson(json);
206206

@@ -292,7 +292,7 @@ describe("Testing jsonapi-server", function() {
292292
}
293293
})
294294
};
295-
helpers.request(data, function(err, res, json) {
295+
request(data, function(err, res, json) {
296296
assert.equal(err, null);
297297
json = helpers.validateJson(json);
298298

0 commit comments

Comments
 (0)