Make TransactionService a bit more convenient for single-device use cases.

This commit is contained in:
Simo Kinnunen
2014-03-27 12:03:21 +09:00
parent c945a460e7
commit c0dbba8471
4 changed files with 64 additions and 26 deletions

View File

@@ -6,34 +6,34 @@ module.exports = function GroupServiceFactory(
}
groupService.invite = function (device) {
var tx = TransactionService.create([device])
var tx = TransactionService.create(device)
socket.emit('group.invite', device.channel, tx.channel, {
serial: {
value: device.serial
, match: 'exact'
}
})
return tx.promise.then(function(results) {
if (!results[0].success) {
return tx.promise.then(function(result) {
if (!result.success) {
throw new Error('Device refused to join the group')
}
return results[0].device
return result.device
})
}
groupService.kick = function (device) {
var tx = TransactionService.create([device])
var tx = TransactionService.create(device)
socket.emit('group.kick', device.channel, tx.channel, {
serial: {
value: device.serial
, match: 'exact'
}
})
return tx.promise.then(function(results) {
if (!results[0].success) {
return tx.promise.then(function(result) {
if (!result.success) {
throw new Error('Device refused to be kicked from the group')
}
return results[0].device
return result.device
})
}