1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00
OpenSTF/res/app/components/stf/user/group/group-service.js
2014-03-26 16:06:49 +09:00

41 lines
997 B
JavaScript

module.exports = function GroupServiceFactory(
socket
, TransactionService
) {
var groupService = {
}
groupService.invite = function (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) {
throw new Error('Device refused to join the group')
}
return results[0].device
})
}
groupService.kick = function (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) {
throw new Error('Device refused to be kicked from the group')
}
return results[0].device
})
}
return groupService
}