var app = require('express'); // get express for server init
var path = require('path');// get the path
var mongoose = require('mongoose');// DB connections
var Schema = mongoose.Schema;//to create schemas

//init for using POST calls
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));//read URL encoded
app.use(bodyParser.json()); //read json data

// exports
var exports = module.exports = {};

//static routes init

app.use('/javascripts', express.static('public/javascripts'));
app.use('/css', express.static('public/css'));
app.use('/images', express.static('public/images'));
app.use('/font', express.static('public/font'));
app.use('/stylesheets', express.static('public/stylesheets'));
app.use(express.static('views'));


//Connect to DB

var connection = mongoose.createConnection('mongodb://Bu1ly:danivolp89@ds049624.mlab.com:49624/ein_prat',function () {

    console.log("App is now connected to Mlab DB");
});

//Create schema

var seniors = new Schema({
    name: String,
    identity: String,
    lastName: String
});

// Connect collection to schema
var Senior = connection.model('Senior',seniors);

// Main route
app.get('/', function (req,res) {
    res.sendfile(path.join(__dirname + "/views/index.ejs"));
});

// --------API CALLS --------
//Register new Users
app.post('reg', function(req,res){
   var jason = req.body; // get the user data
    console.log(jason); //print for debug

   // create senior object
    var seniorJason = {
        name : jason.name,
        lastName : jason.lastName,
        identity : jason.identity
    }

    // create new DB instance
    var newSenior = new Senior(seniorJason);

    // save the newSenior to the DB
    newSenior.save(function(err){
        if(err)
            res.status(500).end("Error");
        else
            res.status(200).end("Added", seniorJason, "to Seniors DB");
    })
});

// Delete some User
app.post('/delete', function (req,res) {
    var SeniorJason = req.body; // get the user data
    console.log(SeniorJason); //print for debug



})




//module.exports(server);



@@ -1910,13 +1910,8 @@
 ete 
-some 
 User
@@ -2058,12 +2058,470 @@
 ug%0A%0A
-%0A%0A%7D)
+    // create senior object%0A    var seniorJason = %7B%0A        name : jason.name,%0A        lastName : jason.lastName,%0A        identity : jason.identity%0A    %7D%0A%0A    // create new DB instance%0A    var newSenior = new Senior(seniorJason);%0A%0A    // remove the newSenior to the DB%0A    newSenior.remove(function(err)%7B%0A        if(err)%0A            res.status(500).end(%22Error%22);%0A        else%0A            res.status(200).end(%22Removed%22, seniorJason, %22from Seniors DB%22);%0A    %7D)%0A%7D);
 %0A%0A%0A%0A

Delete senior from the DB