feedhenry / fh-db

Apache License 2.0
1 stars 16 forks source link

[WIP] Add date support for read #43

Closed mmurphy closed 5 years ago

mmurphy commented 5 years ago

Jira link(s)

https://issues.jboss.org/browse/RHMAP-21771

What

When a date field is present in a document in a collection in RHMAP, altering the document manually in the data browser directly in studio causes the date field to be saved as type string instead of type Date. This can effect how the field is used in its app (e.g. When the field is used as search criteria during a database search).

Why

All Date formats are getting saved as Strings when a user edits a row in the databrowser.

How

Allow Date objects in the database to be transferred and displayed/saved in DateBrowser as javascript objects as follows:

{
   $fhdate: "2018-10-10T11:54:12.366Z"
}

fh.db will check for $fhdate and save the field type as a Date in the database.

To read the fields from the database in the same format. The environment variable needs to be set in the app.

process.env.SERIALISE_FH_DATES=true

Verification Steps

Note:

  1. Check value types are all Dates (see note above)
  2. Go to https://support.eu.feedhenry.com/#projects/ng463isi7so2jzakpoort72q/apps/ng463itjv42t2myz6jnpkjzw/databrowser . Edit a row and save.
  3. Check value types, one should now be a string.
  4. go to databrowser and click advanced editor on any row. Click raw and change the "when" key and value to "when": {"$fhdate", "2018-10-15T15:49:09.746Z"},. Click save
  5. Check value types, the saved row should be a Date
  6. Go to environment variables and add a new env var with the name SERIALISE_FH_DATES and value true.
  7. All Dates in the databrowser should now show as Objects and can only be edited in advanced editor mode
  8. Edit dates and check the value types to ensure they stay as Dates.

Checklist:

mmurphy commented 5 years ago

@davidffrench @camilamacedo86 can you review?