Thanks to visit codestin.com
Credit goes to github.com

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

Commit d93d4e2

Browse files
authored
Merge pull request #206 from Wardormeur/bugfix/1276-export-email-dojo-session
Bugfix/1276 export email dojo session
2 parents 1cf9220 + 1ccab39 commit d93d4e2

1 file changed

Lines changed: 39 additions & 22 deletions

File tree

lib/export-guest-list.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function exportGuestList (args, callback) {
1212

1313
async.waterfall([
1414
retrieveUserData,
15-
convertToCSV
15+
format,
1616
], function (err, csv) {
1717
if (err) return callback(null, {error: err});
1818
return callback(null, {
@@ -33,34 +33,51 @@ function exportGuestList (args, callback) {
3333
if (err) return callback(err);
3434
async.mapSeries(applications, function (application, cb) {
3535
seneca.act({role: 'cd-profiles', cmd: 'list', query: {userId: application.userId}}, function (err, profiles) {
36-
if (err) return cb(err);
36+
if (err) return callback(err);
3737
var userProfile = profiles[0];
38-
seneca.act({role: plugin, cmd: 'loadSession', id: application.sessionId}, function (err, session) {
39-
if (err) return cb(err);
40-
var user = {};
41-
user['Session'] = session.name;
42-
user['Name'] = userProfile.name;
43-
user['Phone'] = userProfile.phone || '';
44-
user['Email'] = userProfile.email || '';
45-
user['Ticket Name'] = application.ticketName;
46-
user['Ticket Type'] = application.ticketType;
47-
48-
user['Status'] = application.status;
49-
if(application.status === 'pending') {
50-
user['Status'] = 'waiting';
51-
}
52-
return cb(null, user);
53-
});
38+
if (!userProfile.email || userProfile.email.trim().length === 0) {
39+
application.userProfile = userProfile;
40+
seneca.act({ role: 'cd-profiles', cmd: 'load_parents_for_user', userId: userProfile.userId, user: args.user }, function (err, parentProfile) {
41+
if (err) callback(err);
42+
if (parentProfile.length > 0) {
43+
const firstParent = parentProfile[0];
44+
application.userProfile.email = firstParent.email;
45+
application.userProfile.phone = application.userProfile.phone || firstParent.phone;
46+
}
47+
cb(null, application);
48+
});
49+
} else {
50+
cb(null, application);
51+
}
5452
});
55-
}, function (err, csvData) {
53+
}, function (err, rows) {
5654
if (err) return callback(null, {error: err});
57-
return done(null, csvData);
55+
return done(null, rows);
5856
});
5957
});
6058
}
6159

62-
function convertToCSV (csvData, done) {
63-
json2csv({data: csvData, fields: csvFields}, done);
60+
function format(applications, done) {
61+
async.mapSeries(applications, function (application, cb) {
62+
seneca.act({role: plugin, cmd: 'loadSession', id: application.sessionId}, function (err, session) {
63+
if (err) return callback(err);
64+
var user = {};
65+
user['Session'] = session.name;
66+
user['Name'] = application.userProfile.name;
67+
user['Phone'] = application.userProfile.phone || '';
68+
user['Email'] = application.userProfile.email || '';
69+
user['Ticket Name'] = application.ticketName;
70+
user['Ticket Type'] = application.ticketType;
71+
72+
user['Status'] = application.status;
73+
if(application.status === 'pending') {
74+
user['Status'] = 'waiting';
75+
}
76+
cb(null, user);
77+
})
78+
}, function (err, rows) {
79+
json2csv({data: rows, fields: csvFields}, done);
80+
});
6481
}
6582
}
6683

0 commit comments

Comments
 (0)