-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignalSubscriber.coffee
31 lines (24 loc) · 1.56 KB
/
SignalSubscriber.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module.exports = class Subscriber
constructor: (@clientId, @event, @handler) ->
match: (req) ->
expression = @event == "newVertex" and req.method == "POST" and req.url.indexOf("/vertices") != -1 ||
@event == "newEdge" and req.method == "POST" and req.url.indexOf("/edges") != -1 ||
@event == "vertexRemoved" and req.method == "DELETE" and req.url.indexOf("/vertices") != -1 and req.url.indexOf("?") == -1 ||
@event == "edgeRemoved" and req.method == "DELETE" and req.url.indexOf("/edges") != -1 and req.url.indexOf("?") == -1 ||
@event == "vertexPropertiesChanged" and req.method == "PUT" and req.url.indexOf("/vertices/") != -1 ||
@event == "edgePropertiesChanged" and req.method == "PUT" and req.url.indexOf("/edges/") != -1 ||
@event == "vertexPropertiesRemoved" and req.method == "DELETE" and req.url.indexOf("/vertices/") != -1 and req.url.indexOf("?") != -1 ||
@event == "edgePropertiesRemoved" and req.method == "DELETE" and req.url.indexOf("/edges/") != -1 and req.url.indexOf("?") != -1 ||
@event == "graphCleared" and req.method == "DELETE" and req.url.indexOf("/graphs/") != -1
return expression
notify: (req, result) ->
if @event == "vertexPropertiesRemoved" || @event == "edgePropertiesRemoved"
data = req.url.split("/").pop().split("?")
id = data[0]
keys = data[1].split("&")
@handler {_id: id, keys: keys}
else if @event == "vertexRemoved" || @event == "edgeRemoved"
id = req.url.split("/").pop()
@handler {_id: id}
else
@handler result