Skip to content

Commit

Permalink
added teacher emails to admin view also
Browse files Browse the repository at this point in the history
  • Loading branch information
ollikehy committed Sep 14, 2021
1 parent 91c19cd commit 357a31e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

dockerhub-release:
runs-on: ubuntu-latest
#needs: [cypress, eslint]
needs: [cypress, eslint]
steps:
- uses: actions/checkout@v2

Expand Down
3 changes: 2 additions & 1 deletion src/server/controllers/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ const resetTestCourse = async (_, res) => {
}

const findEmailsForToday = async (_, res) => {
const emails = await returnEmailsToBeSentToday()
const { students, teachers } = await returnEmailsToBeSentToday()
const emails = students.concat(teachers)
res.send(emails)
}

Expand Down
72 changes: 52 additions & 20 deletions src/server/util/emailSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getOpenFeedbackTargetsForStudents = async () => {
model: CourseUnit,
as: 'courseUnit',
required: true,
attributes: ['courseCode'],
attributes: ['courseCode', 'name'],
include: [
{
model: Organisation,
Expand Down Expand Up @@ -102,7 +102,7 @@ const getFeedbackTargetsAboutToOpenForTeachers = async () => {
model: CourseUnit,
as: 'courseUnit',
required: true,
attributes: ['courseCode'],
attributes: ['courseCode', 'name'],
include: [
{
model: Organisation,
Expand Down Expand Up @@ -188,20 +188,20 @@ const sendEmailAboutSurveyOpeningToStudents = async () => {
)
const ids = feedbackTargets.map((target) => target.id)

// FeedbackTarget.update(
// {
// feedbackOpenNotificationEmailSent: true,
// },
// {
// where: {
// id: {
// [Op.in]: ids,
// },
// },
// },
// )
//
// sendEmail(emailsToBeSent)
FeedbackTarget.update(
{
feedbackOpenNotificationEmailSent: true,
},
{
where: {
id: {
[Op.in]: ids,
},
},
},
)

sendEmail(emailsToBeSent)

return emailsToBeSent
}
Expand All @@ -221,25 +221,57 @@ const sendEmailReminderAboutSurveyOpeningToTeachers = async () => {
),
)

const ids = feedbackTargets.map((target) => target.id)

FeedbackTarget.update(
{
feedbackOpeningReminderEmailSent: true,
},
{
where: {
id: {
[Op.in]: ids,
},
},
},
)

sendEmail(emailsToBeSent)

return emailsToBeSent
/* eslint-enable */
}

const returnEmailsToBeSentToday = async () => {
const feedbackTargets = await getFeedbackTargetsForSpecialCase()
const studentFeedbackTargets = await getOpenFeedbackTargetsForStudents()
const teacherFeedbackTargets =
await getFeedbackTargetsAboutToOpenForTeachers()

const studentsWithFeedbackTargets = await aggregateFeedbackTargets(
feedbackTargets,
studentFeedbackTargets,
)

const emailsToBeSent = Object.keys(studentsWithFeedbackTargets).map(
const teachersWithFeedbackTargets = await aggregateFeedbackTargets(
teacherFeedbackTargets,
)

const studentEmailsToBeSent = Object.keys(studentsWithFeedbackTargets).map(
(student) =>
notificationAboutSurveyOpeningToStudents(
student,
studentsWithFeedbackTargets[student],
),
)

return emailsToBeSent
const teacherEmailsToBeSent = Object.keys(teachersWithFeedbackTargets).map(
(teacher) =>
emailReminderAboutSurveyOpeningToTeachers(
teacher,
teachersWithFeedbackTargets[teacher],
),
)

return { students: studentEmailsToBeSent, teachers: teacherEmailsToBeSent }
}

module.exports = {
Expand Down

0 comments on commit 357a31e

Please sign in to comment.