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

Servicios y modelos añadidos de las entidades Cargo, Comentario, Postulacion, Tag

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>
......
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/things -> index
* POST /api/things -> create
* GET /api/things/:id -> show
* PUT /api/things/:id -> update
* DELETE /api/things/:id -> destroy
* GET /api/cargos -> index
* POST /api/cargos -> create
* GET /api/cargos/:id -> show
* PUT /api/cargos/:id -> update
* DELETE /api/cargos/:id -> destroy
*/
'use strict';
import _ from 'lodash';
import {Thing} from '../../sqldb';
import {Cargo} from '../../sqldb';
function respondWithResult(res, statusCode) {
statusCode = statusCode || 200;
......@@ -58,16 +58,16 @@ function handleError(res, statusCode) {
};
}
// Gets a list of Things
// Gets a list of Cargos
export function index(req, res) {
Thing.findAll()
Cargo.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single Thing from the DB
// Gets a single Cargo from the DB
export function show(req, res) {
Thing.find({
Cargo.find({
where: {
_id: req.params.id
}
......@@ -77,19 +77,19 @@ export function show(req, res) {
.catch(handleError(res));
}
// Creates a new Thing in the DB
// Creates a new Cargo in the DB
export function create(req, res) {
Thing.create(req.body)
Cargo.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Updates an existing Thing in the DB
// Updates an existing Cargo in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Thing.find({
Cargo.find({
where: {
_id: req.params.id
}
......@@ -100,9 +100,9 @@ export function update(req, res) {
.catch(handleError(res));
}
// Deletes a Thing from the DB
// Deletes a Cargo from the DB
export function destroy(req, res) {
Thing.find({
Cargo.find({
where: {
_id: req.params.id
}
......
/**
* Thing model events
* Cargo model events
*/
'use strict';
import {EventEmitter} from 'events';
var Thing = require('../../sqldb').Thing;
var ThingEvents = new EventEmitter();
var Cargo = require('../../sqldb').Cargo;
var CargoEvents = new EventEmitter();
// Set max event listeners (0 == unlimited)
ThingEvents.setMaxListeners(0);
CargoEvents.setMaxListeners(0);
// Model events
var events = {
......@@ -21,15 +21,15 @@ var events = {
// Register the event emitter to the model events
for (var e in events) {
var event = events[e];
Thing.hook(e, emitEvent(event));
Cargo.hook(e, emitEvent(event));
}
function emitEvent(event) {
return function(doc, options, done) {
ThingEvents.emit(event + ':' + doc._id, doc);
ThingEvents.emit(event, doc);
CargoEvents.emit(event + ':' + doc._id, doc);
CargoEvents.emit(event, doc);
done(null);
}
}
export default ThingEvents;
export default CargoEvents;
......@@ -3,40 +3,40 @@
var app = require('../..');
import request from 'supertest';
var newThing;
var newCargo;
describe('Thing API:', function() {
describe('Cargo API:', function() {
describe('GET /api/things', function() {
var things;
describe('GET /api/cargos', function() {
var cargos;
beforeEach(function(done) {
request(app)
.get('/api/things')
.get('/api/cargos')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
things = res.body;
cargos = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(things).to.be.instanceOf(Array);
expect(cargos).to.be.instanceOf(Array);
});
});
describe('POST /api/things', function() {
describe('POST /api/cargos', function() {
beforeEach(function(done) {
request(app)
.post('/api/things')
.post('/api/cargos')
.send({
name: 'New Thing',
info: 'This is the brand new thing!!!'
name: 'New Cargo',
info: 'This is the brand new cargo!!!'
})
.expect(201)
.expect('Content-Type', /json/)
......@@ -44,55 +44,55 @@ describe('Thing API:', function() {
if (err) {
return done(err);
}
newThing = res.body;
newCargo = res.body;
done();
});
});
it('should respond with the newly created thing', function() {
expect(newThing.name).to.equal('New Thing');
expect(newThing.info).to.equal('This is the brand new thing!!!');
it('should respond with the newly created cargo', function() {
expect(newCargo.name).to.equal('New Cargo');
expect(newCargo.info).to.equal('This is the brand new cargo!!!');
});
});
describe('GET /api/things/:id', function() {
var thing;
describe('GET /api/cargos/:id', function() {
var cargo;
beforeEach(function(done) {
request(app)
.get('/api/things/' + newThing._id)
.get('/api/cargos/' + newCargo._id)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
thing = res.body;
cargo = res.body;
done();
});
});
afterEach(function() {
thing = {};
cargo = {};
});
it('should respond with the requested thing', function() {
expect(thing.name).to.equal('New Thing');
expect(thing.info).to.equal('This is the brand new thing!!!');
it('should respond with the requested cargo', function() {
expect(cargo.name).to.equal('New Cargo');
expect(cargo.info).to.equal('This is the brand new cargo!!!');
});
});
describe('PUT /api/things/:id', function() {
var updatedThing;
describe('PUT /api/cargos/:id', function() {
var updatedCargo;
beforeEach(function(done) {
request(app)
.put('/api/things/' + newThing._id)
.put('/api/cargos/' + newCargo._id)
.send({
name: 'Updated Thing',
info: 'This is the updated thing!!!'
name: 'Updated Cargo',
info: 'This is the updated cargo!!!'
})
.expect(200)
.expect('Content-Type', /json/)
......@@ -100,27 +100,27 @@ describe('Thing API:', function() {
if (err) {
return done(err);
}
updatedThing = res.body;
updatedCargo = res.body;
done();
});
});
afterEach(function() {
updatedThing = {};
updatedCargo = {};
});
it('should respond with the updated thing', function() {
expect(updatedThing.name).to.equal('Updated Thing');
expect(updatedThing.info).to.equal('This is the updated thing!!!');
it('should respond with the updated cargo', function() {
expect(updatedCargo.name).to.equal('Updated Cargo');
expect(updatedCargo.info).to.equal('This is the updated cargo!!!');
});
});
describe('DELETE /api/things/:id', function() {
describe('DELETE /api/cargos/:id', function() {
it('should respond with 204 on successful removal', function(done) {
request(app)
.delete('/api/things/' + newThing._id)
.delete('/api/cargos/' + newCargo._id)
.expect(204)
.end((err, res) => {
if (err) {
......@@ -130,9 +130,9 @@ describe('Thing API:', function() {
});
});
it('should respond with 404 when thing does not exist', function(done) {
it('should respond with 404 when cargo does not exist', function(done) {
request(app)
.delete('/api/things/' + newThing._id)
.delete('/api/cargos/' + newCargo._id)
.expect(404)
.end((err, res) => {
if (err) {
......
'use strict';
/**
* Esta funcion define la entidad Cargo, la cual se relaciona(n-m) con la entidad Postulante
* Este modelo nos muestra el cargo al cual un postulante se postula(valga la redundacia)
* @param sequelize
* @param DataTypes
* @returns {*|{timestamps}|{}|Model}
*/
export default function(sequelize, DataTypes) {
return sequelize.define('Cargo', {
_id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
nombre: DataTypes.STRING
}, {
schema:'public',
tableName: 'cargo',
updatedAt: 'fecha_modificacion',
createdAt: 'fecha_creacion'
});
}
'use strict';
var express = require('express');
var controller = require('./thing.controller');
var controller = require('./cargo.controller');
var router = express.Router();
......
......@@ -2,12 +2,12 @@
var proxyquire = require('proxyquire').noPreserveCache();
var thingCtrlStub = {
index: 'thingCtrl.index',
show: 'thingCtrl.show',
create: 'thingCtrl.create',
update: 'thingCtrl.update',
destroy: 'thingCtrl.destroy'
var cargoCtrlStub = {
index: 'cargoCtrl.index',
show: 'cargoCtrl.show',
create: 'cargoCtrl.create',
update: 'cargoCtrl.update',
destroy: 'cargoCtrl.destroy'
};
var routerStub = {
......@@ -19,76 +19,76 @@ var routerStub = {
};
// require the index with our stubbed out modules
var thingIndex = proxyquire('./index.js', {
var cargoIndex = proxyquire('./index.js', {
'express': {
Router: function() {
return routerStub;
}
},
'./thing.controller': thingCtrlStub
'./cargo.controller': cargoCtrlStub
});
describe('Thing API Router:', function() {
describe('Cargo API Router:', function() {
it('should return an express router instance', function() {
expect(thingIndex).to.equal(routerStub);
expect(cargoIndex).to.equal(routerStub);
});
describe('GET /api/things', function() {
describe('GET /api/cargos', function() {
it('should route to thing.controller.index', function() {
it('should route to cargo.controller.index', function() {
expect(routerStub.get
.withArgs('/', 'thingCtrl.index')
.withArgs('/', 'cargoCtrl.index')
).to.have.been.calledOnce;
});
});
describe('GET /api/things/:id', function() {
describe('GET /api/cargos/:id', function() {
it('should route to thing.controller.show', function() {
it('should route to cargo.controller.show', function() {
expect(routerStub.get
.withArgs('/:id', 'thingCtrl.show')
.withArgs('/:id', 'cargoCtrl.show')
).to.have.been.calledOnce;
});
});
describe('POST /api/things', function() {
describe('POST /api/cargos', function() {
it('should route to thing.controller.create', function() {
it('should route to cargo.controller.create', function() {
expect(routerStub.post
.withArgs('/', 'thingCtrl.create')
.withArgs('/', 'cargoCtrl.create')
).to.have.been.calledOnce;
});
});
describe('PUT /api/things/:id', function() {
describe('PUT /api/cargos/:id', function() {
it('should route to thing.controller.update', function() {
it('should route to cargo.controller.update', function() {
expect(routerStub.put
.withArgs('/:id', 'thingCtrl.update')
.withArgs('/:id', 'cargoCtrl.update')
).to.have.been.calledOnce;
});
});
describe('PATCH /api/things/:id', function() {
describe('PATCH /api/cargos/:id', function() {
it('should route to thing.controller.update', function() {
it('should route to cargo.controller.update', function() {
expect(routerStub.patch
.withArgs('/:id', 'thingCtrl.update')
.withArgs('/:id', 'cargoCtrl.update')
).to.have.been.calledOnce;
});
});
describe('DELETE /api/things/:id', function() {
describe('DELETE /api/cargos/:id', function() {
it('should route to thing.controller.destroy', function() {
it('should route to cargo.controller.destroy', function() {
expect(routerStub.delete
.withArgs('/:id', 'thingCtrl.destroy')
.withArgs('/:id', 'cargoCtrl.destroy')
).to.have.been.calledOnce;
});
......
/**
* Using Rails-like standard naming convention for endpoints.
* GET /api/comentarios -> index
* POST /api/comentarios -> create
* GET /api/comentarios/:id -> show
* PUT /api/comentarios/:id -> update
* DELETE /api/comentarios/:id -> destroy
*/
'use strict';
import _ from 'lodash';
import {Comentario} 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 Comentarios
export function index(req, res) {
Comentario.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single Comentario from the DB
export function show(req, res) {
Comentario.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Creates a new Comentario in the DB
export function create(req, res) {
Comentario.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Updates an existing Comentario in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Comentario.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Deletes a Comentario from the DB
export function destroy(req, res) {
Comentario.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(removeEntity(res))
.catch(handleError(res));
}
/**
* Comentario model events
*/
'use strict';
import {EventEmitter} from 'events';
var Comentario = require('../../sqldb').Comentario;
var ComentarioEvents = new EventEmitter();
// Set max event listeners (0 == unlimited)
ComentarioEvents.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];
Comentario.hook(e, emitEvent(event));
}
function emitEvent(event) {
return function(doc, options, done) {
ComentarioEvents.emit(event + ':' + doc._id, doc);
ComentarioEvents.emit(event, doc);
done(null);
}
}
export default ComentarioEvents;
'use strict';
var app = require('../..');
import request from 'supertest';
var newComentario;
describe('Comentario API:', function() {
describe('GET /api/comentarios', function() {
var comentarios;
beforeEach(function(done) {
request(app)
.get('/api/comentarios')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
comentarios = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(comentarios).to.be.instanceOf(Array);
});
});
describe('POST /api/comentarios', function() {
beforeEach(function(done) {
request(app)
.post('/api/comentarios')
.send({
name: 'New Comentario',
info: 'This is the brand new comentario!!!'
})
.expect(201)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
newComentario = res.body;
done();
});
});
it('should respond with the newly created comentario', function() {
expect(newComentario.name).to.equal('New Comentario');
expect(newComentario.info).to.equal('This is the brand new comentario!!!');
});
});