File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,6 +128,20 @@ exports.getCount = function(callback){
128128 } ) ;
129129} ;
130130
131+ exports . getCountries = function ( callback ) {
132+ pool . getConnection ( function ( err , connection ) {
133+ if ( err ) { console . log ( err ) ; callback ( true ) ; return ; }
134+
135+ let sql = "SELECT country, COUNT(id) AS number FROM entries WHERE country != '' GROUP BY country ORDER BY number DESC;" ;
136+
137+ connection . query ( sql , function ( err , results ) {
138+ connection . release ( ) ;
139+ if ( err ) { callback ( results , true ) ; return ; }
140+ callback ( results , false ) ;
141+ } ) ;
142+ } ) ;
143+ } ;
144+
131145exports . saveEntry = function ( fields , callback ) {
132146 pool . getConnection ( function ( err , connection ) {
133147 if ( err ) { console . log ( err ) ; callback ( true ) ; return ; }
Original file line number Diff line number Diff line change @@ -90,6 +90,19 @@ exports.getCount = function(req, res) {
9090 } ) ;
9191} ;
9292
93+ exports . getCountries = function ( req , res ) {
94+ db . getCountries ( function ( results , err ) {
95+ if ( ! err ) {
96+ res . status ( 200 ) . json ( {
97+ success : true ,
98+ countries : results
99+ } ) ;
100+ } else {
101+ res . status ( 400 ) . json ( { success : false , message : "error" } ) ;
102+ }
103+ } ) ;
104+ } ;
105+
93106exports . verifyEntry = function ( req , res ) {
94107 db . verifyEntry ( req . params . k , function ( results , err ) {
95108 if ( ! err ) {
Original file line number Diff line number Diff line change @@ -26,4 +26,5 @@ module.exports = function(app) {
2626 app . route ( '/entries' ) . post ( entryController . createEntry ) ;
2727 app . route ( '/entries/toggle' ) . post ( entryController . toggleStatus ) ;
2828 app . route ( '/entries' ) . get ( entryController . getAll ) ;
29+ app . route ( '/countries' ) . get ( entryController . getCountries ) ;
2930} ;
You can’t perform that action at this time.
0 commit comments