Pergunta

i can get the RSVP array of promises to work:

//if user wants to change username
var promises = [];

promises['username'] = new RSVP.Promise(function(resolve, reject){ 

 if(user.username !== session.username){

    //check if username is available
    $model_users.getBy({
      what:'id',
      where: " username = "+db.escape(user.username) +" AND id != "+ db.escape(session.id_user)
    })
    .then(function(results){

    if(!results || results.length <= 0){
      //update username is available
      $model_users.update({
        update:{username: db.escape(user.username)},
        where: " id = "+ db.escape(session.id_user)

      })
      .then(function(success){

        confirm.username = 'was_saved';

        resolve(success);

      },function(err){

        reject(err);

        console.log('db-error 55299 ' + err);
        res.send('db-error');
      });

    }else{
      validation.username = 'error_username_exists';
      resolve(validation);
      res.send({"validation":validation});
    }

    },function(err){

    reject(err);

    console.log('db-error 0299 ' + err);
    res.send('db-error');

    });

}else{
  reject('no username to update - is same to session username');
}

}

 //create new JWT and send it back to FE localSTorage
RSVP.all(promises).then(function(){

  $model_users.getBy({
      what:'id , username',
      where: " id = "+ db.escape(session.id_user)
    }).then(function(results){

      if(results && results.length > 0){
        //set new user session and token
        var auth = {};

        auth.username = results[0].username;
        auth.id_user = results[0].id;
        auth.session_token =  jwt.sign(auth, config.session_secret_key, { expiresInMinutes: config.session_expiration });

        res.send({"auth":auth,"confirm":confirm});

      }else{

      res.send('db-error');

      }

    },function(err){

     console.log('db-error 0.577 '+ err);
    });
});

the error returned is:

RSVP.all(promises).then(function(){
^^^^
SyntaxError: Unexpected identifier

How is his possible? i'm following the official doc https://github.com/tildeio/rsvp.js/#arrays-of-promises

I setted it on top of node app.js :

var RSVP = require('rsvp');

Foi útil?

Solução

You're missing a ) two lines above RSVP.all(promises)....

Consider using a linter, which will catch this sort of error immediately. See e.g. SublimeLinter.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top