-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from lennygir/fix/203-improve-fix-tests
fix/203-improve-fix-tests
- Loading branch information
Showing
17 changed files
with
1,254 additions
and
1,027 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
const { CronJob } = require('cron'); | ||
const { getProposalsThatExpireInXDays, notifyProposalExpiration } = require('./theses-dao'); | ||
const { CronJob } = require("cron"); | ||
const { getProposalsThatExpireInXDays } = require("./dao/proposals"); | ||
const { notifyProposalExpiration } = require("./dao/misc"); | ||
|
||
const cronjobNames = { | ||
THESIS_EXPIRED: 'THESIS_EXPIRED' | ||
THESIS_EXPIRED: "THESIS_EXPIRED", | ||
}; | ||
|
||
const cronjobs = {}; | ||
|
||
const initCronjobs = () => { | ||
cronjobs[cronjobNames.THESIS_EXPIRED] = new CronJob("0 0 * * *" , () => { | ||
const proposals = getProposalsThatExpireInXDays(7); | ||
if(proposals) { | ||
proposals.forEach((proposal) => { | ||
notifyProposalExpiration(proposal); | ||
}); | ||
} | ||
}, undefined, true, "Europe/Rome", undefined, true); | ||
cronjobs[cronjobNames.THESIS_EXPIRED] = new CronJob( | ||
"0 0 * * *", | ||
() => { | ||
const proposals = getProposalsThatExpireInXDays(7); | ||
if (proposals) { | ||
proposals.forEach((proposal) => { | ||
notifyProposalExpiration(proposal); | ||
}); | ||
} | ||
}, | ||
undefined, | ||
true, | ||
"Europe/Rome", | ||
undefined, | ||
true, | ||
); | ||
}; | ||
|
||
const runCronjob = (cronjobName) => { | ||
console.log('[Cron] Running job ' + cronjobName); | ||
if(cronjobs[cronjobName]) { | ||
cronjobs[cronjobName].fireOnTick(); | ||
} | ||
console.log("[Cron] Running job " + cronjobName); | ||
if (cronjobs[cronjobName]) { | ||
cronjobs[cronjobName].fireOnTick(); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
cronjobNames, | ||
runCronjob, | ||
initCronjobs | ||
}; | ||
cronjobNames, | ||
runCronjob, | ||
initCronjobs, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
"use strict"; | ||
|
||
const { db } = require("../db"); | ||
|
||
exports.insertApplication = (proposal, student, state) => { | ||
const result = db | ||
.prepare( | ||
"insert into APPLICATIONS(proposal_id, student_id, state) values (?,?,?)", | ||
) | ||
.run(proposal, student, state); | ||
const applicationId = result.lastInsertRowid; | ||
return { | ||
application_id: applicationId, | ||
proposal_id: proposal, | ||
student_id: student, | ||
state: state, | ||
}; | ||
}; | ||
|
||
exports.insertPDFInApplication = (file, applicationId) => { | ||
return db | ||
.prepare( | ||
"update APPLICATIONS set attached_file = ? where main.APPLICATIONS.id = ?", | ||
) | ||
.run(file, applicationId); | ||
}; | ||
|
||
exports.getApplicationById = (id) => { | ||
return db.prepare("select * from APPLICATIONS where id = ?").get(id); | ||
}; | ||
|
||
exports.cancelPendingApplications = (of_proposal) => { | ||
db.prepare( | ||
"update APPLICATIONS set state = 'canceled' where proposal_id = ? AND state = 'pending'", | ||
).run(of_proposal); | ||
}; | ||
|
||
exports.cancelPendingApplicationsOfStudent = (student_id) => { | ||
db.prepare( | ||
"update APPLICATIONS set state = 'canceled' where main.APPLICATIONS.student_id = ? and state = 'pending'", | ||
).run(student_id); | ||
}; | ||
|
||
exports.updateApplication = (id, state) => { | ||
db.prepare("update APPLICATIONS set state = ? where id = ?").run(state, id); | ||
}; | ||
|
||
exports.getAcceptedApplicationsOfStudent = (student_id) => { | ||
return db | ||
.prepare( | ||
`select * from APPLICATIONS where student_id = ? and state = 'accepted'`, | ||
) | ||
.all(student_id); | ||
}; | ||
|
||
exports.getPendingApplicationsOfStudent = (student_id) => { | ||
return db | ||
.prepare( | ||
`select * from APPLICATIONS where student_id = ? and state = 'pending'`, | ||
) | ||
.all(student_id); | ||
}; | ||
|
||
exports.findRejectedApplication = (proposal_id, student_id) => { | ||
return db | ||
.prepare( | ||
`select * from APPLICATIONS where proposal_id = ? and student_id = ? and state = 'rejected'`, | ||
) | ||
.get(proposal_id, student_id); | ||
}; | ||
|
||
/** | ||
* @param teacher_id | ||
* @returns {[ | ||
* { | ||
* application_id, | ||
* proposal_id, | ||
* teacher_id, | ||
* state, | ||
* student_name, | ||
* student_surname, | ||
* teacher_name, | ||
* teacher_surname | ||
* title | ||
* } | ||
* ]} | ||
*/ | ||
exports.getApplicationsOfTeacher = (teacher_id) => { | ||
return db | ||
.prepare( | ||
`select APPLICATIONS.id, | ||
APPLICATIONS.proposal_id, | ||
APPLICATIONS.student_id, | ||
APPLICATIONS.state, | ||
APPLICATIONS.attached_file, | ||
STUDENT.name as student_name, | ||
STUDENT.surname as student_surname, | ||
TEACHER.name as teacher_name, | ||
TEACHER.surname as teacher_surname, | ||
PROPOSALS.title as title | ||
from APPLICATIONS, | ||
PROPOSALS, | ||
STUDENT, | ||
TEACHER | ||
where APPLICATIONS.proposal_id = PROPOSALS.id | ||
and PROPOSALS.supervisor = TEACHER.id | ||
and APPLICATIONS.student_id = STUDENT.id | ||
and PROPOSALS.supervisor = ?`, | ||
) | ||
.all(teacher_id); | ||
}; | ||
|
||
exports.getApplicationsOfStudent = (student_id) => { | ||
return db | ||
.prepare( | ||
`select APPLICATIONS.id, | ||
APPLICATIONS.proposal_id, | ||
APPLICATIONS.student_id, | ||
APPLICATIONS.state, | ||
APPLICATIONS.attached_file, | ||
STUDENT.name as student_name, | ||
STUDENT.surname as student_surname, | ||
TEACHER.name as teacher_name, | ||
TEACHER.surname as teacher_surname, | ||
PROPOSALS.title as title | ||
from APPLICATIONS, | ||
PROPOSALS, | ||
STUDENT, | ||
TEACHER | ||
where APPLICATIONS.proposal_id = PROPOSALS.id | ||
and PROPOSALS.supervisor = TEACHER.id | ||
and APPLICATIONS.student_id = STUDENT.id | ||
and APPLICATIONS.student_id = ?`, | ||
) | ||
.all(student_id); | ||
}; | ||
|
||
/** | ||
* Is the given application accepted? | ||
* @param proposal_id the proposal of the application | ||
* @param student_id the student who applied | ||
* @returns {boolean} accepted or not | ||
*/ | ||
exports.isAccepted = (proposal_id, student_id) => { | ||
const accepted_proposal = db | ||
.prepare( | ||
`select * from main.APPLICATIONS | ||
where APPLICATIONS.proposal_id = ? | ||
and APPLICATIONS.student_id = ? | ||
and APPLICATIONS.state = 'accepted'`, | ||
) | ||
.get(proposal_id, student_id); | ||
return accepted_proposal !== undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"use strict"; | ||
function getCosupervisorsFromProposal(proposal) { | ||
return proposal.co_supervisors ? proposal.co_supervisors.split(", ") : []; | ||
} | ||
|
||
function getArrayDifference(arrayIn, arrayNotIn) { | ||
return arrayIn.filter((el) => !arrayNotIn.includes(el)); | ||
} | ||
|
||
module.exports = { | ||
getCosupervisorsFromProposal, | ||
getArrayDifference, | ||
}; |
Oops, something went wrong.