-
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.
Refactorizado en el controlador de employees
- Loading branch information
Jesús Mur Fontanals
committed
Jan 19, 2015
1 parent
060486d
commit 33c1814
Showing
4 changed files
with
100 additions
and
93 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,20 +1,18 @@ | ||
# ngUsers: Aplicación AngularJS sobre trabajadores, horas trabajadas y salarios. | ||
## Desarrollo con proposito de aprendizaje. | ||
# Aplicación AngularJS sobre trabajadores, horas trabajadas y salarios. | ||
## Desarrollo con proposito de aprendizaje y práctica. | ||
|
||
### Como configurar el entorno. | ||
|
||
1. Instalar dependencias mediante el comando: npm install | ||
|
||
2. Requerido tener instalado MongoDB para el almacenamiento de los empleados. | ||
|
||
3. Introducir empleados mediante post del REST a la siguiente ruta http://localhost:3000/api/employees | ||
|
||
### Issues a revisar. | ||
|
||
* Resolver un error en el filtro del array .some (Archivo services.js). | ||
|
||
### Próximas feautures a desarrollar. | ||
|
||
* Metodos PUT y DELETE del controlador de employees. | ||
|
||
### Licencia | ||
|
||
MIT License (MIT) Copyright (c) 2014 @jesusmurf | ||
MIT License (MIT) Copyright (c) 2015 @jesusmurf |
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,76 @@ | ||
var Employee = require('../models/employees.js'); | ||
|
||
|
||
exports.getEmployees = function(req, res) { | ||
Employee.find(function(err, employees) { | ||
if (err) | ||
res.next(err); | ||
res.status(200); | ||
res.json(employees); | ||
}); | ||
}; | ||
|
||
exports.postEmployee = 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) | ||
return next(err); | ||
res.status(201); | ||
res.json({ | ||
employee: employee, | ||
message: 'Employee created!' | ||
}); | ||
}); | ||
}; | ||
|
||
exports.updateEmployee = 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.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.salary = req.body.salary; | ||
|
||
employee.save(function(err, employee) { | ||
if (err) | ||
return next(err); | ||
res.status(200); | ||
res.json({ | ||
message: 'Employee updated!' | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.deleteEmployee = 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!'}); | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.