nimblehq / nimble-survey-web

Nimble Survey API for Mobile Challenge and Certification
0 stars 3 forks source link

Fix: The "Survey list" API should not return the question id list relationship #70

Closed luongvo closed 2 years ago

luongvo commented 2 years ago

Issue

Currently, the "Survey list" API GET v1/surveys focuses on returning the list of survey info without containing the details about the question or answer data. However it's returning the question id list in relationship of the survey object without the included part.

This violates the JSON:API format and causes some unexpected issues when parsing this question relationship in client side.

{
    "data": [
        {
            "id": "d5de6a8f8f5f1cfe51bc",
            "type": "survey",
            "attributes": {
                "title": "Scarlett Bangkok",
                "description": "We'd love ot hear from you!",
                "thank_email_above_threshold": "...",
                "is_active": true,
                "cover_image_url": "https://dhdbhh0jsld0o.cloudfront.net/m/1ea51560991bcb7d00d0_",
                "created_at": "2017-01-23T07:48:12.991Z",
                "active_at": "2015-10-08T07:04:00.000Z",
                "inactive_at": null,
                "survey_type": "Restaurant"
            },
            "relationships": {
                "questions": {
                    "data": [
                        {
                            "id": "d3afbcf2b1d60af845dc",
                            "type": "question"
                        },
                        {
                            "id": "940d229e4cd87cd1e202",
                            "type": "question"
                        },
                        {
                            "id": "ea0555f328b3b0124127",
                            "type": "question"
                        },
                        {
                            "id": "16e68f5610ef0e0fa4db",
                            "type": "question"
                        },
                        {
                            "id": "bab38ad82eaf22afcdfe",
                            "type": "question"
                        },
                        {
                            "id": "85275a0bf28a6f3b1e63",
                            "type": "question"
                        },
                        {
                            "id": "642770376f7cd0c87d3c",
                            "type": "question"
                        },
                        {
                            "id": "b093a6ad9a6a466fa787",
                            "type": "question"
                        },
                        {
                            "id": "e593b2fa2f81891a2b1e",
                            "type": "question"
                        },
                        {
                            "id": "c3a9b8ce5c2356010703",
                            "type": "question"
                        },
                        {
                            "id": "fbf5d260de1ee6195473",
                            "type": "question"
                        },
                        {
                            "id": "4372463ce56db58c0983",
                            "type": "question"
                        }
                    ]
                }
            }
        },
        ...
    ],
    ...
}

Expected

We have another API GET v1/surveys/{survey_id} to return the full question and answer relationships, so GET v1/surveys should not return the above question id list relationship.

{
    "data": [
        {
            "id": "d5de6a8f8f5f1cfe51bc",
            "type": "survey",
            "attributes": {
                "title": "Scarlett Bangkok",
                "description": "We'd love ot hear from you!",
                "thank_email_above_threshold": "...",
                "is_active": true,
                "cover_image_url": "https://dhdbhh0jsld0o.cloudfront.net/m/1ea51560991bcb7d00d0_",
                "created_at": "2017-01-23T07:48:12.991Z",
                "active_at": "2015-10-08T07:04:00.000Z",
                "inactive_at": null,
                "survey_type": "Restaurant"
            },
            "relationships": {}
        },
        ...
    ],
    ...
}

Steps to reproduce

  1. Make a new request on GET v1/surveys API to see the response https://nimblehq.postman.co/workspace/Nimble~9daf6b25-882e-4ad0-8299-95529e2883ff/request/11835486-064357a5-4625-4ef7-b042-0d1f7e2f2acb
hoangmirs commented 2 years ago

@luongvo It seems this is not a bug. The resource object might contain relationships field, but there is no documentation that requires we have to add included field when there is an existing relationships field. But as we don't use the question information when requesting a survey list, so I think we can omit the relationships field. Will create a PR for that 🙏