mgebbe@0: # Copyright (C) 2014 by Intevation GmbH mgebbe@0: # Author: Mathias Gebbe mgebbe@0: # mgebbe@3: # This file is Free Software under the Apache License, Version 2.0; mgebbe@3: # and comes with NO WARRANTY! mgebbe@3: # See the documentation coming with pumpbridge for details. mgebbe@0: mgebbe@0: async = require("async") mgebbe@0: _ = require("underscore") mgebbe@0: Edge = require("./edge") mgebbe@0: mgebbe@0: mgebbe@0: removeEdges = (userid, network, callback) -> mgebbe@0: delEdge = (edge, callback) -> mgebbe@0: unless edge.to.indexOf(network) is -1 mgebbe@0: edge.del callback mgebbe@0: return mgebbe@0: mgebbe@0: async.parallel [ mgebbe@0: (callback) -> mgebbe@0: return Edge.search( mgebbe@0: from: userid mgebbe@0: , (err, edges) -> mgebbe@0: if err mgebbe@0: callback err mgebbe@0: else mgebbe@0: async.each edges, delEdge, callback mgebbe@0: return mgebbe@0: ) mgebbe@0: (callback) -> mgebbe@0: return Edge.search( mgebbe@0: to: userid mgebbe@0: , (err, edges) -> mgebbe@0: if err mgebbe@0: callback err mgebbe@0: else mgebbe@0: async.each edges, delEdge, callback mgebbe@0: return mgebbe@0: ) mgebbe@0: ], callback mgebbe@0: return mgebbe@0: mgebbe@0: addEdge = (from, to) -> mgebbe@0: async.waterfall [(callback) -> mgebbe@0: Edge.create mgebbe@0: from: from mgebbe@0: to: to mgebbe@0: , callback mgebbe@0: return mgebbe@0: mgebbe@0: ], (err, result) -> mgebbe@0: return mgebbe@0: mgebbe@0: deleteEdge = (from, to) -> mgebbe@0: async.waterfall [(callback) -> mgebbe@0: bank = Edge.bank() mgebbe@0: bank.del Edge.type, Edge.key(from, to), callback mgebbe@0: return mgebbe@0: mgebbe@0: ], (err, result) -> mgebbe@0: return mgebbe@0: mgebbe@0: exports.removeEdges = removeEdges mgebbe@0: exports.deleteEdge = deleteEdge mgebbe@0: exports.addEdge = addEdge