@@ -12,7 +12,7 @@ function exportGuestList (args, callback) {
1212
1313 async . waterfall ( [
1414 retrieveUserData ,
15- format ,
15+ convertToCSV
1616 ] , function ( err , csv ) {
1717 if ( err ) return callback ( null , { error : err } ) ;
1818 return callback ( null , {
@@ -33,51 +33,34 @@ 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 callback ( err ) ;
36+ if ( err ) return cb ( err ) ;
3737 var userProfile = profiles [ 0 ] ;
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- }
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+ } ) ;
5254 } ) ;
53- } , function ( err , rows ) {
55+ } , function ( err , csvData ) {
5456 if ( err ) return callback ( null , { error : err } ) ;
55- return done ( null , rows ) ;
57+ return done ( null , csvData ) ;
5658 } ) ;
5759 } ) ;
5860 }
5961
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- } ) ;
62+ function convertToCSV ( csvData , done ) {
63+ json2csv ( { data : csvData , fields : csvFields } , done ) ;
8164 }
8265}
8366
0 commit comments