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

(page) links not serialized properly when one of the params is a date #724

Open
nickschot opened this issue Oct 11, 2017 · 2 comments
Open

Comments

@nickschot
Copy link
Contributor

  • Platform: macOS 10.13
  • Database: Postgres 9.6
  • Lux Version: 1.2.2
  • Node Version: 8.6.0

Requesting a resource with a link like /my-resource?forDate=2017-10-11T00:00:00.000Z&filter[id]=123,124 gives a Date object for the forDate param. Currently the create-query-string function has no knowledge of correctly serializing a date which results in a page link like: /my-resource?&filter[id]=123,124 which is invalid.

Can be solved by modifying create-page-links to:

if (value && typeof value === 'object') {
      if (Array.isArray(value)) {
        result += value.map(encodeURIComponent).join();
      } else if(value instanceof Date) {
        result += value.toISOString();
      } else {
        result = (
          result.substr(0, result.length - (key.length + 1))
          + createQueryString(value, key)
        );
      }
    } else if (!value && typeof value !== 'number') {
      result += 'null';
    } else {
      result += encodeURIComponent(value);
    }
}

This does expect the user to use ISO8601 dates.

@nickschot
Copy link
Contributor Author

Any ideas are welcome @zacharygolba . I can make a PR if you approve of the solution. I'm still a bit in doubt whether or not to make the assumption of an ISO8601 date.

@nickschot
Copy link
Contributor Author

Would need a "back" port to master as well, as I see the implementation has changed.

@nickschot nickschot changed the title [bug] (page) links not serialized properly when one of the params is a date (page) links not serialized properly when one of the params is a date Oct 24, 2017
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

No branches or pull requests

1 participant