Commit a33f6898 authored by D’jalmar Gutierrez Titirico's avatar D’jalmar Gutierrez Titirico 🚲

Validacion a los modelos añadida y nuevos metodos en la API

parent 1bbd1d88
......@@ -18,7 +18,9 @@ export default function(sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false,
validate: {
notEmpty: true
notEmpty: {
msg:'Ingrese un nombre para el cargo'
}
}
}
}, {
......
......@@ -11,6 +11,7 @@
import _ from 'lodash';
import {Comentario} from '../../sqldb';
import {Postulante} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
......@@ -111,3 +112,17 @@ export function destroy(req, res) {
.then(removeEntity(res))
.catch(handleError(res));
}
export function comentarios(req, res) {
Postulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(function (postulante) {
postulante.getComentarios()
.then(respondWithResult(res))
})
.catch(handleError(res));
}
......@@ -14,7 +14,15 @@ export default function(sequelize, DataTypes) {
primaryKey: true,
autoIncrement: true
},
contenido: DataTypes.STRING
contenido: {
type: DataTypes.TEXT,
allowNull:false,
validate:{
notEmpty:{
msg:'Por favor ingrese un comentario'
}
}
}
}, {
schema: 'public',
tableName: 'comentario',
......
......@@ -12,4 +12,6 @@ router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
router.get('/postulante/:id',controller.comentarios);
module.exports = router;
......@@ -6,14 +6,12 @@ var controller = require('./postulacion.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:idPostulante',controller.postulante);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
router.get('/postulante/:id',controller.postulaciones);
router.get('/cargo/:id',controller.postulantes);
module.exports = router;
......@@ -12,6 +12,7 @@
import _ from 'lodash';
import {Postulacion} from '../../sqldb';
import {Postulante} from '../../sqldb';
import {Cargo} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
......@@ -112,11 +113,15 @@ export function destroy(req, res) {
.then(removeEntity(res))
.catch(handleError(res));
}
export function postulante(req, res) {
/**
* Obtiene las postulaciones de un determinado postulante
* @param req
* @param res
*/
export function postulaciones(req, res) {
Postulante.find({
where: {
_id: req.params.idPostulante
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
......@@ -128,3 +133,24 @@ export function postulante(req, res) {
})
.catch(handleError(res));
}
/**
* Obtiene los postulantes a un determinado cargo
* @param req
* @param res
*/
export function postulantes(req, res) {
Cargo.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(function (cargos) {
cargos.getPostulantes()
.then(function (postulantes) {
return res.json(postulantes);
})
})
.catch(handleError(res));
}
......@@ -8,7 +8,15 @@ export default function(sequelize, DataTypes) {
primaryKey: true,
autoIncrement: true
},
presentacion: DataTypes.TEXT
presentacion: {
type: DataTypes.TEXT,
allowNull:false,
validate:{
notEmpty:{
msg:'Por favor ingrese un mensaje de presentacion'
}
}
}
}, {
schema: 'public',
tableName: 'postulacion',
......
......@@ -14,7 +14,15 @@ export default function(sequelize, DataTypes) {
primaryKey: true,
autoIncrement: true
},
nombre: DataTypes.STRING
nombre: {
type:DataTypes.STRING,
allowNull:false,
validate:{
notEmpty:{
msg:'Por favor ingrese un nombre para el tag'
}
}
}
}, {
schema: 'public',
tableName: 'tag',
......
......@@ -12,4 +12,7 @@ router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
router.get('/postulante/:id',controller.tags);
router.get('/tags/:id',controller.postulantes);
module.exports = router;
......@@ -11,6 +11,8 @@
import _ from 'lodash';
import {TagPostulante} from '../../sqldb';
import {Postulante} from '../../sqldb';
import {Tag} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
......@@ -111,3 +113,26 @@ export function destroy(req, res) {
.then(removeEntity(res))
.catch(handleError(res));
}
export function tags(req,res) {
Postulante.find({
where: {_id: req.params.id}
})
.then(handleEntityNotFound(res))
.then(function (postulante) {
postulante.getTags()
.then(respondWithResult(res))
})
.catch(handleError(res));
}
export function postulantes(req, res) {
Tag.find({
where: {_id: req.params.id}
})
.then(handleEntityNotFound(res))
.then(function (tag) {
tag.getPostulantes()
.then(respondWithResult(res))
})
.catch(handleError(res));
}
......@@ -25,7 +25,7 @@ var all = {
ip: process.env.IP || '0.0.0.0',
// Should we populate the DB with sample data?
seedDB: false,
seedDB: true,
// Secret for session, you will want to change this and make it an environment variable
secrets: {
......
......@@ -5,40 +5,52 @@
'use strict';
import sqldb from '../sqldb';
var Thing = sqldb.Thing;
Thing.sync()
.then(() => {
return Thing.destroy({ where: {} });
var Tag = sqldb.Tag;
var Cargo = sqldb.Cargo;
//var Comentario = sqldb.Comentario;
//Comentario.sync()
// .then(()=>{
// return Comentario.destroy({where:{}});
// })
// .then(()=>{
// Comentario.bulkCreate([{
//
// }])
// })
Cargo.sync()
.then(()=>{
return Cargo.destroy({where:{}});
})
.then(() => {
Thing.bulkCreate([{
name: 'Development Tools',
info: 'Integration with popular tools such as Bower, Grunt, Babel, Karma, ' +
'Mocha, JSHint, Node Inspector, Livereload, Protractor, Jade, ' +
'Stylus, Sass, and Less.'
}, {
name: 'Server and Client integration',
info: 'Built with a powerful and fun stack: MongoDB, Express, ' +
'AngularJS, and Node.'
}, {
name: 'Smart Build System',
info: 'Build system ignores `spec` files, allowing you to keep ' +
'tests alongside code. Automatic injection of scripts and ' +
'styles into your index.html'
}, {
name: 'Modular Structure',
info: 'Best practice client and server structures allow for more ' +
'code reusability and maximum scalability'
}, {
name: 'Optimized Build',
info: 'Build process packs up your templates as a single JavaScript ' +
'payload, minifies your scripts/css/images, and rewrites asset ' +
'names for caching.'
}, {
name: 'Deployment Ready',
info: 'Easily deploy your app to Heroku or Openshift with the heroku ' +
'and openshift subgenerators'
}]);
.then(()=> {
Cargo.bulkCreate([{
nombre: 'Secretario'
}, {
nombre: 'Encargado de sistemas'
}, {
nombre: 'Jefe de Unidad'
}, {
nombre: 'Director Ejecutivo'
}, {
nombre: 'Consultor'
}])
});
Tag.sync()
.then(()=>{
return Tag.destroy({where:{}});
})
.then(()=> {
Tag.bulkCreate([{
nombre: 'C#'
}, {
nombre: 'Postgres'
}, {
nombre: 'Laravel'
}, {
nombre: 'Node'
}, {
nombre: 'Angular'
}, {
nombre: 'Sequelize'
}
])
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment