Skip to content

Commit

Permalink
Implemented diff #52
Browse files Browse the repository at this point in the history
  • Loading branch information
nicho90 committed Jul 1, 2018
1 parent 820a03c commit 4cc800b
Show file tree
Hide file tree
Showing 37 changed files with 3,165 additions and 2,631 deletions.
10 changes: 9 additions & 1 deletion controllers/documents/change_status.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ exports.request = function(req, res) {
} else {
if(decoded.member || req.body.status == 1){
callback(null, client, done);
} else {
} else {
callback(new Error("Authorization failed"), 401);
}
}
Expand Down Expand Up @@ -340,6 +340,14 @@ exports.request = function(req, res) {
var status_description_2 = "";

switch (updated_document.status) {
case 1: {
icon = "fa-pencil-square-o";
status_description_1 = "You reverted your document and can now modify it. Please note that a reverted document has to be submitted and approved again.";
status_description_2 = "If you have problems with your document, please get in touch with a committee member of your institute.";
updated_document._status_label = "badge-info";
updated_document._status_description = "unsubmitted";
break;
}
case 4: {
icon = "fa-eye";
status_description_1 = "Your document is under review now. You will get another email as soon as the Ethics-committee has reviewed it completely.";
Expand Down
416 changes: 416 additions & 0 deletions controllers/documents/get_v2.js

Large diffs are not rendered by default.

70 changes: 36 additions & 34 deletions controllers/documents/submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ exports.request = function(req, res) {
} else if(concern.q14_value){
callback(null, client, done, document, course, revision, description, concern, 3);
} else {
// Check if document has been already in review
// Check if document has already been in review
if(document.status === 5){
callback(null, client, done, document, course, revision, description, concern, 3);
} else {
Expand Down Expand Up @@ -258,129 +258,130 @@ exports.request = function(req, res) {
}
},
function(client, done, document, course, revision, description, concern, author, members, callback){

// Check status to notify members, in case of a review
if(document.status === 2){
callback(null, 204, null);
} else {

// Formatting
if(concern.q01_value){
concern.q01_label = "badge-danger";
concern.q01_label = "badge-warning";
concern.q01_sign = "yes";
} else {
concern.q01_label = "badge-success";
concern.q01_label = "badge-default";
concern.q01_sign = "no";
}

if(concern.q02_value){
concern.q02_label = "badge-danger";
concern.q02_label = "badge-warning";
concern.q02_sign = "yes";
} else {
concern.q02_label = "badge-success";
concern.q02_label = "badge-default";
concern.q02_sign = "no";
}

if(concern.q03_value){
concern.q03_label = "badge-danger";
concern.q03_label = "badge-warning";
concern.q03_sign = "yes";
} else {
concern.q03_label = "badge-success";
concern.q03_label = "badge-default";
concern.q03_sign = "no";
}

if(concern.q04_value){
concern.q04_label = "badge-danger";
concern.q04_label = "badge-warning";
concern.q04_sign = "yes";
} else {
concern.q04_label = "badge-success";
concern.q04_label = "badge-default";
concern.q04_sign = "no";
}

if(concern.q05_value){
concern.q05_label = "badge-danger";
concern.q05_label = "badge-warning";
concern.q05_sign = "yes";
} else {
concern.q05_label = "badge-success";
concern.q05_label = "badge-default";
concern.q05_sign = "no";
}

if(concern.q06_value){
concern.q06_label = "badge-danger";
concern.q06_label = "badge-warning";
concern.q06_sign = "yes";
} else {
concern.q06_label = "badge-success";
concern.q06_label = "badge-default";
concern.q06_sign = "no";
}

if(concern.q07_value){
concern.q07_label = "badge-danger";
concern.q07_label = "badge-warning";
concern.q07_sign = "yes";
} else {
concern.q07_label = "badge-success";
concern.q07_label = "badge-default";
concern.q07_sign = "no";
}

if(concern.q08_value){
concern.q08_label = "badge-danger";
concern.q08_label = "badge-warning";
concern.q08_sign = "yes";
} else {
concern.q08_label = "badge-success";
concern.q08_label = "badge-default";
concern.q08_sign = "no";
}

if(concern.q09_value){
concern.q09_label = "badge-danger";
concern.q09_label = "badge-warning";
concern.q09_sign = "yes";
} else {
concern.q09_label = "badge-success";
concern.q09_label = "badge-default";
concern.q09_sign = "no";
}

if(concern.q10_value){
concern.q10_label = "badge-danger";
concern.q10_label = "badge-warning";
concern.q10_sign = "yes";
} else {
concern.q10_label = "badge-success";
concern.q10_label = "badge-default";
concern.q10_sign = "no";
}

if(concern.q11_1_value){
concern.q11_1_label = "badge-danger";
concern.q11_1_label = "badge-warning";
concern.q11_1_sign = "yes";
} else {
concern.q11_1_label = "badge-success";
concern.q11_1_label = "badge-default";
concern.q11_1_sign = "no";
}

if(concern.q11_2_value){
concern.q11_2_label = "badge-danger";
concern.q11_2_label = "badge-warning";
concern.q11_2_sign = "yes";
} else {
concern.q11_2_label = "badge-success";
concern.q11_2_label = "badge-default";
concern.q11_2_sign = "no";
}

if(concern.q12_value){
concern.q12_label = "badge-danger";
concern.q12_label = "badge-warning";
concern.q12_sign = "yes";
} else {
concern.q12_label = "badge-success";
concern.q12_label = "badge-default";
concern.q12_sign = "no";
}

if(concern.q13_value){
concern.q13_label = "badge-danger";
concern.q13_label = "badge-warning";
concern.q13_sign = "yes";
} else {
concern.q13_label = "badge-success";
concern.q13_label = "badge-default";
concern.q13_sign = "no";
}

if(concern.q14_value){
concern.q14_label = "badge-danger";
concern.q14_label = "badge-warning";
concern.q14_sign = "yes";
} else {
concern.q14_label = "badge-success";
concern.q14_label = "badge-default";
concern.q14_sign = "no";
}

Expand Down Expand Up @@ -411,17 +412,18 @@ exports.request = function(req, res) {
address: process.env.SENDER_EMAIL_ADDRESS
},
to: member.email_address,
subject: "[Ethics-App] A Study needs your review - Study Title: " + description.en_title,
subject: "[Ethics-App] A document needs your review - Study title: " + description.en_title,
text: text,
html: output,
messageId: document.document_id + "[email protected]"
}, function(err, info) {
if (err) {
callback(err);
} else {
callback();
callback(null);
}
});
callback(null);

}, function(err){
callback(null, 204, null);
Expand Down
33 changes: 31 additions & 2 deletions controllers/recovery/find_user_by_email.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ var fs = require("fs");
var dir_1 = "/../../templates/emails/";
var dir_2 = "/../../sql/queries/users/";
var dir_3 = "/../../sql/queries/documents/";
var dir_4 = "/../../sql/queries/revisions/";
var template_document_recovery = fs.readFileSync(__dirname + dir_1 + 'document_recovery.html', 'utf8').toString();
var query_get_user_by_email = fs.readFileSync(__dirname + dir_2 + 'get_by_email.sql', 'utf8').toString();
var query_list_documents_by_user = fs.readFileSync(__dirname + dir_3 + 'list_by_user.sql', 'utf8').toString();
var query_get_latest_revision_by_document = fs.readFileSync(__dirname + dir_4 + 'get_latest_by_document.sql', 'utf8').toString();


// FIND BY EMAIL
Expand Down Expand Up @@ -79,6 +81,33 @@ exports.request = function(req, res) {
}
});
},
function(client, done, user, documents, callback) {
async.eachOfSeries(documents, function (document, key, callback) {
// Database query
client.query(query_get_latest_revision_by_document, [
document.document_id
], function(err, result) {
done();
if (err) {
callback(err, 500);
} else {
// Check if Revision exists
if (result.rows.length === 0) {
callback(new Error("Revision not found"), 404);
} else {
document.latest_revision = result.rows[0];
callback(null);
}
}
});
}, function(err){
if (err) {
callback(err, 500);
} else {
callback(null, client, done, user, documents);
}
});
},
function(client, done, user, documents, callback) {

// Formatting
Expand Down Expand Up @@ -148,7 +177,7 @@ exports.request = function(req, res) {
});

// Render text for emails without HTML support
var text = "You asked for your Document-IDs";
var text = "You asked for your document-IDs";

// Send email
transporter.sendMail({
Expand All @@ -157,7 +186,7 @@ exports.request = function(req, res) {
address: process.env.SENDER_EMAIL_ADDRESS
},
to: user.email_address,
subject: "[Ethics-App] You asked for your Document-IDs",
subject: "[Ethics-App] You asked for your document-IDs",
text: text,
html: output
}, function(err, info) {
Expand Down
Loading

0 comments on commit 4cc800b

Please sign in to comment.