Last active
August 29, 2015 14:00
-
-
Save bhanuc/c3bc7f5b28e290317f2d to your computer and use it in GitHub Desktop.
delete fn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//userdetails.cmaps has all the info of project to be deleted | |
module.exports.deletenode = function (userdetails) { | |
return function(done) { | |
Project.findOne({'_id': userdetails.cmaps.project_id}, function findmap(err, proj) { | |
if (err) { | |
done(null, "please login again"); | |
} else { | |
var req_map = proj.maps[userdetails.cmaps.map_name]; | |
var deleted = {}; | |
var length = req_map.length; | |
var key = 0; | |
for(var i =0 ; i <length; i++){ | |
if(req_map[i].i_no == userdetails.cmaps.i_no ) { | |
key = 1; | |
break; | |
} | |
} | |
(function delete_all(i,req_map){ | |
if(req_map[i].childi_no!=undefined) | |
{ | |
var child_length = req_map[i].childi_no.length; | |
for (var j=0; j<child_length ; j++) | |
{ | |
var k=0; | |
while(k < req_map.length && req_map[k].i_no != req_map[i].childi_no[j] ) | |
{ | |
k++; | |
} | |
delete_all(k,req_map); | |
deleted[req_map[k].i_no] = req_map[k]; | |
req_map.splice(k,1); | |
} | |
} | |
})(i,req_map); | |
var z=0; | |
if(req_map.length>1) | |
{ | |
while(req_map[i].parenti_no!=req_map[z].i_no) | |
{ | |
z++; | |
} | |
var w=0; | |
while(req_map[z].childi_no[w]!=req_map[i].i_no) | |
{ | |
w++; | |
} | |
req_map[z].childi_no.splice(w,1); | |
} | |
deleted[req_map[i].i_no] = req_map[i]; | |
req_map.splice(i,1); | |
proj.markModified('maps'); | |
proj.save(function save(){ | |
if (err) { | |
done(null, "map cannot be edited"); | |
} | |
done(null, JSON.stringify({ map: proj.maps[userdetails.cmaps.map_name], deleted: deleted})); | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment