11const db = require ( './db' ) ;
22const logger = require ( '../util/logger' ) ;
33
4- if ( ! String . prototype . splice ) {
5- /**
6- * {JSDoc}
7- *
8- * The splice() method changes the content of a string by removing a range of
9- * characters and/or adding new characters.
10- *
11- * @this {String}
12- * @param {number } start Index at which to start changing the string.
13- * @param {number } delCount An integer indicating the number of old chars to remove.
14- * @param {string } newSubStr The String that is spliced in.
15- * @return {string } A new string with the spliced substring.
16- */
4+ /*
5+ if (!String.prototype.splice) { //Needed?
176 String.prototype.splice = function(start, delCount, newSubStr) {
187 return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
198 };
209}
10+ */
2111
2212function getBotActionsAndResponses ( req , res , next ) {
23- logger . winston . info ( 'actions.getBotActions ' ) ;
13+ logger . winston . info ( 'actions.getBotActionsAndResponses ' ) ;
2414 db . all ( 'select * from actions where bot_id = ? order by action_id desc' , req . query . bot_id , function ( err , actions ) {
2515 if ( err ) {
26- logger . winston . info ( err ) ;
16+ logger . winston . error ( err ) ;
2717 } else {
2818 var actionIds = [ ] ;
2919 for ( var i = 0 ; i < actions . length ; i ++ ) {
@@ -32,7 +22,7 @@ function getBotActionsAndResponses(req, res, next) {
3222 if ( actionIds . length > 0 ) {
3323 db . all ( 'select * from responses where action_id in (' + actionIds . splice ( "," ) + ') order by action_id desc' , function ( err , responses ) {
3424 if ( err ) {
35- logger . winston . info ( err ) ;
25+ logger . winston . error ( err ) ;
3626 } else {
3727 res . status ( 200 ) . json ( [ { actions : actions , responses : responses } ] ) ;
3828 }
@@ -48,7 +38,7 @@ function createAction(req, res, next) {
4838 logger . winston . info ( 'actions.createAction' ) ;
4939 db . run ( 'insert into actions (action_name, bot_id)' + 'values (?,?)' , [ req . body . action_name , req . body . bot_id ] , function ( err ) {
5040 if ( err ) {
51- logger . winston . info ( "Error inserting a new record" ) ;
41+ logger . winston . error ( "Error inserting a new record" ) ;
5242 } else {
5343 res . status ( 200 ) . json ( { status : 'success' , message : 'Inserted' } ) ;
5444 }
@@ -60,7 +50,7 @@ function removeAction(req, res, next) {
6050 logger . winston . info ( 'actions..removeAction' ) ;
6151 db . run ( 'delete from actions where action_id = ?' , req . query . action_id , function ( err ) {
6252 if ( err ) {
63- logger . winston . info ( "Error removing the record" ) ;
53+ logger . winston . error ( "Error removing the record" ) ;
6454 } else {
6555 db . run ( 'delete from responses where action_id = ?' , req . query . action_id ) ;
6656 res . status ( 200 ) . json ( { status : 'success' , message : 'Removed' } ) ;
@@ -73,7 +63,7 @@ function updateAction(req, res, next) {
7363 logger . winston . info ( 'actions.updateAction' ) ;
7464 db . run ( 'update actions set action_name = ? where action_id = ?' , [ req . body . action_name , req . body . bot_id ] , function ( err ) {
7565 if ( err ) {
76- logger . winston . info ( "Error updating the record" ) ;
66+ logger . winston . error ( "Error updating the record" ) ;
7767 } else {
7868 res . status ( 200 ) . json ( { status : 'success' , message : 'Updated' } ) ;
7969 }
0 commit comments