Clear presets when task is deleted

This commit is contained in:
Shweelan Samson committed 2016-05-11 20:16:25 +03:00
1 parent 47f7282a27
commit b8e3260e75
1 file changed
+14 -8
+14 -8
View File
@@ -290,19 +290,25 @@ listener = (request, response) ->
action = r[2] action = r[2]
if not action? or action is '/' if not action? or action is '/'
if request.method == 'DELETE' if request.method == 'DELETE'
db.tasksCollection.remove({'_id' : taskId}, (err, removedCount) -> db.tasksCollection.findOne({'_id' : taskId}, {'device' : 1}, (err, task) ->
if err throw err if err
response.writeHead(500)
response.end(errorToString(err))
return
if removedCount == 0 if not task
response.writeHead(404) response.writeHead(404)
response.end() response.end()
return return
response.writeHead(200) deviceId = task.device
response.end() db.tasksCollection.remove({'_id' : taskId}, (err, removedCount) ->
throw err if err
db.redisClient.del("#{deviceId}_presets_hash", (err) ->
throw err if err
response.writeHead(200)
response.end()
)
)
) )
else else
response.writeHead 405, {'Allow': 'PUT DELETE'} response.writeHead 405, {'Allow': 'PUT DELETE'}