mysql - sequelize - cannot read property catch of undefined -


i using sequelize mysql in project. current use case populating table 'roles_master' default roles.

the function createdefaultroles implementation checks:

  • if there rows in table
  • if yes, , force true, deletes existing rows , inserts new rows
  • if table empty, directly inserts new rows

my code below...

/**  *  creates pre-defined set of roles  *  if roles table exists , contains data,   *  function returns, without creating roles.  *  list of roles defined in file "ecp_db_defaults.js"  *  *  @param force -- boolean flag indicate whether drop existng roles , recreate afresh  **/ function createdefaultroles(force, callback) {   console.log("executing createdefaultroles...");   db.role.count().then(function(result) {     if (result>0) {       if (force) {         console.log("emptying roles table...");         db.role.destroy({force:true, where: {}}).then(function() {           db.role.bulkcreate(dbconfig.roles).done(function() {             console.log("1. created user roles.");             if (callback) return callback(null); else return;           }).catch(function(e){             console.log("error while creating roles...", e);             if (callback) return callback(e);           });         }).catch(function(e) {           console.error("error while destroying roles table.", e);           return (callback)?callback(e):e;         });       }       //if (callback) return callback(null); else return;      } else {       db.role.bulkcreate(dbconfig.roles).done(function(){         console.log("2. created user roles.");         if (callback) return callback(null);       })     }   }).catch(function(e){     console.error("error while querying roles table.", e);     if (callback) return callback(e);   }); } 

the problem that, works partially. while, able delete existing rows , add new ones, throws exception caught , printed below..

  • executing createdefaultroles...
  • emptying roles table... error while destroying roles table. [typeerror: cannot read property 'catch'of undefined]
    1. successfully created user roles.

finally, function fails, because of above error. have tried matching .then() , .catch() promises correctly. seem fine.

any in solving highly appreciated.

i guess problem in block

db.role.bulkcreate(dbconfig.roles).done(function() {             console.log("1. created user roles.");             if (callback) return callback(null); else return;           }).catch(function(e){             console.log("error while creating roles...", e);             if (callback) return callback(e);           }); 

since .done() returns undefined cannot append 'catch' on this. if replace .done .then should work expected


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -