Skip to content

Commit

Permalink
dbHandler y /archivos/X funcionando, tests actualizados
Browse files Browse the repository at this point in the history
  • Loading branch information
demiurgosoft committed Feb 24, 2016
1 parent c2b7589 commit e867a12
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion app/dbhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = {
var col = db.collection(collection);
col.insertMany(documents, done);
},
getAll: function(collection, done) {
getCollection: function(collection, done) {
var col = db.collection(collection);
col.find({}).toArray(done);
},
Expand Down
28 changes: 19 additions & 9 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ var buscador = require('./routes/buscador');
var calendario = require('./routes/calendario');
var calendarioSolo = require('./routes/calendarioSolo');

var cargar = require('../lib/cargar');
var dbHandler = require('./dbhandler');
var config = require('../config/config');

var cargar = require('../lib/cargar');

var sendCollection = function(res, collection) {
dbHandler.getCollection(collection, function(err, data) {
if (err) res.status(500).json(err);
if (data.length === 0) res.status(404).json(data);
else res.json(data);
});
};


//Generate all the routes
module.exports = function(app) {
Expand Down Expand Up @@ -69,28 +79,28 @@ module.exports = function(app) {

// Archivos de datos
app.get('/archivos/personal', function(req, res) {
res.send(cargar('./config/personal.json'));
sendCollection(res, "personal");
});
app.get('/archivos/infoEconomica', function(req, res) {
res.send(cargar('./config/infoEconomica.json'));
sendCollection(res, "infoEconomica");
});
app.get('/archivos/ofertaDemanda', function(req, res) {
res.send(cargar('./config/ofertaDemanda.json'));
sendCollection(res, "ofertaDemanda");
});
app.get('/archivos/claustro', function(req, res) {
res.send(cargar('./config/claustro.json'));
sendCollection(res, "claustro");
});
app.get('/archivos/estudiantes', function(req, res) {
res.send(cargar('./config/estudiantes.json'));
sendCollection(res, "estudiantes");
});
app.get('/archivos/gobierno', function(req, res) {
res.send(cargar('./config/gobierno.json'));
sendCollection(res, "gobierno");
});
app.get('/archivos/rendimiento', function(req, res) {
res.send(cargar('./config/rendimiento.json'));
sendCollection(res, "rendimiento");
});
app.get('/archivos/normativaLegal', function(req, res) {
res.send(cargar('./config/normativaLegal.json'));
sendCollection(res, "normativaLegal");
});
// Manejador de errores:
app.use(function(req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion test/acceso.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ describe("Pruebas en producción", function() {
done();
});
});
});
});
4 changes: 2 additions & 2 deletions test/archivos.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('Archivos de configuración', function() {
var existe = require('../lib/existe');
var cargar = require('../lib/cargar');
_.each(config.archivosJSON, function(valor) {
assert.ok(existe('./config/' + valor));
var file = cargar('./config/' + valor);
assert.ok(existe('./config/jsons/' + valor));
var file = cargar('./config/jsons/' + valor);
assert.ok(file);
});

Expand Down
14 changes: 7 additions & 7 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var express = require('express');

var dbHandler=require('../app/dbhandler');

module.exports = {
archivosJSON: [
Expand Down Expand Up @@ -62,11 +62,11 @@ module.exports = {
var routes = require('../app/routes');
serverConfig(app);
routes(app);

server = app.listen(app.get('port'), app.get('ip'), function() {
done(app, server);
dbHandler.initDatabase(function(err) {
if(err) console.log("Database Init problem");
server = app.listen(app.get('port'), app.get('ip'), function() {
done(app, server);
});
});


}
};
};

0 comments on commit e867a12

Please sign in to comment.