Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix form responses giving error and not inserting values when the boolean value is false #156

Merged
merged 5 commits into from
May 22, 2024

Conversation

cherylli
Copy link
Contributor

@cherylli cherylli commented May 22, 2024

Description

When response is false, the validation pipe returns an error and the boolean value is also not inserted into the database properly

This is a new PR after renaming #154 as the branch name was causing issue for some members

Issue link

Fixes # (issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature updates / changes
  • Tests
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

ran all the tests, send request from swagger and verified the values in the database

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have updated the change log

@cherylli cherylli added the bug label May 22, 2024
@cherylli cherylli self-assigned this May 22, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
@cherylli
Copy link
Contributor Author

New PR for #154 (branch rename)

@cherylli cherylli changed the title Fix/form response boolean Fix form responses giving error and not inserting values when the boolean value is false May 22, 2024
Copy link
Contributor

@Ajen07 Ajen07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests works fine . No error when the response is false and database is correctly updated for false values

Copy link
Contributor

@JoshuaHinman JoshuaHinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests passed and boolean false verified with swagger and prisma studio. One thing I was curious about: in the responseDtoToArray function, when pushing to the responsesArray, what do the spread operators do?

@cherylli
Copy link
Contributor Author

cherylli commented May 22, 2024

Tests passed and boolean false verified with swagger and prisma studio. One thing I was curious about: in the responseDtoToArray function, when pushing to the responsesArray, what do the spread operators do?

@JoshuaHinman
Thanks for asking the question, I don't remember why I did that it seemed natural to me at the point, but then I did some research, it seems, with the spread operator, you can conditionally set the values
without spread operator, all have to be included in the push vs the alternative

for (const index in responses) {
    if (responseIndex.includes(index)) {
        responses[index].forEach((v: FormResponseDto) => {
            responsesArray.push({
                questionId: v.questionId,
                text: v.text,
                numeric: v.numeric,
                boolean: v.boolean,
                optionChoiceId: v.optionChoiceId,
            });
        });
    }
}

which probably did not matter if we have all these values inserted into the database (including nulls), I was trying to convert into the same structure as the input, but I think empty values are undefined coming from the res body, so I don't think we could just leave it as undefined as we can insert null into the database but not undefined(not tested, just my theory)

@cherylli cherylli merged commit 010170d into dev May 22, 2024
1 check passed
@cherylli cherylli deleted the fix/form-response-boolean branch May 22, 2024 23:51
@JoshuaHinman
Copy link
Contributor

it seems, with the spread operator, you can conditionally set the values
Thank you for explaining this - I don't recall seeing it before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants