sealcode / sealious

An extensible, declarative node framework
25 stars 2 forks source link

Method PATCH shouldn't be requires fields with property required: "true" #234

Closed arkadiusz-wieczorek closed 8 years ago

arkadiusz-wieczorek commented 8 years ago

When I sent PATCH for some resource without fields with property required: "true" I've received error:

11:12:14.363 - error:   PATCH /api/v1/places/igv5i69ubd
            from: 127.0.0.1, mime: multipart/form-data
            result: failed - There are problems with some of the provided values.
Error: There are problems with some of the provided values.

Because I didn't give values of fields latitude and longitude with property required: "true".

{
    "data": {
        "longitude": "Missing value for field `longitude`",
        "latitude": "Missing value for field `latitude`"
    },
    "is_error": true,
    "type": "validation",
    "status_message": "There are problems with some of the provided values."
}

In my opinion such fields shouldn't be checked until validation. What do you think?

kuba-orlik commented 8 years ago

Please include here the declaration of your resource-types and the full stack from the console

arkadiusz-wieczorek commented 8 years ago

Ok, I will add this information.

arkadiusz-wieczorek commented 8 years ago
new Sealious.ChipTypes.ResourceType({
    name: "person",
    human_readable_name: "Person",
    human_readable_description: "Description about ResourceType: Person",
    fields: [
        {name: "name", type: "text"}, 
        {name: "age", type: "int"},
        {name: "lat", type: "float", required: true}
    ]
    //,
    // access_strategy: {
    // } //crud
});
01:52:58.110 - error:   PATCH /api/v1/person/ude30cvhhm
            from: 127.0.0.1, mime: multipart/form-data
            result: failed - There are problems with some of the provided values.
Error: There are problems with some of the provided values.
    at new SealiousErrors.Error (/home/arkadiusz/Projects/hello-world/node_modules/sealious/lib/response/error.js:6:12)
    at new SealiousErrors.ValidationError (/home/arkadiusz/Projects/hello-world/node_modules/sealious/lib/response/error.js:21:12)
    at /home/arkadiusz/Projects/hello-world/node_modules/sealious/lib/chip-types/resource-type.js:171:28
    at bound (domain.js:250:14)
    at runBound (domain.js:263:12)
    at tryCatcher (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/promise.js:503:31)
    at Promise._settlePromiseAt (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/promise.js:577:18)
    at Promise._settlePromises (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/promise.js:693:14)
    at Async._drainQueue (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/async.js:123:16)
    at Async._drainQueues (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/arkadiusz/Projects/hello-world/node_modules/sealious/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:371:17)
{
    "id": "ude30cvhhm",
    "type": "person",
    "body": {
        "name": "2",
        "age": 2,
        "lat": 2.4
    },
    "created_context": {
        "timestamp": 1445557957742,
        "ip": "127.0.0.1",
        "user_id": "neglxy1mn1"
    }
}

^^^

  1. I've created new resource
  2. Next, I've sent PATCH to resource of id ude30cvhhm (without "lat" field) <- it generated error.
arkadiusz-wieczorek commented 8 years ago

It's the change in our new api, because on sealious@0.4.9 in Placetag I sent PATCH without latitude and longitude fields for update place and it worked. At now I had to add latitude and longitude fields for success update.

kuba-orlik commented 8 years ago

I've written test cases that reproduce your issue and fixed it. Changes are now live on 0.6.16. Please check if the issue is fixed and reopen this issue if necessary.