"use strict";

module.exports = jsonTransformPlugin;

function jsonTransformPlugin(schema) {
  schema.set('toJSON', {transform: fixDates});
  schema.set('toObject', {transform: fixDates});
}

function fixDates(doc, ret, options) {
  ['start_date', 'end_date', 'birth_date', 'death_date', 'founding_date', 'dissolution_date'].forEach(function(field) {
    if (!ret[field]) {
      ret[field] = null;
    }

  });
  return ret;
}

"use strict";

module.exports = jsonTransformPlugin;

function jsonTransformPlugin(schema) {
  schema.set('toJSON', {transform: fixDates, getters: true});
  schema.set('toObject', {transform: fixDates, getters: true});
}

function fixDates(doc, ret, options) {
  ['start_date', 'end_date', 'birth_date', 'death_date', 'founding_date', 'dissolution_date'].forEach(function(field) {
    if (!ret[field]) {
      ret[field] = null;
    }

  });
  return ret;
}

Make sure translations are applied when converting to JSON
Make sure translations are applied when converting to JSON

set getters to true which makes sure the decorated get is called when
running toJSON and hence the output is translated. Required to make sure
the JS version used in templates for things like adding memberships is
translated
