Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #206 from Wardormeur/bugfix/1276-export-email-dojo…
Browse files Browse the repository at this point in the history
…-session

Bugfix/1276 export email dojo session
  • Loading branch information
ArayB authored Feb 13, 2020
2 parents 1cf9220 + 1ccab39 commit d93d4e2
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions lib/export-guest-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function exportGuestList (args, callback) {

async.waterfall([
retrieveUserData,
convertToCSV
format,
], function (err, csv) {
if (err) return callback(null, {error: err});
return callback(null, {
Expand All @@ -33,34 +33,51 @@ function exportGuestList (args, callback) {
if (err) return callback(err);
async.mapSeries(applications, function (application, cb) {
seneca.act({role: 'cd-profiles', cmd: 'list', query: {userId: application.userId}}, function (err, profiles) {
if (err) return cb(err);
if (err) return callback(err);
var userProfile = profiles[0];
seneca.act({role: plugin, cmd: 'loadSession', id: application.sessionId}, function (err, session) {
if (err) return cb(err);
var user = {};
user['Session'] = session.name;
user['Name'] = userProfile.name;
user['Phone'] = userProfile.phone || '';
user['Email'] = userProfile.email || '';
user['Ticket Name'] = application.ticketName;
user['Ticket Type'] = application.ticketType;

user['Status'] = application.status;
if(application.status === 'pending') {
user['Status'] = 'waiting';
}
return cb(null, user);
});
if (!userProfile.email || userProfile.email.trim().length === 0) {
application.userProfile = userProfile;
seneca.act({ role: 'cd-profiles', cmd: 'load_parents_for_user', userId: userProfile.userId, user: args.user }, function (err, parentProfile) {
if (err) callback(err);
if (parentProfile.length > 0) {
const firstParent = parentProfile[0];
application.userProfile.email = firstParent.email;
application.userProfile.phone = application.userProfile.phone || firstParent.phone;
}
cb(null, application);
});
} else {
cb(null, application);
}
});
}, function (err, csvData) {
}, function (err, rows) {
if (err) return callback(null, {error: err});
return done(null, csvData);
return done(null, rows);
});
});
}

function convertToCSV (csvData, done) {
json2csv({data: csvData, fields: csvFields}, done);
function format(applications, done) {
async.mapSeries(applications, function (application, cb) {
seneca.act({role: plugin, cmd: 'loadSession', id: application.sessionId}, function (err, session) {
if (err) return callback(err);
var user = {};
user['Session'] = session.name;
user['Name'] = application.userProfile.name;
user['Phone'] = application.userProfile.phone || '';
user['Email'] = application.userProfile.email || '';
user['Ticket Name'] = application.ticketName;
user['Ticket Type'] = application.ticketType;

user['Status'] = application.status;
if(application.status === 'pending') {
user['Status'] = 'waiting';
}
cb(null, user);
})
}, function (err, rows) {
json2csv({data: rows, fields: csvFields}, done);
});
}
}

Expand Down

0 comments on commit d93d4e2

Please sign in to comment.