feat(webhooks): add webhooks operations

This commit is contained in:
Tyler Renelle
2014-11-16 20:03:20 -08:00
parent d078654f41
commit 83a22b8133
2 changed files with 47 additions and 0 deletions
+20
View File
@@ -594,6 +594,26 @@ api.wrap = (user, main=true) ->
user.markModified? type
cb? null, user.tags
# ------
# Webhooks
# ------
addWebhook: (req, cb) ->
wh = user.preferences.webhooks
wh[req.body.id or api.uuid()] =
url: req.body.url
enabled: req.body.enabled or true
sort: if _.isEmpty(wh) then 0 else _.max(wh,'sort').sort+1
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
updateWebhook: (req, cb) ->
_.merge(user.preferences.webhooks[req.params.id], req.body)
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
deleteWebhook: (req, cb) ->
delete user.preferences.webhooks[req.params.id]
user.markModified? 'preferences.webhooks'
cb? null, user.preferences.webhooks
# ------
# Inventory
# ------