示例#1
0
var validateTreatment = function (res, treatment) {

    if (treatment.serviceArea == null || treatment.serviceArea == '') {
        console.log('Error adding treatment: area de atendimento invalida');
        res.status('500').send({ status: 500, error: 'Area de atendimento invalida' });
        return false;
    }

    if ((treatment.doctor == null) || (treatment.doctor != null && !iz.between(treatment.doctor.trim().length, 1, 100))) {
        console.log('Error adding treatment: o nome do medico deve ter 1 a 100 caracteres');
        res.status('500').send({ status: 500, error: 'O nome do medico deve ter 1 a 100 caracteres' });
        return false;
    }
    treatment.doctor = treatment.doctor.trim();

    if ((treatment.CRMDoctor == null) || (treatment.CRMDoctor != null && !iz.between(treatment.CRMDoctor.trim().length, 1, 20))) {
        console.log('Error adding treatment: o CRM do medico deve ter 1 a 20 caracteres');
        res.status('500').send({ status: 500, error: 'O CRM do medico deve ter 1 a 20 caracteres' });
        return false;
    }
    treatment.CRMDoctor = treatment.CRMDoctor.trim();

    if (!iz.maxLength(treatment.observations, 3000)) {
        console.log('Error adding treatment: o complemento deve ter maximo 20 caracteres');
        res.status('500').send({ status: 500, error: 'O complemento deve ter maximo 20 caracteres' });
        return false;
    }
    if (treatment.observations != null) { treatment.observations = treatment.observations.trim() };

    if (!(treatment.treatmentPerformed == 'true' || treatment.treatmentPerformed == true)) {
        treatment.treatmentPerformed = false;
    }

    if (!(treatment.canceledTreatment == 'true' || treatment.canceledTreatment == true)) {
        treatment.canceledTreatment = false;
    }

    if ((treatment.diagnosis == null) || (treatment.diagnosis != null && !iz.between(treatment.diagnosis.trim().length, 1, 3000))) {
        console.log('Error adding treatment: o diagnostico deve ter 1 a 3000 caracteres');
        res.status('500').send({ status: 500, error: 'O diagnostico deve ter 1 a 3000 caracteres' });
        return false;
    }
    treatment.diagnosis = treatment.diagnosis.trim();

    if (!iz(treatment.dateInclusion).required().date().valid) {
        console.log('Error adding treatment: data de inclusao invalida');
        res.status('500').send({ status: 500, error: 'Data de inclusao invalida' });
        return false;
    }

    return true;
}
示例#2
0
router.post('/meatballs', function(req, res) {
	console.log("here");
	// Set our internal DB variable
	var db = req.db;
	require('http');
	
	// Get our form values. These rely on the "name" attributes
	var entrant_ID = req.body.entrant_ID;
	var sauce = req.body.sauce;
	var originality = req.body.originality;
	var taste = req.body.taste;
	var texture = req.body.texture;
	var food = req.body.food;
	var voter_IP = req.connection.remoteAddress;
	
	// Set vote array so it validates all four dimensions.
	var vote_array = [taste, texture, originality, sauce];
	var failure_rate = 0;
	for (var i = 0; i < 4; i++) {
		console.log(vote_array[i]);
		if (iz.between(vote_array[i], 1,10) == false) { 
		failure_rate = 1;
		console.log(failure_rate);
		}
	}
	console.log(failure_rate);
	
	// Validate votes. Set condition to check if false
	if (failure_rate == 1) {
	
	// if (iz.between(vote_array, 1,10) == false) { 
		res.location("invalid");
		res.redirect("invalid");
	}
	else {
		// Set our collection
		var collection = db.get('cookoffdata');
	
	
		// Submit to the DB
		console.log("checkpoint");
		collection.insert({
			"entrant_ID" : entrant_ID,
			"sauce" : sauce,
			"originality" : originality,
			"taste" : taste,
			"texture" : texture,
			"food" : food,
			"voter_IP" : voter_IP
		
		}, function (err, doc) {
			if (err) { 
				// If it failed, return error
				res.send("There was a problem adding the information to the database.")
			}
			else {
				// If it worked, set the header so the address bar doesn't still say /meatballs
				res.location("complete");
				// And forward to success page
				res.redirect("complete");
			}
		});
	}
	
	
});