Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fixed the saveContacts method on the contacts object and did some ref…
…actoring. This concept could be applied across all endpoints. Also removed some console.log statments from the code
- Loading branch information
Jordan Walsh
committed
Feb 22, 2017
1 parent
efed46b
commit 251b083
Showing
5 changed files
with
176 additions
and
162 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
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,39 +1,36 @@ | ||
var _ = require('lodash') | ||
, logger = require('../logger') | ||
, EntityHelper = require('./entity_helper') | ||
, Contact = require('../entities/contact') | ||
, p = require('../misc/promise') | ||
, util = require('util') | ||
var _ = require('lodash'), | ||
logger = require('../logger'), | ||
EntityHelper = require('./entity_helper'), | ||
Contact = require('../entities/contact'), | ||
p = require('../misc/promise'), | ||
util = require('util') | ||
|
||
var Contacts = EntityHelper.extend({ | ||
constructor: function (application, options) | ||
{ | ||
EntityHelper.call(this, application, _.extend({ entityName:'Contact', entityPlural:'Contacts'}, options)); | ||
constructor: function(application, options) { | ||
EntityHelper.call(this, application, _.extend({ entityName: 'Contact', entityPlural: 'Contacts' }, options)); | ||
}, | ||
newContact: function (data, options) | ||
{ | ||
newContact: function(data, options) { | ||
return new Contact(this.application, data, options) | ||
}, | ||
getContact: function (id, modifiedAfter) | ||
{ | ||
return this.getContacts({ id: id, modifiedAfter: modifiedAfter}) | ||
.then(function (contacts) | ||
{ | ||
getContact: function(id, modifiedAfter) { | ||
return this.getContacts({ id: id, modifiedAfter: modifiedAfter }) | ||
.then(function(contacts) { | ||
return _.first(contacts); | ||
}) | ||
}, | ||
saveContacts: function (contacts, options) | ||
{ | ||
return this.saveEntities(contacts, options) | ||
saveContacts: function(contacts, options) { | ||
return this.saveEntities(contacts, this.setupOptions(options)); | ||
}, | ||
getContacts: function (options) | ||
{ | ||
getContacts: function(options) { | ||
return this.getEntities(this.setupOptions(options)); | ||
}, | ||
setupOptions: function(options) { | ||
var self = this; | ||
var clonedOptions = _.clone(options || {}); | ||
clonedOptions.entityConstructor = function(data) { return self.newContact(data)}; | ||
return this.getEntities(clonedOptions) | ||
clonedOptions.entityPath = 'Contacts.Contact'; | ||
clonedOptions.entityConstructor = function(data) { return self.newContact(data) }; | ||
return clonedOptions; | ||
} | ||
}) | ||
|
||
module.exports = Contacts; | ||
|
||
module.exports = Contacts; |
Oops, something went wrong.