diff --git a/src/client/pages/FeedbackTarget/tabs/Share/ReminderEmailModal.js b/src/client/pages/FeedbackTarget/tabs/Share/ReminderEmailModal.js index 7b9e02a89..69683ef0d 100644 --- a/src/client/pages/FeedbackTarget/tabs/Share/ReminderEmailModal.js +++ b/src/client/pages/FeedbackTarget/tabs/Share/ReminderEmailModal.js @@ -53,7 +53,7 @@ const ReminderEmailModal = ({ open, onClose, feedbackTarget }) => { const disabled = differenceInHours(Date.now(), lastSentAt) < FEEDBACK_REMINDER_COOLDOWN const sendEmailReminder = useInteractiveMutation(() => - sendReminderEmail.mutateAsync({ id, courseName, data: reminder }) + sendReminderEmail.mutateAsync({ id, data: { reminder, courseName } }) ) const onEmailSend = () => { diff --git a/src/client/pages/FeedbackTarget/tabs/Share/api.js b/src/client/pages/FeedbackTarget/tabs/Share/api.js index bc77f5068..58e3b1439 100644 --- a/src/client/pages/FeedbackTarget/tabs/Share/api.js +++ b/src/client/pages/FeedbackTarget/tabs/Share/api.js @@ -5,7 +5,7 @@ import { updateCache } from '../../../../util/reactQuery' export const useSendReminderEmail = () => { const mutationFn = async ({ id, data }) => apiClient.put(`/feedback-targets/${id}/remind-students`, { - data: { data }, + data, }) const mutation = useMutation(mutationFn, { diff --git a/src/server/mailer/mails/sendFeedbackReminderToStudents.js b/src/server/mailer/mails/sendFeedbackReminderToStudents.js index 17777b525..8a9ed2ad4 100644 --- a/src/server/mailer/mails/sendFeedbackReminderToStudents.js +++ b/src/server/mailer/mails/sendFeedbackReminderToStudents.js @@ -1,5 +1,4 @@ const { differenceInHours, format } = require('date-fns') -const { CourseUnit } = require('../../models') const { FEEDBACK_REMINDER_COOLDOWN, PUBLIC_URL } = require('../../util/config') const { ApplicationError } = require('../../util/customErrors') const { pate } = require('../pateClient') @@ -37,12 +36,11 @@ const sendReminderToGiveFeedbackToStudents = async ( return emails } -const sendFeedbackReminderToStudents = async (feedbackTarget, reminder) => { +const sendFeedbackReminderToStudents = async (feedbackTarget, reminder, courseName) => { if (differenceInHours(new Date(), feedbackTarget.feedbackReminderLastSentAt) < FEEDBACK_REMINDER_COOLDOWN) { throw new ApplicationError(`Can send only 1 feedback reminder every ${FEEDBACK_REMINDER_COOLDOWN} hours`, 403) } - const courseUnit = await CourseUnit.findByPk(feedbackTarget.courseUnitId) const students = await feedbackTarget.getStudentsWhoHaveNotGivenFeedback() const url = `${PUBLIC_URL}/targets/${feedbackTarget.id}/feedback` const formattedStudents = students @@ -58,7 +56,7 @@ const sendFeedbackReminderToStudents = async (feedbackTarget, reminder) => { const emails = await sendReminderToGiveFeedbackToStudents( url, formattedStudents, - feedbackTarget.userCreated ? feedbackTarget.name : courseUnit.name, + courseName, reminder, formattedClosesAt, feedbackTarget.userCreated diff --git a/src/server/routes/feedbackTargets/feedbackTargetController.js b/src/server/routes/feedbackTargets/feedbackTargetController.js index f36593473..a74f0abb2 100644 --- a/src/server/routes/feedbackTargets/feedbackTargetController.js +++ b/src/server/routes/feedbackTargets/feedbackTargetController.js @@ -151,11 +151,12 @@ adRouter.put('/:id/response', async (req, res) => { adRouter.put('/:id/remind-students', async (req, res) => { const { user } = req const feedbackTargetId = Number(req.params.id) - const { data: reminderText } = req.body.data + const { reminder: reminderText, courseName } = req.body.data const feedbackTarget = await remindStudentsOnFeedback({ feedbackTargetId, reminderText, + courseName, user, }) diff --git a/src/server/services/feedbackTargets/remindStudentsOnFeedback.js b/src/server/services/feedbackTargets/remindStudentsOnFeedback.js index 4efb4f058..e402d21e5 100644 --- a/src/server/services/feedbackTargets/remindStudentsOnFeedback.js +++ b/src/server/services/feedbackTargets/remindStudentsOnFeedback.js @@ -2,7 +2,7 @@ const { mailer } = require('../../mailer') const { ApplicationError } = require('../../util/customErrors') const { getFeedbackTargetContext } = require('./getFeedbackTargetContext') -const remindStudentsOnFeedback = async ({ feedbackTargetId, reminderText, user }) => { +const remindStudentsOnFeedback = async ({ feedbackTargetId, reminderText, courseName, user }) => { const { feedbackTarget, access } = await getFeedbackTargetContext({ feedbackTargetId, user, @@ -10,7 +10,7 @@ const remindStudentsOnFeedback = async ({ feedbackTargetId, reminderText, user } if (!access?.canSendReminderEmail()) ApplicationError.Forbidden('Not allowed to send reminder') - await mailer.sendFeedbackReminderToStudents(feedbackTarget, reminderText) + await mailer.sendFeedbackReminderToStudents(feedbackTarget, reminderText, courseName) return feedbackTarget }