Last active
June 24, 2016 20:33
-
-
Save raphaklaus/5514c465027b0a56a36a7d0e79fbf6ff to your computer and use it in GitHub Desktop.
This file contains 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