Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Feedback and GHC Signups are now stored in a DB, not files.
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelAPB committed Jan 23, 2018
1 parent b40f968 commit 922a946
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 6 deletions.
28 changes: 28 additions & 0 deletions server/mongodb/accesses/access-feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Feedback = require('../models/feedback');
let TYPE = 'Feedback';

class AccessFeedback {
constructor() {
this.addFeedback = addFeedback;
}
}

let access_signup = module.exports = exports = new AccessFeedback();


/********************************
* C.R.U.D. FUNCTIONS
*******************************/
function addFeedback(name, entity, email, rating, message, intention, callback) {
let newFeedback = new Feedback({
name: name,
entity: entity,
email: email,
rating: rating,
message: message,
intention: intention
});

newFeedback.save(callback);

}
30 changes: 30 additions & 0 deletions server/mongodb/accesses/access-signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Signup = require('../models/signup');
const Utils = require('./utils-accesses');
let TYPE = 'Signup';

class AccessSignup {
constructor() {
this.addPreSignup = addPreSignup;
}
}

let access_signup = module.exports = exports = new AccessSignup();


/********************************
* C.R.U.D. FUNCTIONS
*******************************/
function addPreSignup(teamName, teamCaptain, teamContactEmail, teamContactPhone, participantsNumber, newsletter, EmailIST, callback) {
let newSignup = new Signup({
teamName: teamName,
teamCaptain: teamCaptain,
teamContactEmail: teamContactEmail,
teamContactPhone: teamContactPhone,
participantsNumber: participantsNumber,
newsletter: newsletter,
EmailIST: EmailIST
});

newSignup.save(callback);

}
2 changes: 2 additions & 0 deletions server/mongodb/accesses/mongo-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ function MongoAccess() {
this.professors = require('./access-professor');
this.applications = require('./access-application');
this.admins = require('./access-admin');
this.signup = require('./access-signup');
this.users = require('./access-user');
this.utils = require('./utils-accesses');
this.feedback = require('./access-feedback');
}

let mongo_access = module.exports = exports = new MongoAccess;
32 changes: 32 additions & 0 deletions server/mongodb/models/feedback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const mongoose = require('mongoose');

// User Schema - Abstract

const FeedbackSchema = mongoose.Schema({
entity: {
type: String,
required: true
},
intention: {
type: String,
required: true
},
rating: {
type: Number,
required: true
},
name: {
type: String,
required: true
},
email: {
type: String,
required: true
},
message: {
type: String,
required: true,
}
});

const Feedback = module.exports = mongoose.model('Feedback', FeedbackSchema);
36 changes: 36 additions & 0 deletions server/mongodb/models/signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const mongoose = require('mongoose');

// User Schema - Abstract

const SignupSchema = mongoose.Schema({
teamName: {
type: String,
required: true
},
teamCaptain: {
type: String,
required: true
},
teamContactEmail: {
type: String,
required: true
},
teamContactPhone: {
type: String,
required: false
},
EmailIST: {
type: String,
required: true
},
participantsNumber: {
type: String,
required: true
},
newsletter: {
type: Boolean,
required: true,
}
});

const Feedback = module.exports = mongoose.model('Signup', SignupSchema);
27 changes: 24 additions & 3 deletions server/routes/general-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,44 @@ const UtilsRoutes = require('./utils-routes');
const multer = require('multer');
const ba_logger = require('../log/ba_logger');
const Utils = require('../mongodb/accesses/utils-accesses');
const passport = require('passport');
const DBAccess = require('../mongodb/accesses/mongo-access');
const ERROR = "Não foi possível concluir o registo. Contacte a administração.";

//If you wish to save signups as a file
const fs = require('fs');
const path = require('path');
const passport = require('passport');


//Others, related with student
router.post('/signupHashCode', passport.authenticate('jwt', {session: false}), (req, res, next) => {
if(!UtilsRoutes.roleIs(req,'Student')) {
UtilsRoutes.replyFailure(res,"","Só os estudantes podem inscrever-se");
return;
}
// return false se n

const teamName = req.body.signup.teamName;
const teamCaptain = req.body.signup.teamCaptain;
const teamContactEmail = req.body.signup.teamContactEmail;
const teamContactPhone = req.body.signup.teamContactPhone;
const newsletter = req.body.signup.newsletter;
const participantsNumber = req.body.signup.participantsNumber;
const nomeAluno = req.user.name;
//const nomeAluno = req.user.name;
const emailAluno = req.user.email;

DBAccess.signup.addPreSignup(teamName, teamCaptain,teamContactEmail,
teamContactPhone,participantsNumber,newsletter,emailAluno, (err) => {
if (err) {
console.log(err);
return UtilsRoutes.replyFailure(res,err,ERROR);
} else {
return UtilsRoutes.replySuccess(res,"","");
}
});



/* Save as a file
fileContent =
"[EQUIPA]:" + teamName + "\n" +
"[RESPONSÁVEL]:" + teamCaptain + "\n" +
Expand All @@ -37,6 +55,8 @@ router.post('/signupHashCode', passport.authenticate('jwt', {session: false}), (
"[NOME]:" + nomeAluno + "\n" +
"[EMAIL]:" + emailAluno;
const filePath = '../files/GoogleHashCode/' + emailAluno + " [" + Date.now() + "].txt";
fs.writeFile(path.join(__dirname, filePath), fileContent, function (err) {
Expand All @@ -47,6 +67,7 @@ router.post('/signupHashCode', passport.authenticate('jwt', {session: false}), (
ba_logger.ba("Nova Pré-Inscrição:" + teamCaptain + ":" + Utils.utc);
UtilsRoutes.replySuccess(res, "", "Inscrição efetuado com sucesso");
});
*/

});

Expand Down
18 changes: 15 additions & 3 deletions server/routes/user-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const WRONG_PASSWORD_PART_2 = " tentativas restantes.";
const WRONG_PASSWORD_INVALIDATE = "Errou todas as tentativas. A sua conta encontra-se invalidada. Por favor contacte a administração";
const USER_INVALID = "A sua conta está invalidada. Por favor contacte a administração";
const USER_UNCONFIRMED = "A sua conta está por confirmar. Por favor contacte a administração, para que se proceda à ativação da conta";
const ERROR_F = "Não foi possível adicionar feedback. Por favor contacte a administração";

router.post('/login', (req, res, next) => {
const email = req.body.username;
Expand Down Expand Up @@ -109,8 +110,19 @@ router.post('/feedback', (req, res, next) => {
const message = req.body.message;
const rate = req.body.rate;
const entity = req.body.entity;
const type = req.body.type;

const intention = req.body.type;

DBAccess.feedback.addFeedback(name, entity,email,
rate,message,intention, (err) => {
if (err) {
console.log(err);
return UtilsRoutes.replyFailure(res,err,ERROR_F);
} else {
return UtilsRoutes.replySuccess(res,"","");
}
});

/*Save as a file
fileContent = "[TYPE]:" + type + "\n" +
"[RATE]:" + rate + "\n" +
"[NOME]:" + name + "\n" + "[EMAIL]:" + email + "\n" +
Expand All @@ -126,7 +138,7 @@ router.post('/feedback', (req, res, next) => {
ba_logger.ba("Feedback:" + email + ":Gave Feedback:" + Utils.utc);
UtilsRoutes.replySuccess(res, "", "Feedback foi enviado com sucesso");
});

*/
});

module.exports = router;

0 comments on commit 922a946

Please sign in to comment.