🐛 Fixed "undefined" values in member csv export

no issue

We missed handling `undefined` values for fields during csv export for memebrs, which causes csv entries as `undefined` for fields that don't exist. It also added need for extra handling of `undefined` entries during csv import. This PR fixes the bug by properly handling empty/undefined values in export
This commit is contained in:
Rish 2020-02-12 11:03:16 +05:30
parent 2c52282662
commit 4eeed0d32a
2 changed files with 7 additions and 4 deletions

View File

@ -18,8 +18,11 @@ const decorateWithSubscriptions = async function (member) {
});
};
// NOTE: this method should not exist at all and needs to be cleaned up
// it was created due to a bug in how CSV is currently created for exports
/** NOTE: this method should not exist at all and needs to be cleaned up
it was created due to a bug in how CSV is currently created for exports
Export bug was fixed in 3.6 but method exists to handle older csv exports with undefined
**/
const cleanupUndefined = (obj) => {
for (let key in obj) {
if (obj[key] === 'undefined') {
@ -31,7 +34,7 @@ const cleanupUndefined = (obj) => {
// NOTE: this method can be removed once unique constraints are introduced ref.: https://github.com/TryGhost/Ghost/blob/e277c6b/core/server/data/schema/schema.js#L339
const sanitizeInput = (members) => {
const customersMap = members.reduce((acc, member) => {
if (member.stripe_customer_id) {
if (member.stripe_customer_id && member.stripe_customer_id !== 'undefined') {
if (acc[member.stripe_customer_id]) {
acc[member.stripe_customer_id] += 1;
} else {

View File

@ -10,7 +10,7 @@ module.exports = function formatCSV(data, fields) {
for (i = 0; i < fields.length; i = i + 1) {
field = fields[i];
csv += entry[field] !== null ? entry[field] : '';
csv += (entry[field] !== null && entry[field] !== undefined) ? entry[field] : '';
if (i !== fields.length - 1) {
csv += ',';
}