Convert query string to date object
up vote
1
down vote
favorite
I have a GET
endpoint/internal/users?role=057426a1235fa1084c6f&lastLoggedIn[$lte]=2018-11-07T22:57:44.612Z
I am using featherjs and feathers-rest client to call my services.
My problem is I get the req.query as
role: '057426a1235fa1084c6f',
lastLogged: $lte: '2018-11-07T22:57:44.612Z'
and I am getting date as string not date object.
is there any way I can transform my query to have the correct date object if I encountered any ISODate string?
I have tried something like
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
This is working fine, but is there any way I can pass to qs.parser
which can automatically convert date string to date Object?
express query-string feathersjs
add a comment |
up vote
1
down vote
favorite
I have a GET
endpoint/internal/users?role=057426a1235fa1084c6f&lastLoggedIn[$lte]=2018-11-07T22:57:44.612Z
I am using featherjs and feathers-rest client to call my services.
My problem is I get the req.query as
role: '057426a1235fa1084c6f',
lastLogged: $lte: '2018-11-07T22:57:44.612Z'
and I am getting date as string not date object.
is there any way I can transform my query to have the correct date object if I encountered any ISODate string?
I have tried something like
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
This is working fine, but is there any way I can pass to qs.parser
which can automatically convert date string to date Object?
express query-string feathersjs
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a GET
endpoint/internal/users?role=057426a1235fa1084c6f&lastLoggedIn[$lte]=2018-11-07T22:57:44.612Z
I am using featherjs and feathers-rest client to call my services.
My problem is I get the req.query as
role: '057426a1235fa1084c6f',
lastLogged: $lte: '2018-11-07T22:57:44.612Z'
and I am getting date as string not date object.
is there any way I can transform my query to have the correct date object if I encountered any ISODate string?
I have tried something like
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
This is working fine, but is there any way I can pass to qs.parser
which can automatically convert date string to date Object?
express query-string feathersjs
I have a GET
endpoint/internal/users?role=057426a1235fa1084c6f&lastLoggedIn[$lte]=2018-11-07T22:57:44.612Z
I am using featherjs and feathers-rest client to call my services.
My problem is I get the req.query as
role: '057426a1235fa1084c6f',
lastLogged: $lte: '2018-11-07T22:57:44.612Z'
and I am getting date as string not date object.
is there any way I can transform my query to have the correct date object if I encountered any ISODate string?
I have tried something like
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
This is working fine, but is there any way I can pass to qs.parser
which can automatically convert date string to date Object?
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
app.use((req, res, next) =>
const queryFlat = flat(req.query);
for (key in queryFlat)
queryFlat[key] = dateCheck(queryFlat[key]) // dateCheck returns date object if ISODate String
req.query = unlfat(queryFlat)
);
express query-string feathersjs
express query-string feathersjs
edited Nov 7 at 23:21
Shankar Regmi
522213
522213
asked Nov 7 at 23:18
Harish Paudel
16629
16629
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
I think your flat
and unflat
can have problem if you pass some query with keys containing .
itself.
so, this can help,
using qs library
app.use(req, res, next) =>
req.query = qs.parse(qs.stringify(req.query),
decoder: dateCheck, // dateCheck returns date object if ISODate String
);
Your dateCheck function should be something like this
const dateCheck = (value, decoder) =>
const key = decoder(value); // this
// ... rest of date check function
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I think your flat
and unflat
can have problem if you pass some query with keys containing .
itself.
so, this can help,
using qs library
app.use(req, res, next) =>
req.query = qs.parse(qs.stringify(req.query),
decoder: dateCheck, // dateCheck returns date object if ISODate String
);
Your dateCheck function should be something like this
const dateCheck = (value, decoder) =>
const key = decoder(value); // this
// ... rest of date check function
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
add a comment |
up vote
1
down vote
accepted
I think your flat
and unflat
can have problem if you pass some query with keys containing .
itself.
so, this can help,
using qs library
app.use(req, res, next) =>
req.query = qs.parse(qs.stringify(req.query),
decoder: dateCheck, // dateCheck returns date object if ISODate String
);
Your dateCheck function should be something like this
const dateCheck = (value, decoder) =>
const key = decoder(value); // this
// ... rest of date check function
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I think your flat
and unflat
can have problem if you pass some query with keys containing .
itself.
so, this can help,
using qs library
app.use(req, res, next) =>
req.query = qs.parse(qs.stringify(req.query),
decoder: dateCheck, // dateCheck returns date object if ISODate String
);
Your dateCheck function should be something like this
const dateCheck = (value, decoder) =>
const key = decoder(value); // this
// ... rest of date check function
I think your flat
and unflat
can have problem if you pass some query with keys containing .
itself.
so, this can help,
using qs library
app.use(req, res, next) =>
req.query = qs.parse(qs.stringify(req.query),
decoder: dateCheck, // dateCheck returns date object if ISODate String
);
Your dateCheck function should be something like this
const dateCheck = (value, decoder) =>
const key = decoder(value); // this
// ... rest of date check function
edited Nov 10 at 14:06
answered Nov 10 at 14:00
Shankar Regmi
522213
522213
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
add a comment |
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
perfect, it works as expected
– Harish Paudel
Nov 10 at 14:06
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53199364%2fconvert-query-string-to-date-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown