@@ -82,6 +82,31 @@ exports.getEntries = function(filter, callback){
8282 } ) ;
8383} ;
8484
85+ exports . getEntry = function ( id , callback ) {
86+ pool . getConnection ( function ( error , connection ) {
87+ if ( error ) {
88+ console . log ( error ) ;
89+ callback ( true ) ;
90+ return ;
91+ }
92+
93+ let sql = 'SELECT * FROM entries WHERE id = ?' ;
94+
95+ connection . query ( sql , [ id ] , function ( error , result ) {
96+ connection . release ( ) ;
97+ if ( error ) {
98+ callback ( result , error ) ;
99+ return ;
100+ }
101+ if ( ! result || ! result . length ) {
102+ callback ( null , 'Entry with the specified id does not exist' ) ;
103+ return ;
104+ }
105+ callback ( result , false ) ;
106+ } ) ;
107+ } ) ;
108+ } ;
109+
85110exports . getUserByHash = function ( hash , callback ) {
86111 pool . getConnection ( function ( err , connection ) {
87112 if ( err ) { console . log ( err ) ; callback ( true ) ; return ; }
@@ -113,6 +138,27 @@ exports.verifyEntry = function(hash, callback){
113138 } ) ;
114139} ;
115140
141+ exports . deleteEntry = function ( id , callback ) {
142+ pool . getConnection ( function ( error , connection ) {
143+ if ( error ) {
144+ console . log ( error ) ;
145+ callback ( error ) ;
146+ return ;
147+ }
148+ let sql = "DELETE FROM entries WHERE id = ?" ;
149+
150+ // make the query
151+ connection . query ( sql , [ id ] , function ( error ) {
152+ connection . release ( ) ;
153+ if ( error ) {
154+ callback ( error ) ;
155+ return ;
156+ }
157+ callback ( false ) ;
158+ } ) ;
159+ } ) ;
160+ } ;
161+
116162exports . getCount = function ( callback ) {
117163 pool . getConnection ( function ( err , connection ) {
118164 if ( err ) { console . log ( err ) ; callback ( true ) ; return ; }
0 commit comments