Skip to content

Commit

Permalink
public: Extract Backend.createOrUpdate
Browse files Browse the repository at this point in the history
This attempts to address Code Climate similar code issues.
  • Loading branch information
mbland committed Aug 8, 2017
1 parent bd0978e commit 0dc32fa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions public/app.js
Expand Up @@ -101,10 +101,15 @@
'Request for user info failed')
}

cl.Backend.prototype.createLink = function(link, target) {
cl.Backend.prototype.createOrUpdate = function(link, target, action, errMsg) {
link = cl.createLinkInfo(link)
return this.makeApiCall('POST', 'create', link, { target: target },
link.anchor + ' now redirects to ' + target, 'The link wasn\'t created')
return this.makeApiCall('POST', action, link, { target: target },
link.anchor + ' now redirects to ' + target, errMsg)
}

cl.Backend.prototype.createLink = function(link, target) {
return this.createOrUpdate(link, target, 'create',
'The link wasn\'t created')
}

cl.Backend.prototype.getLink = function(link) {
Expand All @@ -120,9 +125,7 @@
}

cl.Backend.prototype.updateTarget = function(link, target) {
link = cl.createLinkInfo(link)
return this.makeApiCall('POST', 'target', link, { target: target },
link.anchor + ' now redirects to ' + target,
return this.createOrUpdate(link, target, 'target',
'The target URL wasn\'t updated')
}

Expand Down

0 comments on commit 0dc32fa

Please sign in to comment.