Skip to content

Commit

Permalink
Merge pull request #1 from vick1990/master
Browse files Browse the repository at this point in the history
Corregido algunas cosas
  • Loading branch information
Jesús Mur Fontanals committed Jan 10, 2015
2 parents bb9028e + 4870ebd commit 060486d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 48 deletions.
37 changes: 21 additions & 16 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
var express = require('express');
var path = require('path');
var morgan = require('morgan');
var swig = require('swig');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
var app = express();
//Este es un comentario
var express = require('express'),
path = require('path'),
morgan = require('morgan'),
swig = require('swig'),
methodOverride = require('method-override'),
bodyParser = require('body-parser'),
mongoose = require('mongoose'),
app = express(),
router = express.Router();

app.engine('html', swig.renderFile);
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());

/* Error handling:
Deveplopment.
*/
if (app.get('env') === 'development') {
app.use(function(err, req, res, next){
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
Expand All @@ -29,7 +33,7 @@ if (app.get('env') === 'development') {
Production.
*/
if (app.get('env') === 'production') {
app.use(function(err, req, res, next){
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
Expand All @@ -41,21 +45,22 @@ if (app.get('env') === 'production') {
app.set('view engine', 'html');
app.set('views', __dirname + '/views');
app.use(express.static(path.join(__dirname, 'public')));
app.use('/bower_components', express.static(__dirname + '/bower_components'));
app.use('/bower_components', express.static(__dirname + '/bower_components'));

app.get('/', function (req, res) {
app.get('/', function(req, res) {
res.render('index');
});

mongoose.connect('mongodb://localhost:27017/employees');
var employeeRoutes = require('./routes/employee.js')(app);

require('./routes/employee.js')(app,router);


var port = 3000;
app.listen(port, function (err) {
app.listen(port, function(err) {
if (err) {
console.log('Error del servidor ' + err);
} else {
console.log('Servidor corriendo en el puerto ' + port);
}
});
});
26 changes: 13 additions & 13 deletions public/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
(function () {
(function() {
/**
* user.controllers Module
*
* Description
*/
* user.controllers Module
*
* Description
*/
angular.module('user.controllers', [])
.controller('UserListController', ['$scope', '$routeParams','userService', function($scope, $routeParams, userService){
.controller('UserListController', ['$scope', '$routeParams', 'userService', function($scope, $routeParams, userService) {
var type = $routeParams.type;

if (type) {
$scope.type = type;
userService.byType(type).then(function(data){

userService.byType(type).then(function(data) {
$scope.users = data;
})
} else {
Expand All @@ -20,7 +20,7 @@
})
};
}])
.controller('UserController', ['$scope', '$routeParams', 'userService', function($scope, $routeParams, userService){
.controller('UserController', ['$scope', '$routeParams', 'userService', function($scope, $routeParams, userService) {
var first = $routeParams.first;
$scope.user = {};

Expand All @@ -29,11 +29,11 @@
$scope.user = data;
})
}])
.controller('TabsController', function(){
.controller('TabsController', function() {
this.tab = 3;

this.selectTab = function (tab) {
this.selectTab = function(tab) {
this.tab = tab;
};
});
};
});
})()
2 changes: 1 addition & 1 deletion public/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var deferred = $q.defer();

function all() {
$http.get('/api/employee/all')
$http.get('/api/employees')
.success(function(data) {
deferred.resolve(data);
});
Expand Down
41 changes: 23 additions & 18 deletions routes/employee.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
var express = require('express');
app = express();

var Employee = require('../models/employees.js');
var router = express.Router();

module.exports = function (app) {
router.get('/employees', function(req, res){
Employee.find(function(err, employee){
module.exports = function(app, router) {
router.get('/employees', function(req, res) {
Employee.find(function(err, employee) {
if (err)
res.next(err);
res.status(200);
res.json(employee);
});
});

router.post('/employee/add',function(req, res) {
router.post('/employee/add', function(req, res) {
var employee = new Employee({
first: req.body.first,
last: req.body.last,
Expand All @@ -35,42 +31,51 @@ module.exports = function (app) {
if (err)
return next(err);
res.status(201);
res.json({employee: employee, message: 'Employee created!' });
res.json({
employee: employee,
message: 'Employee created!'
});
});
});

router.put('/employee/update/:employee_id', function (req, res){
Employee.findById(req.params.employee_id, function(err, employee){
router.put('/employee/update/:employee_id', function(req, res) {
Employee.findById(req.params.employee_id, function(err, employee) {
if (err)
return next(err);

employee.first = req.body.first;
employee.last = req.body.last;
employee.street = req.body.street;
employee.street = req.body.street;
employee.city = req.body.city;
employee.state = req.body.state;
employee.country = req.body.country;
employee.postal_code = req.body.postal_code;
employee.abilities = req.body.abilities;
employee.data.worked_hours = req.body.worked_hours;
employee.data.worked_hpd = req.body.worked_hpd;
employee.data.worked_hpd = req.body.worked_hpd;
employee.data.salary = req.body.salary;

employee.save(function (err, employee){
employee.save(function(err, employee) {
if (err)
return next(err);
res.status(200);
res.json({message: 'Employee updated!'});
res.json({
message: 'Employee updated!'
});
});
});
});

router.delete('/employee/delete/:employee_id', function (req, res){
Employee.remove({_id: req.params.employee_id}, function (err, employee){
router.delete('/employee/delete/:employee_id', function(req, res) {
Employee.remove({
_id: req.params.employee_id
}, function(err, employee) {
if (err)
return next(err);
res.status(200);
res.json({message: 'Employee deleted!'});
res.json({
message: 'Employee deleted!'
});
});
});

Expand Down

0 comments on commit 060486d

Please sign in to comment.