Zendro-dev / graphql-server

Skeleton NodeJS project for a graphQL server.
GNU General Public License v3.0
0 stars 1 forks source link

Enable the tabular streamed bulk creation from uploaded CSV files to assign NULL values #14

Closed asishallab closed 5 years ago

asishallab commented 5 years ago

In the respective helper method that streams uploaded data tables (CSV) enable the conversion of string "NULL" or "null" values to natural (true) Javascript null values.

This enables the user to actually leave some attributes empty.

Consider something like the following pseudo-code that can be used to post-process the objects that are going to be passed to the respective create function.

/**
 * Function replaces all String values "NULL" or "null" in the argument plain
 * old JavaScript object (POJO) with literal null.
 *
 * @param {Object} pojo - A plain old JavaScript object.
 *
 * @return {Object} A modified clone of the argument pojo in which all String
 * "NULL" or "null" values are replaced with literal nulls.
 */
exports.replacePojoNullValueWithLiteralNull = function(pojo) {
  if (pojo === null) {
    return null
  }
  let res = Object.assign({}, pojo)
  Object.keys(res).forEach((k) => {
    if (res[k] === 'NULL' || res[k] === 'null') {
      res[k] = null
    }
  })
  return res
}

Please include integration tests.

Expected work time: 4h