-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retocado también el html.
- Loading branch information
Jesús Mur Fontanals
committed
Nov 29, 2014
1 parent
58bdfdc
commit 121a2e1
Showing
8 changed files
with
87 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
node_modules | ||
.idea/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,60 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
var app = module.exports = express(); | ||
|
||
var morgan = require('morgan'); | ||
var swig = require('swig'); | ||
var methodOverride = require('method-override'); | ||
var bodyParser = require('body-parser'); | ||
var mongoose = require('mongoose'); | ||
var app = module.exports = express(); | ||
|
||
app.engine('html', swig.renderFile); | ||
app.use(morgan('dev')); | ||
app.use(bodyParser.urlencoded({ extended: true })); | ||
app.use(bodyParser.json()); | ||
|
||
app.set('view engine', 'html'); | ||
app.set('views', __dirname + '/views'); | ||
|
||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use(morgan('dev')); | ||
|
||
app.get('/', function (req, res) { | ||
debugger; | ||
res.render('index', {message: 'hola mundo'}); | ||
}); | ||
|
||
mongoose.connect('mongodb://localhost:27017/employees'); | ||
var Employee = require('./models/employees.js'); | ||
|
||
app.post('/add',function(req, res) { | ||
var employee = new Employee({ | ||
first: req.body.first, | ||
last: req.body.last, | ||
street: req.body.street, | ||
city: req.body.city, | ||
state: req.body.state, | ||
country: req.body.country, | ||
postal_code: req.body.postal_code, | ||
abilities: req.body.abilities, | ||
data: { | ||
worked_hours: req.body.worked_hours, | ||
worked_hpd: req.body.worked_hpd, | ||
salary: req.body.salary | ||
} | ||
}); | ||
|
||
employee.save(function(err, employee) { | ||
if (err) | ||
res.send(err); | ||
console.log(employee); | ||
res.json({employee: employee, message: 'Employee created!' }); | ||
}); | ||
}); | ||
|
||
var port = 3000; | ||
app.listen(port, function (err) { | ||
if (err) { | ||
console.log('Error del servidor ' + err); | ||
} else { | ||
console.log('servidor corriendo en el puerto ' + port); | ||
}; | ||
}); | ||
console.log('Servidor corriendo en el puerto ' + port); | ||
} | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var mongoose = require('mongoose'); | ||
|
||
var EmployeesSchema = new mongoose.Schema({ | ||
first: String, | ||
last: String, | ||
street: String, | ||
city: String, | ||
state: String, | ||
country: String, | ||
postal_code: Number, | ||
abilities: Array, | ||
data: { | ||
worked_hours: Number, | ||
worked_hpd: Number, | ||
salary: Number | ||
} | ||
|
||
}); | ||
|
||
module.exports = mongoose.model('Employees', EmployeesSchema); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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