Refactor installation to work out a few bugs and to make it cleaner. Transactions now reject on fail-responses, still need to update other places.

This commit is contained in:
Simo Kinnunen
2014-09-04 19:40:54 +09:00
parent f91bf901fa
commit c5a4727ae3
7 changed files with 159 additions and 233 deletions

View File

@@ -1,7 +1,7 @@
var Promise = require('bluebird')
var uuid = require('node-uuid')
module.exports = function TransactionServiceFactory(socket) {
module.exports = function TransactionServiceFactory(socket, TransactionError) {
var transactionService = {}
function createChannel() {
@@ -126,20 +126,21 @@ module.exports = function TransactionServiceFactory(socket) {
if (seq === last) {
result.success = message.success
if (message.success) {
if (message.data) {
result.lastData = result.data[seq] = message.data
}
}
else {
result.lastData = result.error = message.data
}
if (message.body) {
result.body = JSON.parse(message.body)
}
resolver.resolve(result)
if (result.success) {
if (message.data) {
result.lastData = result.data[seq] = message.data
}
resolver.resolve(result)
}
else {
result.lastData = result.error = message.data
resolver.reject(new TransactionError(result))
}
return
}
else {
@@ -196,6 +197,9 @@ module.exports = function TransactionServiceFactory(socket) {
this.device = this.source
}
DeviceTransactionResult.prototype = Object.create(TransactionResult)
DeviceTransactionResult.constructor = DeviceTransactionResult
transactionService.create = function(target, options) {
if (options && !options.result) {
options.result = TransactionResult
@@ -234,7 +238,5 @@ module.exports = function TransactionServiceFactory(socket) {
})
}
transactionService.TransactionResult = TransactionResult
return transactionService
}