Desarrollo de los servicios Postulantes [iss02]

parent 7de939b4
(function(angular, undefined) {
'use strict';
angular.module('moduloPersonalApp.constants', [])
.constant('appConfig', {userRoles:['guest','user','admin']})
;
})(angular);
\ No newline at end of file
......@@ -16,7 +16,7 @@ $fa-font-path: "../bower_components/font-awesome/fonts";
// Component styles are injected through grunt
// injector
@import 'account/login/login.scss';
@import 'admin/admin.scss';
@import 'main/main.scss';
@import '../components/footer/footer.scss';
@import '../components/modal/modal.scss';
// endinjector
......@@ -48,11 +48,28 @@
<![endif]-->
<!-- build:js({client,node_modules}) app/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="bower_components/lodash/dist/lodash.compat.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<!-- endbower -->
<!-- endbuild -->
<!-- build:js(.tmp) app/app.js -->
<script src="app/app.js"></script>
<!-- injector:js -->
<script src="components/util/util.module.js"></script>
<script src="app/app.constant.js"></script>
<script src="app/main/main.controller.js"></script>
<script src="app/main/main.js"></script>
<script src="components/footer/footer.directive.js"></script>
<script src="components/modal/modal.service.js"></script>
<script src="components/navbar/navbar.controller.js"></script>
<script src="components/navbar/navbar.directive.js"></script>
<script src="components/util/util.service.js"></script>
<!-- endinjector -->
<!-- endbuild -->
</body>
......
** MANEJO DE POSTULANTES
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/datoPostulantes -> index
* POST /api/datoPostulantes -> create
* GET /api/datoPostulantes/:id -> show
* PUT /api/datoPostulantes/:id -> update
* DELETE /api/datoPostulantes/:id -> destroy
*/
'use strict';
import _ from 'lodash';
import {DatoPostulante} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
return function(entity) {
if (entity) {
res.status(statusCode).json(entity);
}
};
}
function saveUpdates(updates) {
return function(entity) {
return entity.updateAttributes(updates)
.then(updated => {
return updated;
});
};
}
function removeEntity(res) {
return function(entity) {
if (entity) {
return entity.destroy()
.then(() => {
res.status(204).end();
});
}
};
}
function handleEntityNotFound(res) {
return function(entity) {
if (!entity) {
res.status(404).end();
return null;
}
return entity;
};
}
function handleError(res, statusCode) {
statusCode = statusCode || 500;
return function(err) {
res.status(statusCode).send(err);
};
}
// Gets a list of DatoPostulantes
export function index(req, res) {
DatoPostulante.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single DatoPostulante from the DB
export function show(req, res) {
DatoPostulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Creates a new DatoPostulante in the DB
export function create(req, res) {
DatoPostulante.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Updates an existing DatoPostulante in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
DatoPostulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Deletes a DatoPostulante from the DB
export function destroy(req, res) {
DatoPostulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(removeEntity(res))
.catch(handleError(res));
}
/**
* DatoPostulante model events
*/
'use strict';
import {EventEmitter} from 'events';
var DatoPostulante = require('../../sqldb').DatoPostulante;
var DatoPostulanteEvents = new EventEmitter();
// Set max event listeners (0 == unlimited)
DatoPostulanteEvents.setMaxListeners(0);
// Model events
var events = {
'afterCreate': 'save',
'afterUpdate': 'save',
'afterDestroy': 'remove'
};
// Register the event emitter to the model events
for (var e in events) {
var event = events[e];
DatoPostulante.hook(e, emitEvent(event));
}
function emitEvent(event) {
return function(doc, options, done) {
DatoPostulanteEvents.emit(event + ':' + doc._id, doc);
DatoPostulanteEvents.emit(event, doc);
done(null);
}
}
export default DatoPostulanteEvents;
'use strict';
var app = require('../..');
import request from 'supertest';
var newDatoPostulante;
describe('DatoPostulante API:', function() {
describe('GET /api/datoPostulantes', function() {
var datoPostulantes;
beforeEach(function(done) {
request(app)
.get('/api/datoPostulantes')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
datoPostulantes = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(datoPostulantes).to.be.instanceOf(Array);
});
});
describe('POST /api/datoPostulantes', function() {
beforeEach(function(done) {
request(app)
.post('/api/datoPostulantes')
.send({
name: 'New DatoPostulante',
info: 'This is the brand new datoPostulante!!!'
})
.expect(201)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
newDatoPostulante = res.body;
done();
});
});
it('should respond with the newly created datoPostulante', function() {
expect(newDatoPostulante.name).to.equal('New DatoPostulante');
expect(newDatoPostulante.info).to.equal('This is the brand new datoPostulante!!!');
});
});
describe('GET /api/datoPostulantes/:id', function() {
var datoPostulante;
beforeEach(function(done) {
request(app)
.get('/api/datoPostulantes/' + newDatoPostulante._id)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
datoPostulante = res.body;
done();
});
});
afterEach(function() {
datoPostulante = {};
});
it('should respond with the requested datoPostulante', function() {
expect(datoPostulante.name).to.equal('New DatoPostulante');
expect(datoPostulante.info).to.equal('This is the brand new datoPostulante!!!');
});
});
describe('PUT /api/datoPostulantes/:id', function() {
var updatedDatoPostulante;
beforeEach(function(done) {
request(app)
.put('/api/datoPostulantes/' + newDatoPostulante._id)
.send({
name: 'Updated DatoPostulante',
info: 'This is the updated datoPostulante!!!'
})
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
return done(err);
}
updatedDatoPostulante = res.body;
done();
});
});
afterEach(function() {
updatedDatoPostulante = {};
});
it('should respond with the updated datoPostulante', function() {
expect(updatedDatoPostulante.name).to.equal('Updated DatoPostulante');
expect(updatedDatoPostulante.info).to.equal('This is the updated datoPostulante!!!');
});
});
describe('DELETE /api/datoPostulantes/:id', function() {
it('should respond with 204 on successful removal', function(done) {
request(app)
.delete('/api/datoPostulantes/' + newDatoPostulante._id)
.expect(204)
.end((err, res) => {
if (err) {
return done(err);
}
done();
});
});
it('should respond with 404 when datoPostulante does not exist', function(done) {
request(app)
.delete('/api/datoPostulantes/' + newDatoPostulante._id)
.expect(404)
.end((err, res) => {
if (err) {
return done(err);
}
done();
});
});
});
});
'use strict';
export default function(sequelize, DataTypes) {
return sequelize.define('DatoPostulante', {
_id: {
allowNull: false,
primaryKey: true,
autoIncrement: true,
type: DataTypes.INTEGER
},
nombre: {
allowNull: false,
type: DataTypes.STRING(50)
},
propiedad: {
allowNull: false,
type: DataTypes.STRING(50)
}
},{
schema: 'public',
tableName: 'dato_postulante'
});
}
'use strict';
var express = require('express');
var controller = require('./datoPostulante.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
module.exports = router;
'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var datoPostulanteCtrlStub = {
index: 'datoPostulanteCtrl.index',
show: 'datoPostulanteCtrl.show',
create: 'datoPostulanteCtrl.create',
update: 'datoPostulanteCtrl.update',
destroy: 'datoPostulanteCtrl.destroy'
};
var routerStub = {
get: sinon.spy(),
put: sinon.spy(),
patch: sinon.spy(),
post: sinon.spy(),
delete: sinon.spy()
};
// require the index with our stubbed out modules
var datoPostulanteIndex = proxyquire('./index.js', {
'express': {
Router: function() {
return routerStub;
}
},
'./datoPostulante.controller': datoPostulanteCtrlStub
});
describe('DatoPostulante API Router:', function() {
it('should return an express router instance', function() {
expect(datoPostulanteIndex).to.equal(routerStub);
});
describe('GET /api/datoPostulantes', function() {
it('should route to datoPostulante.controller.index', function() {
expect(routerStub.get
.withArgs('/', 'datoPostulanteCtrl.index')
).to.have.been.calledOnce;
});
});
describe('GET /api/datoPostulantes/:id', function() {
it('should route to datoPostulante.controller.show', function() {
expect(routerStub.get
.withArgs('/:id', 'datoPostulanteCtrl.show')
).to.have.been.calledOnce;
});
});
describe('POST /api/datoPostulantes', function() {
it('should route to datoPostulante.controller.create', function() {
expect(routerStub.post
.withArgs('/', 'datoPostulanteCtrl.create')
).to.have.been.calledOnce;
});
});
describe('PUT /api/datoPostulantes/:id', function() {
it('should route to datoPostulante.controller.update', function() {
expect(routerStub.put
.withArgs('/:id', 'datoPostulanteCtrl.update')
).to.have.been.calledOnce;
});
});
describe('PATCH /api/datoPostulantes/:id', function() {
it('should route to datoPostulante.controller.update', function() {
expect(routerStub.patch
.withArgs('/:id', 'datoPostulanteCtrl.update')
).to.have.been.calledOnce;
});
});
describe('DELETE /api/datoPostulantes/:id', function() {
it('should route to datoPostulante.controller.destroy', function() {
expect(routerStub.delete
.withArgs('/:id', 'datoPostulanteCtrl.destroy')
).to.have.been.calledOnce;
});
});
});
'use strict';
var express = require('express');
var controller = require('./postulante.controller');
var router = express.Router();
router.get('/', controller.index);
router.get('/:id', controller.show);
router.post('/', controller.create);
router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);
module.exports = router;
'use strict';
var proxyquire = require('proxyquire').noPreserveCache();
var postulanteCtrlStub = {
index: 'postulanteCtrl.index',
show: 'postulanteCtrl.show',
create: 'postulanteCtrl.create',
update: 'postulanteCtrl.update',
destroy: 'postulanteCtrl.destroy'
};
var routerStub = {
get: sinon.spy(),
put: sinon.spy(),
patch: sinon.spy(),
post: sinon.spy(),
delete: sinon.spy()
};
// require the index with our stubbed out modules
var postulanteIndex = proxyquire('./index.js', {
'express': {
Router: function() {
return routerStub;
}
},
'./postulante.controller': postulanteCtrlStub
});
describe('Postulante API Router:', function() {
it('should return an express router instance', function() {
expect(postulanteIndex).to.equal(routerStub);
});
describe('GET /api/postulantes', function() {
it('should route to postulante.controller.index', function() {
expect(routerStub.get
.withArgs('/', 'postulanteCtrl.index')
).to.have.been.calledOnce;
});
});
describe('GET /api/postulantes/:id', function() {
it('should route to postulante.controller.show', function() {
expect(routerStub.get
.withArgs('/:id', 'postulanteCtrl.show')
).to.have.been.calledOnce;
});
});
describe('POST /api/postulantes', function() {
it('should route to postulante.controller.create', function() {
expect(routerStub.post
.withArgs('/', 'postulanteCtrl.create')
).to.have.been.calledOnce;
});
});
describe('PUT /api/postulantes/:id', function() {
it('should route to postulante.controller.update', function() {
expect(routerStub.put
.withArgs('/:id', 'postulanteCtrl.update')
).to.have.been.calledOnce;
});
});
describe('PATCH /api/postulantes/:id', function() {
it('should route to postulante.controller.update', function() {
expect(routerStub.patch
.withArgs('/:id', 'postulanteCtrl.update')
).to.have.been.calledOnce;
});
});
describe('DELETE /api/postulantes/:id', function() {
it('should route to postulante.controller.destroy', function() {
expect(routerStub.delete
.withArgs('/:id', 'postulanteCtrl.destroy')
).to.have.been.calledOnce;
});
});
});
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/postulantes -> index
* POST /api/postulantes -> create
* GET /api/postulantes/:id -> show
* PUT /api/postulantes/:id -> update
* DELETE /api/postulantes/:id -> destroy
*/
'use strict';
import _ from 'lodash';
import {Postulante} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
return function(entity) {
if (entity) {
res.status(statusCode).json(entity);
}
};
}
function saveUpdates(updates) {
return function(entity) {
return entity.updateAttributes(updates)
.then(updated => {
return updated;
});
};
}
function removeEntity(res) {
return function(entity) {
if (entity) {
return entity.destroy()
.then(() => {
res.status(204).end();
});
}
};
}
function handleEntityNotFound(res) {
return function(entity) {
if (!entity) {
res.status(404).end();
return null;
}
return entity;
};
}
function handleError(res, statusCode) {
statusCode = statusCode || 500;
return function(err) {
res.status(statusCode).send(err);
};
}
// Gets a list of Postulantes
export function index(req, res) {
Postulante.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single Postulante from the DB
export function show(req, res) {
Postulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Creates a new Postulante in the DB
export function create(req, res) {
Postulante.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Updates an existing Postulante in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Postulante.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))