Skip to content

Commit

Permalink
feat: notify cosupervisors on decision (#102)
Browse files Browse the repository at this point in the history
* feat: notify cosupervisors on decision

* fix: show the application status

* fix: tests
  • Loading branch information
lennygir authored Jan 14, 2024
1 parent bf8a74c commit 893a010
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
21 changes: 21 additions & 0 deletions server/src/mail/cosupervisor-application-decision.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const cosupervisorApplicationDecisionHtmlTemplate = (variables) => {
return `
<html>
<body>
<p>Dear ${variables.name},</p>
<p>An application has been ${variables.decision} for the thesis proposal "${variables.thesis}" for which you are co-supervisor.</p>
<p>Best regards,</p>
<p>the Thesis Managment system</p>
</body>
</html>
`;
};

const cosupervisorApplicationDecisionTextTemplate = (variables) => {
return `Dear ${variables.name},\nAn application has been ${variables.decision} for the thesis proposal "${variables.thesis}" for which you are co-supervisor.\nBest regards,\nthe Thesis Managment system`;
};

exports.cosupervisorApplicationDecisionTemplate = (variables) => ({
html: cosupervisorApplicationDecisionHtmlTemplate(variables),
text: cosupervisorApplicationDecisionTextTemplate(variables)
});
55 changes: 43 additions & 12 deletions server/src/theses-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const { db } = require("./db");
const { nodemailer } = require("./smtp");
const { applicationDecisionTemplate } = require("./mail/application-decision");
const { newApplicationTemplate } = require("./mail/new-application");
const {
supervisorStartRequestTemplate,
} = require("./mail/supervisor-start-request");
const { supervisorStartRequestTemplate } = require("./mail/supervisor-start-request");
const { cosupervisorApplicationDecisionTemplate } = require("./mail/cosupervisor-application-decision");

exports.insertApplication = (proposal, student, state) => {
const result = db
Expand Down Expand Up @@ -268,17 +267,20 @@ exports.findRejectedApplication = (proposal_id, student_id) => {
};

exports.notifyApplicationDecision = async (applicationId, decision) => {
// Send email to a student
// Retrieve the data
const applicationJoined = db
.prepare(
`SELECT S.id, P.title, S.email, S.surname, S.name
FROM APPLICATIONS A
JOIN PROPOSALS P ON P.id = A.proposal_id
JOIN STUDENT S ON S.id = A.student_id
WHERE A.id = ?`,
"SELECT S.id, P.title, P.co_supervisors, S.email, S.surname, S.name \
FROM APPLICATIONS A \
JOIN PROPOSALS P ON P.id = A.proposal_id \
JOIN STUDENT S ON S.id = A.student_id \
WHERE A.id = ?",
)
.get(applicationId);
const mailBody = applicationDecisionTemplate({
let mailBody;
// Notify the student
// -- Email
mailBody = applicationDecisionTemplate({
name: applicationJoined.surname + " " + applicationJoined.name,
thesis: applicationJoined.title,
decision: decision,
Expand All @@ -293,15 +295,44 @@ exports.notifyApplicationDecision = async (applicationId, decision) => {
} catch (e) {
console.log("[mail service]", e);
}

// Save email in DB
// -- Website notification
db.prepare(
"INSERT INTO NOTIFICATIONS(student_id, object, content) VALUES(?,?,?)",
).run(
applicationJoined.id,
"New decision on your thesis application",
mailBody.text,
);
// Notify the co-supervisors
if(applicationJoined.co_supervisors) {
for(const cosupervisor of applicationJoined.co_supervisors.split(', ')) {
const fullCosupervisor = this.getTeacherByEmail(cosupervisor);
// -- Email
mailBody = cosupervisorApplicationDecisionTemplate({
name: fullCosupervisor.surname + " " + fullCosupervisor.name,
thesis: applicationJoined.title,
decision: decision,
});
try {
await nodemailer.sendMail({
to: cosupervisor,
subject: "New decision for a thesis you co-supervise",
text: mailBody.text,
html: mailBody.html,
});
} catch (e) {
console.log("[mail service]", e);
}
// -- Website notification
db.prepare(
"INSERT INTO NOTIFICATIONS(teacher_id, object, content) VALUES(?,?,?)",
).run(
fullCosupervisor.id,
"New decision for a thesis you co-supervise",
mailBody.text,
);
}
}
};

exports.notifyNewStartRequest = async (requestId) => {
Expand Down
2 changes: 1 addition & 1 deletion server/tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let proposal, start_request;
beforeEach(() => {
proposal = {
title: "Test title",
co_supervisors: ["[email protected]", "[email protected]"],
co_supervisors: ["[email protected]", "[email protected]"],
groups: ["SOFTENG"],
keywords: ["SOFTWARE ENGINEERING", "SOFTWARE DEVELOPMENT"],
types: ["EXPERIMENTAL", "RESEARCH"],
Expand Down

0 comments on commit 893a010

Please sign in to comment.