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

resolviendo confilctos

parents 102f90b1 ee18529a
/**
* Using Rails-like standard naming convention for endpoints.
* 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 {Cargo} 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 Cargos
export function index(req, res) {
Cargo.findAll()
.then(respondWithResult(res))
.catch(handleError(res));
}
// Gets a single Cargo from the DB
export function show(req, res) {
Cargo.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Creates a new Cargo in the DB
export function create(req, res) {
Cargo.create(req.body)
.then(respondWithResult(res, 201))
.catch(handleError(res));
}
// Updates an existing Cargo in the DB
export function update(req, res) {
if (req.body._id) {
delete req.body._id;
}
Cargo.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(saveUpdates(req.body))
.then(respondWithResult(res))
.catch(handleError(res));
}
// Deletes a Cargo from the DB
export function destroy(req, res) {
Cargo.find({
where: {
_id: req.params.id
}
})
.then(handleEntityNotFound(res))
.then(removeEntity(res))
.catch(handleError(res));
}
/**
* Cargo model events
*/
'use strict';
import {EventEmitter} from 'events';
var Cargo = require('../../sqldb').Cargo;
var CargoEvents = new EventEmitter();
// Set max event listeners (0 == unlimited)
CargoEvents.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];
Cargo.hook(e, emitEvent(event));
}
function emitEvent(event) {
return function(doc, options, done) {
CargoEvents.emit(event + ':' + doc._id, doc);
CargoEvents.emit(event, doc);
done(null);
}
}
export default CargoEvents;
'use strict';
var app = require('../..');
import request from 'supertest';
var newCargo;
describe('Cargo API:', function() {
describe('GET /api/cargos', function() {
var cargos;
beforeEach(function(done) {
request(app)
.get('/api/cargos')
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
cargos = res.body;
done();
});
});
it('should respond with JSON array', function() {
expect(cargos).to.be.instanceOf(Array);
});
});
describe('POST /api/cargos', function() {
beforeEach(function(done) {
request(app)
.post('/api/cargos')
.send({
name: 'New Cargo',
info: 'This is the brand new cargo!!!'
})
.expect(201)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
newCargo = res.body;
done();
});
});
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/cargos/:id', function() {
var cargo;
beforeEach(function(done) {
request(app)
.get('/api/cargos/' + newCargo._id)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
cargo = res.body;
done();
});
});
afterEach(function() {
cargo = {};
});
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/cargos/:id', function() {
var updatedCargo;
beforeEach(function(done) {
request(app)
.put('/api/cargos/' + newCargo._id)
.send({
name: 'Updated Cargo',
info: 'This is the updated cargo!!!'
})
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
return done(err);
}
updatedCargo = res.body;
done();
});
});
afterEach(function() {
updatedCargo = {};
});
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/cargos/:id', function() {
it('should respond with 204 on successful removal', function(done) {
request(app)
.delete('/api/cargos/' + newCargo._id)
.expect(204)
.end((err, res) => {
if (err) {
return done(err);
}
done();
});
});
it('should respond with 404 when cargo does not exist', function(done) {
request(app)
.delete('/api/cargos/' + newCargo._id)
.expect(404)
.end((err, res) => {
if (err) {
return done(err);
}
done();
});
});
});
});
'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('./cargo.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 cargoCtrlStub = {
index: 'cargoCtrl.index',
show: 'cargoCtrl.show',
create: 'cargoCtrl.create',
update: 'cargoCtrl.update',
destroy: 'cargoCtrl.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 cargoIndex = proxyquire('./index.js', {
'express': {
Router: function() {
return routerStub;
}
},
'./cargo.controller': cargoCtrlStub
});
describe('Cargo API Router:', function() {
it('should return an express router instance', function() {
expect(cargoIndex).to.equal(routerStub);
});
describe('GET /api/cargos', function() {
it('should route to cargo.controller.index', function() {
expect(routerStub.get
.withArgs('/', 'cargoCtrl.index')
).to.have.been.calledOnce;
});
});
describe('GET /api/cargos/:id', function() {
it('should route to cargo.controller.show', function() {
expect(routerStub.get
.withArgs('/:id', 'cargoCtrl.show')
).to.have.been.calledOnce;
});
});
describe('POST /api/cargos', function() {
it('should route to cargo.controller.create', function() {
expect(routerStub.post
.withArgs('/', 'cargoCtrl.create')
).to.have.been.calledOnce;
});
});
describe('PUT /api/cargos/:id', function() {
it('should route to cargo.controller.update', function() {
expect(routerStub.put
.withArgs('/:id', 'cargoCtrl.update')
).to.have.been.calledOnce;
});
});
describe('PATCH /api/cargos/:id', function() {
it('should route to cargo.controller.update', function() {
expect(routerStub.patch
.withArgs('/:id', 'cargoCtrl.update')
).to.have.been.calledOnce;
});
});
describe('DELETE /api/cargos/:id', function() {
it('should route to cargo.controller.destroy', function() {
expect(routerStub.delete
.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!!!');
});
});
describe('GET /api/comentarios/:id', function() {
var comentario;
beforeEach(function(done) {
request(app)
.get('/api/comentarios/' + newComentario._id)
.expect(200)
.expect('Content-Type', /json/)
.end((err, res) => {
if (err) {
return done(err);
}
comentario = res.body;
done();
});
});
afterEach(function() {
comentario = {};
});
it('should respond with the requested comentario', function() {
expect(comentario.name).to.equal('New Comentario');
expect(comentario.info).to.equal('This is the brand new comentario!!!');
});
});
describe('PUT /api/comentarios/:id', function() {
var updatedComentario;
beforeEach(function(done) {
request(app)
.put('/api/comentarios/' + newComentario._id)
.send({
name: 'Updated Comentario',
info: 'This is the updated comentario!!!'
})
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) {
return done(err);
}
updatedComentario = res.body;
done();
});
});
afterEach(function() {
updatedComentario = {};
});
it('should respond with the updated comentario', function() {
expect(updatedComentario.name).to.equal('Updated Comentario');
expect(updatedComentario.info).to.equal('This is the updated comentario!!!');
});
});
describe('DELETE /api/comentarios/:id', function() {