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

Bugfix/1276 export email dojo session #206

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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