nordnet / nordnet-next-api

Nordnet nExt API Javascript client
27 stars 11 forks source link

Bugfix - the number zero is a valid parameter in path #20

Closed codler closed 6 years ago

codler commented 6 years ago
export const getPortfolioSuggestion = score => ({
  type: SOME_TYPE,
  fetch: {
    method: 'get',
    url: '/api-url/{score}',
    params: {
      score,
    },
  },
});

dispatch(getPortfolioSuggestion(0)); // This always failed and throws "Params object doesn't have all required keys for url"

This PR fix so you can send zero as a parameter

JCB-K commented 6 years ago

Isn't it expected behaviour that sending in an integer as a url param fails? Sending in 0 as a string instead should work, since Boolean(!'0') === true.

bstream commented 6 years ago

@JCB-K I am not sure about expected behaviour or not but in the example posted above it makes sense to be able send in { score: 0 }. Maybe the solution then is to make an explicit typeof var !== 'undefined'. Then we will allow these falsy values as values for params:

false
null
undefined
0
NaN
''
""
codler commented 6 years ago

Agree with @bstream , it would be strange to only accept strings in params

JCB-K commented 6 years ago

Yeah I suppose it's useful to do all typecasting within this repo, so you can send in whatever you want. Man, I wish we were using Flow or Typescript :)

codler commented 6 years ago

@JCB-K TypeScript 👍

iamstarkov commented 6 years ago

@codler nay, if we go into types, then Flow