Skip to content

Commit

Permalink
Merged dabvidbanhan-less-lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 8, 2017
2 parents f732c5e + 560950b commit 619146e
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
.DS_Store
.vscode
testing_config.json
sample_app/config/config.json
14 changes: 7 additions & 7 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Batch(application) {
this._operations = [];
}

_.extend(Batch.prototype, {
Object.assign(Batch.prototype, {
get: function() {

},
Expand Down Expand Up @@ -61,7 +61,7 @@ function Application(options) {

Application.extend = extend;

_.extend(Application, {
Object.assign(Application, {
defaults: {
baseUrl: 'https://api.xero.com',
consumerSecret: '',
Expand All @@ -76,7 +76,7 @@ _.extend(Application, {
}
})

_.extend(Application.prototype, {
Object.assign(Application.prototype, {
init: function() {
if (this.options["runscopeBucketId"] && this.options["runscopeBucketId"] !== "") {
this.options.baseUrl = "https://api-xero-com-" + this.options["runscopeBucketId"] + ".runscope.net";
Expand Down Expand Up @@ -423,7 +423,7 @@ _.extend(Application.prototype, {
var PrivateApplication = Application.extend({
constructor: function(config) {
logger.debug('PrivateApplication::constructor');
Application.call(this, _.extend({}, config, { type: 'private' }));
Application.call(this, Object.assign({}, config, { type: 'private' }));
},
init: function() {
Application.prototype.init.apply(this, arguments);
Expand Down Expand Up @@ -485,7 +485,7 @@ var RequireAuthorizationApplication = Application.extend({
});
},
buildAuthorizeUrl: function(requestToken, other) {
var q = _.extend({}, { oauth_token: requestToken }, other);
var q = Object.assign({}, { oauth_token: requestToken }, other);
return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q);
},
setOptions: function(options) {
Expand All @@ -498,7 +498,7 @@ var RequireAuthorizationApplication = Application.extend({
var PublicApplication = RequireAuthorizationApplication.extend({
constructor: function(config) {
logger.debug('PublicApplication::constructor');
RequireAuthorizationApplication.call(this, _.extend({}, config, { type: 'public' }));
RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'public' }));
},
init: function() {
RequireAuthorizationApplication.prototype.init.apply(this, arguments);
Expand All @@ -518,7 +518,7 @@ var PublicApplication = RequireAuthorizationApplication.extend({
var PartnerApplication = RequireAuthorizationApplication.extend({
constructor: function(config) {
logger.debug('PartnerApplication::constructor');
RequireAuthorizationApplication.call(this, _.extend({}, config, { type: 'partner' }));
RequireAuthorizationApplication.call(this, Object.assign({}, config, { type: 'partner' }));
},

init: function() {
Expand Down
4 changes: 2 additions & 2 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function Core(application, options) {
}

// Static
_.extend(Core, {
Object.assign(Core, {

})

// Instance
_.extend(Core.prototype, {
Object.assign(Core.prototype, {


})
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/banktransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ var BankTransaction = Entity.extend(BankTransactionSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'LineItems', 'Contact'));
Object.assign(self, _.omit(obj, 'LineItems', 'Contact'));
if (obj.LineItems) {
var lineItems = this.application.asArray(obj.LineItems.LineItem);
_.each(lineItems, function(lineItem) {
self.LineItems.push(lineItem);
})
}
if (obj.Contact)
_.extend(self.Contact, new Contact(self.application).fromXmlObj(obj.Contact))
Object.assign(self.Contact, new Contact(self.application).fromXmlObj(obj.Contact))

return this;
},
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/banktransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var BankTransfer = Entity.extend(BankTransferSchema, {
return this._super(options);
},
fromXmlObj: function(obj) {
_.extend(this, obj);
Object.assign(this, obj);
return this;
},
toXml: function() {
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var Contact = Entity.extend(ContactSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'Contact', 'LineItems', 'CreditNotes'));
Object.assign(self, _.omit(obj, 'Contact', 'LineItems', 'CreditNotes'));
if (obj.Addresses) {
this.extractArray(obj.Addresses.Address, this.Addresses);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports.extend = function(schema, classProps, staticProps) {
return _.clone(this.tracking._changes);
},
fromXmlObj: function(obj) {
return _.extend(this, obj);
return Object.assign(this, obj);
},
extractArray: function(src, dest) {
var items = this.application.asArray(src);
Expand All @@ -45,7 +45,7 @@ module.exports.extend = function(schema, classProps, staticProps) {
}
})

return Entity.extend(_.extend(classProps, { Entity: Entity }), staticProps);
return Entity.extend(Object.assign(classProps, { Entity: Entity }), staticProps);

}

Expand Down
4 changes: 2 additions & 2 deletions lib/entities/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var Invoice = Entity.extend(InvoiceSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'LineItems', 'Payments'));
Object.assign(self, _.omit(obj, 'LineItems', 'Payments'));
if (obj.LineItems) {
this.extractArray(obj.LineItems.LineItem, this.LineItems);
}
Expand All @@ -89,7 +89,7 @@ var Invoice = Entity.extend(InvoiceSchema, {
},
toXml: function() {
var invoice = _.omit(this.toObject(), 'LineItems', 'Payments', 'CreditNotes', 'InvoiceID', 'HasAttachments', 'AmountDue', 'AmountPaid', 'FullyPaidOnDate', 'AmountCredited', 'UpdatedDateUTC');
_.extend(invoice, { LineItems: { LineItem: [] } });
Object.assign(invoice, { LineItems: { LineItem: [] } });
_.forEach(this.LineItems, function(lineItem) {
invoice.LineItems.LineItem.push(lineItem.toObject());
});
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/journal.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var Journal = Entity.extend(JournalSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'JournalLines'));
Object.assign(self, _.omit(obj, 'JournalLines'));
if (obj.JournalLines) {
var journalLines = this.application.asArray(obj.JournalLines.JournalLine);
_.each(journalLines, function(journalLine) {
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var Organisation = Entity.extend(OrganisationSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'Addresses', 'Phones', 'ExternalLinks'));
Object.assign(self, _.omit(obj, 'Addresses', 'Phones', 'ExternalLinks'));
if (obj.Addresses) {
_.each(obj.Addresses.Address, function(address) {
self.Addresses.push(address);
Expand Down
2 changes: 1 addition & 1 deletion lib/entities/payitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var PayItems = Entity.extend(PayItemsSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'BenefitTypes', 'EarningsTypes', 'ReimbursementTypes', 'DeductionTypes', 'TimeOffTypes'));
Object.assign(self, _.omit(obj, 'BenefitTypes', 'EarningsTypes', 'ReimbursementTypes', 'DeductionTypes', 'TimeOffTypes'));
if (obj.BenefitTypes) {
this.extractArray(obj.BenefitTypes.BenefitType, this.BenefitTypes);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/payroll_employee.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,14 @@ var Employee = Entity.extend(EmployeeSchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations', 'PaymentMethod', 'PayTemplate', 'OpeningBalances'));
Object.assign(self, _.omit(obj, 'SalaryAndWages', 'WorkLocations', 'PaymentMethod', 'PayTemplate', 'OpeningBalances'));
if (obj.SalaryAndWages)
this.extractArray(obj.SalaryAndWages.SalaryAndWage, this.SalaryAndWages);
if (obj.WorkLocations)
this.extractArray(obj.WorkLocations.WorkLocation, this.WorkLocations);

if (obj.PaymentMethod) {
_.extend(this.PaymentMethod, _.pick(obj.PaymentMethod, 'PaymentMethodType'));
Object.assign(this.PaymentMethod, _.pick(obj.PaymentMethod, 'PaymentMethodType'));
if (obj.PaymentMethod.BankAccounts)
this.extractArray(obj.PaymentMethod.BankAccounts, this.PaymentMethod.BankAccounts);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/timesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var Timesheet = Entity.extend(TimesheetSchema, {
fromXmlObj: function (obj)
{
var self = this;
_.extend(self, _.omit(obj, 'TimesheetLines'));
Object.assign(self, _.omit(obj, 'TimesheetLines'));
if (obj.TimesheetLines) {
var items = this.application.asArray(obj.TimesheetLines.TimesheetLine);
_.each(items,function(item)
Expand All @@ -60,7 +60,7 @@ var Timesheet = Entity.extend(TimesheetSchema, {
toXml: function ()
{
var timesheet = _.omit(this.toObject(), 'TimesheetLines');
_.extend(timesheet, { TimesheetLines: []});
Object.assign(timesheet, { TimesheetLines: []});
_.forEach(this.TimesheetLines, function(timesheetline)
{
timesheet.TimesheetLines.push({ TimesheetLine: _.pick(timesheetline.toObject(),'EarningsTypeID','TrackingItemID')});
Expand Down
4 changes: 2 additions & 2 deletions lib/entities/trackingcategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var TrackingCategory = Entity.extend(TrackingCategorySchema, {
},
fromXmlObj: function(obj) {
var self = this;
_.extend(self, _.omit(obj, 'Options'));
Object.assign(self, _.omit(obj, 'Options'));
if (obj.Options) {
_.each(this.application.asArray(obj.Options.Option), function(option) {
self.Options.push(option);
Expand All @@ -36,7 +36,7 @@ var TrackingCategory = Entity.extend(TrackingCategorySchema, {
toXml: function() {
var trackingCategory = _.omit(this.toObject(), 'Options');
// Options cannot be saved using this endpoint, they must use the specific /options endpoint
// _.extend(trackingCategory, { Options: [] });
// Object.assign(trackingCategory, { Options: [] });
// _.forEach(this.Options, function(option) {
// trackingCategory.Options.push({ Option: option.toObject() })
// })
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Accounts = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Account', entityPlural: 'Accounts' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Account', entityPlural: 'Accounts' }, options));
},
newAccount: function(data, options) {
return new Account(this.application, data, options)
Expand Down
4 changes: 2 additions & 2 deletions lib/entity_helpers/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Attachments = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Attachment', entityPlural: 'Attachments' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Attachment', entityPlural: 'Attachments' }, options));
},
newAttachment: function(data, options) {
return new Attachment(this.application, data, options)
Expand All @@ -19,7 +19,7 @@ var Attachments = EntityHelper.extend({
})
},
getAttachments: function(ownerPath, options) {
var clonedOptions = _.extend({}, options, { path: ownerPath + '/Attachments' });
var clonedOptions = Object.assign({}, options, { path: ownerPath + '/Attachments' });
clonedOptions.entityConstructor = function(data) { return self.newAttachment(data) };
return this.getEntities(clonedOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/banktransactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var BankTransactions = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'BankTransaction', entityPlural: 'BankTransactions' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransaction', entityPlural: 'BankTransactions' }, options));
},
newBankTransaction: function(data, options) {
return new BankTransaction(this.application, data, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/banktransfers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var BankTransfers = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'BankTransfer', entityPlural: 'BankTransfers' }, options));
},
newBankTransfer: function(data, options) {
return new BankTransfer(this.application, data, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Contacts = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Contact', entityPlural: 'Contacts' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Contact', entityPlural: 'Contacts' }, options));
},
newContact: function(data, options) {
return new Contact(this.application, data, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/entity_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function EntityHelper(application, options) {
}
EntityHelper.extend = extend;

_.extend(EntityHelper.prototype, {
Object.assign(EntityHelper.prototype, {
saveEntities: function(entities, options) {
logger.debug('EntityHelper::saveEntities');
options = options || {};
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/invoices.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Invoices = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Invoice', entityPlural: 'Invoices' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Invoice', entityPlural: 'Invoices' }, options));
},
newInvoice: function(data, options) {
return new Invoice(this.application, data, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Items = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Item', entityPlural: 'Items' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Item', entityPlural: 'Items' }, options));
},
newItem: function(data, options) {
return new Item(this.application, data, options)
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/organisations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Organisations = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Organisation', entityPlural: 'Organisations' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Organisation', entityPlural: 'Organisations' }, options));
},
getOrganisations: function(options, callback) {
var self = this;
Expand Down
4 changes: 2 additions & 2 deletions lib/entity_helpers/payitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var _ = require('lodash')
var PayItems = EntityHelper.extend({
constructor: function (application, options)
{
EntityHelper.call(this, application, _.extend({
EntityHelper.call(this, application, Object.assign({
entityPlural: 'PayItems', path: 'Payitems'}, options));
},
newPayItems: function(data, options)
Expand Down Expand Up @@ -42,7 +42,7 @@ var PayItems = EntityHelper.extend({
getPayItems: function (options)
{
var self = this;
var clonedOptions = _.extend({},options, { api: 'payroll'});
var clonedOptions = Object.assign({},options, { api: 'payroll'});
clonedOptions.entityConstructor = function(data) { return self.newPayItems(data)};
return this.getEntities(clonedOptions)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Payments = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Payment', entityPlural: 'Payments' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Payment', entityPlural: 'Payments' }, options));
},
createPayment: function(data, options) {
return new Payment(this.application, data, options);
Expand Down
4 changes: 2 additions & 2 deletions lib/entity_helpers/payroll_employees.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var Employees = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'Employee', entityPlural: 'Employees' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'Employee', entityPlural: 'Employees' }, options));
},
newEmployee: function(data, options) {
return new Employee(this.application, data, options)
Expand All @@ -23,7 +23,7 @@ var Employees = EntityHelper.extend({
},
getEmployees: function(options) {
var self = this;
var clonedOptions = _.extend({}, options, { api: 'payroll' });
var clonedOptions = Object.assign({}, options, { api: 'payroll' });
clonedOptions.entityConstructor = function(data) { return self.newEmployee(data) };
return this.getEntities(clonedOptions)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/entity_helpers/taxrates.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var _ = require('lodash'),

var TaxRates = EntityHelper.extend({
constructor: function(application, options) {
EntityHelper.call(this, application, _.extend({ entityName: 'TaxRate', entityPlural: 'TaxRates' }, options));
EntityHelper.call(this, application, Object.assign({ entityName: 'TaxRate', entityPlural: 'TaxRates' }, options));
},
newTaxRate: function(data, options) {
return new TaxRate(this.application, data, options);
Expand Down
Loading

0 comments on commit 619146e

Please sign in to comment.