Created
June 24, 2016 20:36
-
-
Save raphaklaus/d3c8686ba5d9f5309487d6cdc0aaafad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Inviter { | |
constructor() { | |
// this.groupId = groupId; | |
// this.userId = userId; | |
this.GruposPool = bookshelf.Model.extend({ | |
tableName: 'MensageriaExternaGrupoPool' | |
}); | |
bookshelf.transaction((t) => { | |
new this.GruposPool().where({disponivel: true}).orderBy('id', 'ASC').fetchAll().then(grupos => { | |
if (grupos.toJSON().length > 0) { | |
let grupo = grupos.last().toJSON(); | |
return new this.GruposPool({id: grupo.id}).save({disponivel: false}, | |
{transacting: t, patch: true}); | |
} else { | |
logger.info('There are no groups available. ' + | |
'Update not executed.'); | |
} | |
}) | |
.then((savedModel) => { | |
logger.info('Done!'); | |
t.commit(savedModel); | |
}) | |
.catch(error => { | |
logger.info(`Rollback! ${error}`); | |
t.rollback(error); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment