<commit_before>// Get all of our friend data
var data = require('../data.json');
var models = require('../models');

exports.memberFunctions = function(req, res){
	var user = req.query.user;

	var remove = req.query.remove;
	var name = req.query.name;
	var relationship = req.query.relationship;
	var side = req.query.side;
	var id = req.query.id;

	var gender = req.query.gender;
	var age = req.query.age;
	
	var height = req.query.height;
	var weight = req.query.weight;
	var allergy = req.query.allergy; 
	var sense = req.query.sense;
	var med = req.query.med;
	var heart = req.query.heart;
	var bprob =req.query.bprob;
	var eprob = req.query.eprob;
	var eye = req.query.eye;
	//update fake json for user
	console.log("JSON IS: "+data["jane"]);
	if(user=="me") {
		console.log("YOOOOOOO");
		// get json entry
		var person = data["jane"];
		person['name'] = name;
		person['gender'] = gender;
		person['age'] = age;
		person['height'] = height;
		person['weight'] = weight;
		person['allergies'] = allergy; 
		person['sensitivities'] = sense;
		person['medications'] = med;
		person['heart_conditions'] = heart;
		person['behavioral_problems'] = bprob;
		person['emotional_problems'] = eprob;
		person['eye_conditions'] = eye;
		console.log(person);
	}
	if(remove=="1") {
		//modify json

			if(req.query.side =="dad") {
				for(var x=0; x<data.dtree.length; x++) {
					console.log("at member: "+data.dtree[x]+" and x is "+x);
					if(data.dtree[x].id == id) {					
						data.dtree.splice(x, 1);
					}
				}
				
			}
			else if(req.query.side=="mom") {

				for(var i=0; i<data.mtree.length; i++) {
					if(data.mtree[i].id == id) {
						data.mtree.splice(i, 1);
					}
				}
				
			}
		
			
		//remove from db
		models.member.findById(id, function (err, toRemove) {
			if (err) throw err;

			//delete
			toRemove.remove(function(err) {
				if(err) throw err;
				console.log(data);
				console.log("length of json:"+data.dtree.length);
				console.log("Member deleted!");
			});
		});
		res.render('user', data);
	}
	else {


	var update = req.query.update;
	var oldname = req.query.oldname;
	
	//update if request sent from edit 
	if(update=="1") {
		console.log("side is: "+side);
		
		if(side =="dad") {
			for(var x=0; x<data.dtree.length; x++) {
				if(data.dtree[x].id == id) {
					data.dtree[x].name = name;
					data.dtree[x].relationship = relationship;
					data.dtree[x].side = side;
					//data.dtree[x].id = id;
				}
			}
		}
		else if(side=="mom"){
			for(var i=0; i<data.mtree.length; i++) {
						
				if(data.mtree[i].id == id) {
					data.mtree[i].name = name;
					data.mtree[i].relationship = relationship;
					data.mtree[i].side = side;
					//data.mtree[i].id = id;
				}
			}
		}
		models.member.findById(id, function (err, obj){
			if(!err) {
				console.log("old name: "+oldname);
				console.log("new name: "+name);
				console.log("id: "+id);
				//modify json
				
				obj.name = name;
				obj.relationship = relationship;
				obj.gender = gender;
				obj.age = age;
				obj.side = side;
				obj.height = height;
				obj.weight = weight;
				obj.allergy = allergy;
				obj.sensitivity = sense;
				obj.heart = heart;
				obj.bprob = bprob;
				obj.eprob = eprob;
				obj.eye = eye;<commit_msg>fixed medications edit<commit_after>// Get all of our friend data
var data = require('../data.json');
var models = require('../models');

exports.memberFunctions = function(req, res){
	var user = req.query.user;

	var remove = req.query.remove;
	var name = req.query.name;
	var relationship = req.query.relationship;
	var side = req.query.side;
	var id = req.query.id;

	var gender = req.query.gender;
	var age = req.query.age;
	
	var height = req.query.height;
	var weight = req.query.weight;
	var allergy = req.query.allergy; 
	var sense = req.query.sense;
	var med = req.query.med;
	var heart = req.query.heart;
	var bprob =req.query.bprob;
	var eprob = req.query.eprob;
	var eye = req.query.eye;
	//update fake json for user
	console.log("JSON IS: "+data["jane"]);
	if(user=="me") {
		console.log("YOOOOOOO");
		// get json entry
		var person = data["jane"];
		person['name'] = name;
		person['gender'] = gender;
		person['age'] = age;
		person['height'] = height;
		person['weight'] = weight;
		person['allergies'] = allergy; 
		person['sensitivities'] = sense;
		person['medications'] = med;
		person['heart_conditions'] = heart;
		person['behavioral_problems'] = bprob;
		person['emotional_problems'] = eprob;
		person['eye_conditions'] = eye;
		console.log(person);
	}
	if(remove=="1") {
		//modify json

			if(req.query.side =="dad") {
				for(var x=0; x<data.dtree.length; x++) {
					console.log("at member: "+data.dtree[x]+" and x is "+x);
					if(data.dtree[x].id == id) {					
						data.dtree.splice(x, 1);
					}
				}
				
			}
			else if(req.query.side=="mom") {

				for(var i=0; i<data.mtree.length; i++) {
					if(data.mtree[i].id == id) {
						data.mtree.splice(i, 1);
					}
				}
				
			}
		
			
		//remove from db
		models.member.findById(id, function (err, toRemove) {
			if (err) throw err;

			//delete
			toRemove.remove(function(err) {
				if(err) throw err;
				console.log(data);
				console.log("length of json:"+data.dtree.length);
				console.log("Member deleted!");
			});
		});
		res.render('user', data);
	}
	else {


	var update = req.query.update;
	var oldname = req.query.oldname;
	
	//update if request sent from edit 
	if(update=="1") {
		console.log("side is: "+side);
		
		if(side =="dad") {
			for(var x=0; x<data.dtree.length; x++) {
				if(data.dtree[x].id == id) {
					data.dtree[x].name = name;
					data.dtree[x].relationship = relationship;
					data.dtree[x].side = side;
					//data.dtree[x].id = id;
				}
			}
		}
		else if(side=="mom"){
			for(var i=0; i<data.mtree.length; i++) {
						
				if(data.mtree[i].id == id) {
					data.mtree[i].name = name;
					data.mtree[i].relationship = relationship;
					data.mtree[i].side = side;
					//data.mtree[i].id = id;
				}
			}
		}
		models.member.findById(id, function (err, obj){
			if(!err) {
				console.log("old name: "+oldname);
				console.log("new name: "+name);
				console.log("id: "+id);
				//modify json
				
				obj.name = name;
				obj.relationship = relationship;
				obj.gender = gender;
				obj.age = age;
				obj.side = side;
				obj.height = height;
				obj.weight = weight;
				obj.allergy = allergy;
				obj.sensitivity = sense;
				obj.med = med;
				obj.heart = heart;
				obj.bprob = bprob;
				obj.eprob = eprob;
				obj.eye = eye;
{'fraction_non_alphanumeric': 0.1799015081563558, 'fraction_numerical': 0.0024622960911049553, 'mean_word_length': 2.798363530099357, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6223196', 'n_tokens_mistral': 2960, 'n_tokens_neox': 2413, 'n_words': 507}