Skip to content

Commit

Permalink
moongose-csv
Browse files Browse the repository at this point in the history
  • Loading branch information
mukuljainx committed Jan 8, 2017
1 parent 210284d commit 12b7266
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 20 deletions.
3 changes: 2 additions & 1 deletion models/astronomy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var astronomyRegistrationSchema = mongoose.Schema({
team : [
Expand All @@ -25,5 +25,6 @@ var astronomyRegistrationSchema = mongoose.Schema({
},
});

astronomyRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Astronomy', astronomyRegistrationSchema);
2 changes: 2 additions & 0 deletions models/contact.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
var mongoose = require('mongoose');
var mongoose_csv = require('mongoose-csv');

var contactSchema = mongoose.Schema({
name : String,
email : String,
query : String,
});

contactSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Contact', contactSchema);
2 changes: 2 additions & 0 deletions models/cybros.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
var mongoose_csv = require('mongoose-csv');


var cybrosRegistrationSchema = mongoose.Schema({
Expand All @@ -25,5 +26,6 @@ var cybrosRegistrationSchema = mongoose.Schema({
},
});

cybrosRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Cybros', cybrosRegistrationSchema);
3 changes: 2 additions & 1 deletion models/ecell.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var ecellRegistrationSchema = mongoose.Schema({
team : [
Expand Down Expand Up @@ -27,5 +27,6 @@ var ecellRegistrationSchema = mongoose.Schema({
},
});

ecellRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Ecell', ecellRegistrationSchema);
3 changes: 2 additions & 1 deletion models/literary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var literaryRegistrationSchema = mongoose.Schema({
team : [
Expand All @@ -25,5 +25,6 @@ var literaryRegistrationSchema = mongoose.Schema({
},
});

literaryRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Literary', literaryRegistrationSchema);
3 changes: 2 additions & 1 deletion models/payment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var paymentSchema = mongoose.Schema({
id : String,
Expand All @@ -8,5 +8,6 @@ var paymentSchema = mongoose.Schema({
order_id : String
});

paymentSchema.plugin(mongoose_csv);
// create the model for payments and expose it to our app
module.exports = mongoose.model('PaymentDB', paymentSchema);
4 changes: 2 additions & 2 deletions models/paymentMUN.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var paymentMUNSchema = mongoose.Schema({
order_id : String,
Expand All @@ -16,6 +16,6 @@ var paymentMUNSchema = mongoose.Schema({
timestamps: { createdAt: 'created_at' }
}
);

paymentMUNSchema.plugin(mongoose_csv);
// create the model for payments and expose it to our app
module.exports = mongoose.model('PaymentMUN', paymentMUNSchema);
4 changes: 2 additions & 2 deletions models/paymentSIF.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var paymentSIFSchema = mongoose.Schema({
order_id : String,
Expand All @@ -13,6 +13,6 @@ var paymentSIFSchema = mongoose.Schema({
timestamps: { createdAt: 'created_at' }
}
);

paymentSIFSchema.plugin(mongoose_csv);
// create the model for payments and expose it to our app
module.exports = mongoose.model('PaymentSIF', paymentSIFSchema);
4 changes: 2 additions & 2 deletions models/quiz.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var quizRegistrationSchema = mongoose.Schema({
team : [
Expand All @@ -24,6 +24,6 @@ var quizRegistrationSchema = mongoose.Schema({
amount : String,
},
});

quizRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Quiz', quizRegistrationSchema);
4 changes: 2 additions & 2 deletions models/robotics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var roboticsRegistrationSchema = mongoose.Schema({
team : [
Expand All @@ -24,6 +24,6 @@ var roboticsRegistrationSchema = mongoose.Schema({
amount : String,
},
});

roboticsRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Robotics', roboticsRegistrationSchema);
4 changes: 2 additions & 2 deletions models/sif.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var sifSchema = mongoose.Schema({
detail:
Expand All @@ -24,6 +24,6 @@ var sifSchema = mongoose.Schema({
amount : Number,
},
});

sifSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('SIF', sifSchema);
6 changes: 3 additions & 3 deletions models/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mongoose = require('mongoose');

var mongoose_csv = require('mongoose-csv');

var userSchema = mongoose.Schema({
googletoken : String,
Expand All @@ -9,7 +9,7 @@ var userSchema = mongoose.Schema({
email : String,
name : String,
phoneNumber : Number,
cryptexLevel : Number,
cryptexLevel : Number,
cryptexTime : Number, //the time when cryptexLevel got updated;
college : String,
year : Number,
Expand All @@ -20,6 +20,6 @@ var userSchema = mongoose.Schema({
events : Array,
paidEvents : Array,
});

userSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);
3 changes: 2 additions & 1 deletion models/workshop.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mongoose = require('mongoose');
var mongoose_csv = require('mongoose-csv');

var workshopRegistrationSchema = mongoose.Schema({
team : [
Expand All @@ -23,6 +24,6 @@ var workshopRegistrationSchema = mongoose.Schema({
amount : String,
},
});

workshopRegistrationSchema.plugin(mongoose_csv);
// create the model for users and expose it to our app
module.exports = mongoose.model('Workshop', workshopRegistrationSchema);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"jade": "~1.11.0",
"jsonwebtoken": "^7.1.9",
"mongoose": "^4.6.3",
"mongoose-csv": "^1.0.0",
"mongoose-currency": "^0.2.0",
"morgan": "~1.7.0",
"njwt": "^0.3.2",
Expand Down
4 changes: 3 additions & 1 deletion public/partials/users.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
padding: 10px 5px;
}
</style>

<div class="row">
<a href="/results/user/registered/csv">Export to csv</a>
</div>
<section>
<% for(var i=0; i<results.length; i++) { %>
<div class="row">
Expand Down
2 changes: 1 addition & 1 deletion routes/cryptex.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ router.get('/leaderboard', Verify.verifyOrdinaryUser ,function(req, res) {
};
if(req.decoded.sub === ""){
isLoggedIn = false;
User.find({'cryptexLevel' : { $exists : true}}, null, {sort : {'cryptexLevel' : -1, 'cryptexTime' : 1 }}, function(err,results){
User.find({'cryptexLevel' : { $exists : true}}, usersProjection, {sort : {'cryptexLevel' : -1, 'cryptexTime' : 1 }}, function(err,results){
res.render('cryptex_leaderboard', {
"isLoggedIn" : isLoggedIn,
results : results
Expand Down
86 changes: 86 additions & 0 deletions routes/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ var PaymentDB = require('../models/payment');
var PaymentMUN = require('../models/paymentMUN');
var PaymentSIF = require('../models/paymentSIF');
var EventURL = require('../config/eventURL');
var mongoose_csv = require('mongoose-csv');



router.get('/sif/startup', Verify.verifyOrdinaryUser ,function(req, res) {
Expand Down Expand Up @@ -280,5 +282,89 @@ router.get('/user/registered', Verify.verifyOrdinaryUser ,function(req, res) {
});
});

router.get('/user/registered/csv', Verify.verifyOrdinaryUser ,function(req, res) {
var poc = authUser.poc;
if(req.decoded.sub === "" || (poc.indexOf(req.decoded.sub) === -1)){
res.end("You are not authorized. Login and try");
return;
}
res.writeHead(200, {
'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename=registereduser.csv'
});
// pipe file using mongoose-csv
User.find().csv(res);
});


router.get('/csv/*', Verify.verifyOrdinaryUser ,function(req, res) {
var poc = authUser.poc;
var allowedUser = ['[email protected]'];
var paymentUser = poc.slice(0);

if(EventURL[req.query.event] === undefined){
res.end('Please Check the link once again there may some typo in event name');
return;
}

switch(req.params['0']) {
case "astronomy":
eventx = Astronomy;
allowedUser = authUser.astronomy;
paymentUser = paymentUser.concat(allowedUser[0]);
break;
case "coding":
eventx = Cybros;
allowedUser = authUser.cybros;
paymentUser = paymentUser.concat(allowedUser[0]);
break;
case "literature":
eventx = Literary;
break;
case "robotics":
eventx = Robotics;
allowedUser = authUser.robotics;
paymentUser = paymentUser.concat(allowedUser[0]);
break;
case "management":
eventx = Ecell;
allowedUser = authUser.ecell;
paymentUser = paymentUser.concat(allowedUser[0]);
break;
case "quizzing":
eventx = Quiz;
allowedUser = authUser.quiz;
paymentUser = paymentUser.concat(allowedUser[0]);
break;
case "workshop":
eventx = Workshop;
allowedUser = authUser.admin;
break;
default:
res.end('Please Check the link once again there may some typo in club name');
return;
break;
}
if(req.decoded.sub === "" || (poc.indexOf(req.decoded.sub) === -1 && allowedUser.indexOf(req.decoded.sub) === -1)){
res.end("You are not authorized. Login and try");
return;
}

User.findOne({'email' : req.decoded.sub }, function(err, user) {
// if there are any errors, return the error
if (err){
return done(err);
}
// check to see if theres already a user with that email
if (user){
res.writeHead(200, {
'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename=' + req.query.event + '.csv'
});
eventx.find({'eventName' : req.query.event}).csv(res);
}
});
});


module.exports = router;

0 comments on commit 12b7266

Please sign in to comment.