Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed issue with banktransfers fromXML function, updated tests to pas…
…s above 80%
- Loading branch information
Jordan Walsh
committed
Feb 21, 2017
1 parent
f947ece
commit 2b8b65a
Showing
4 changed files
with
138 additions
and
80 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,63 @@ | ||
var _ = require('lodash') | ||
, Entity = require('./entity') | ||
, logger = require('../logger') | ||
, ContactSchema = require('./contact').ContactSchema | ||
, Contact = require('./contact') | ||
, LineItemSchema = require('./shared').LineItemSchema | ||
var _ = require('lodash'), | ||
Entity = require('./entity'), | ||
logger = require('../logger'), | ||
ContactSchema = require('./contact').ContactSchema, | ||
Contact = require('./contact'), | ||
LineItemSchema = require('./shared').LineItemSchema | ||
|
||
var BankTransferSchema = new Entity.SchemaObject({ | ||
FromBankAccount: { | ||
type: { | ||
AccountID: {type: String, toObject: 'always'} | ||
AccountID: { type: String, toObject: 'always' }, | ||
Code: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' } | ||
}, | ||
toObject: 'always' | ||
}, | ||
ToBankAccount: { | ||
type: { | ||
AccountID: {type: String, toObject: 'always'} | ||
AccountID: { type: String, toObject: 'always' }, | ||
Code: { type: String, toObject: 'always' }, | ||
Name: { type: String, toObject: 'always' } | ||
}, | ||
toObject: 'always' | ||
}, | ||
Date: {type: String, toObject: 'always'}, | ||
Amount: {type: String, toObject: 'always'} | ||
Date: { type: String, toObject: 'always' }, | ||
Amount: { type: String, toObject: 'always' }, | ||
BankTransferID: { type: String, toObject: 'hasValue' }, | ||
CurrencyRate: { type: String, toObject: 'hasValue' }, | ||
FromBankTransactionID: { type: String, toObject: 'hasValue' }, | ||
ToBankTransactionID: { type: String, toObject: 'hasValue' }, | ||
HasAttachments: { type: Boolean, toObject: 'hasValue' }, | ||
CreatedDateUTC: { type: String, toObject: 'hasValue' } | ||
}); | ||
|
||
/** | ||
<BankTransfers> | ||
<BankTransfer> | ||
<FromBankAccount> | ||
<Code>090</Code> | ||
</FromBankAccount> | ||
<ToBankAccount> | ||
<Code>091</Code> | ||
</ToBankAccount> | ||
<Amount>20.00</Amount> | ||
</BankTransfer> | ||
</BankTransfers> | ||
*/ | ||
var BankTransfer = Entity.extend(BankTransferSchema, { | ||
constructor: function (application, data, options) | ||
{ | ||
constructor: function(application, data, options) { | ||
logger.debug('BankTransfer::constructor'); | ||
this.Entity.apply(this, arguments); | ||
}, | ||
initialize: function (data, options) | ||
{ | ||
}, | ||
changes: function (options) | ||
{ | ||
initialize: function(data, options) {}, | ||
changes: function(options) { | ||
return this._super(options); | ||
}, | ||
_toObject: function (options) | ||
{ | ||
_toObject: function(options) { | ||
return this._super(options); | ||
}, | ||
fromXmlObj: function (obj) | ||
{ | ||
fromXmlObj: function(obj) { | ||
_.extend(this, obj); | ||
return this; | ||
}, | ||
toXml: function () | ||
{ | ||
toXml: function() { | ||
var transaction = _.omit(this.toObject()); | ||
transaction.FromBankAccount = this.FromBankAccount.toObject(); | ||
transaction.ToBankAccount = this.ToBankAccount.toObject(); | ||
return this.application.js2xml(transaction, 'BankTransfer'); | ||
}, | ||
save:function(cb) | ||
{ | ||
save: function(cb) { | ||
var xml = '<BankTransfers>' + this.toXml() + '</BankTransfers>'; | ||
//console.log(xml); | ||
//cb(); | ||
return this.application.putOrPostEntity('put', 'BankTransfers', xml, {}, cb); | ||
return this.application.putOrPostEntity('put', 'BankTransfers', xml, {}, cb); | ||
} | ||
}); | ||
|
||
module.exports = BankTransfer; | ||
module.exports = BankTransfer; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,35 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, BankTransfer = require('../entities/banktransfer') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
BankTransfer = require('../entities/banktransfer'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var BankTransfers = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'BankTransfer', entityPlural:'BankTransfers'}, options)); | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options)); | ||
}, | ||
newBankTransfer: function (data, options) | ||
{ | ||
newBankTransfer: function(data, options) { | ||
return new BankTransfer(this.application, data, options) | ||
}, | ||
newBankTransfers: function (data) | ||
{ | ||
newBankTransfers: function(data) { | ||
var that = this; | ||
return _.map(data, function(item){ | ||
return _.map(data, function(item) { | ||
return new BankTransfer(that.application, item, {}); | ||
}); | ||
}, | ||
saveAll: function(data, cb){ | ||
var transactionXml = ''; | ||
data.forEach(function(transaction){ | ||
transactionXml += transaction.toXml(); | ||
}); | ||
var xml = '<BankTransfers>' + transactionXml + '</BankTransfers>'; | ||
return this.application.putOrPostEntity('put', 'BankTransfers', xml, {}, cb); | ||
}, | ||
getBankTransfer: function (id, modifiedAfter) | ||
{ | ||
return this.getBankTransfers({ id: id, modifiedAfter: modifiedAfter}) | ||
.then(function (bankTransfers) | ||
{ | ||
getBankTransfer: function(id, modifiedAfter) { | ||
return this.getBankTransfers({ id: id, modifiedAfter: modifiedAfter }) | ||
.then(function(bankTransfers) { | ||
return _.first(bankTransfers); | ||
}) | ||
}, | ||
createBankTransfers: function (BankTransfers, options) | ||
{ | ||
|
||
}, | ||
getBankTransfers: function (options) | ||
{ | ||
getBankTransfers: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newBankTransfer(data)}; | ||
clonedOptions.entityConstructor = function(data) { return self.newBankTransfer(data) }; | ||
return this.getEntities(clonedOptions) | ||
} | ||
}) | ||
|
||
module.exports = BankTransfers; | ||
|
||
module.exports = BankTransfers; |
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