Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/services/ResourceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ async function createResource (currentUser, resource) {
console.log('config template id', config.get('TOPCROWD_CHALLENGE_TEMPLATE_ID'))
if (config.get('TOPCROWD_CHALLENGE_TEMPLATE_ID') !== timelineTemplateId) {
console.log('sending email')
const submissionPhase = _.find(challenge.phases, phase => ['Submission', 'Topgear Submission'].includes(phase.name))
const submissionEndTime = submissionPhase && submissionPhase.scheduledEndDate
? new Date(submissionPhase.scheduledEndDate).toUTCString()
: null

await helper.postEvent(config.EMAIL_NOTIFICATIN_TOPIC, {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The variable submissionEndTime is derived from submissionPhase.scheduledEndDate without validation of the date format. Consider adding a check to ensure scheduledEndDate is a valid date before converting it to a UTC string to prevent potential runtime errors.

from: config.REGISTRATION_EMAIL.EMAIL_FROM,
replyTo: config.REGISTRATION_EMAIL.EMAIL_FROM,
Expand All @@ -543,7 +548,7 @@ async function createResource (currentUser, resource) {
handle,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The submissionEndTime variable is used directly in the email data payload. Ensure that submissionEndTime is not null before sending the email, or handle the null case appropriately to avoid sending incomplete data.

challengeName: challenge.name,
forum: forumUrl,
submissionEndTime: new Date(_.get(_.find(challenge.phases, phase => phase.name === 'Submission'), 'scheduledEndDate')).toUTCString(),
submissionEndTime,
submitUrl: _.replace(config.REGISTRATION_EMAIL.SUBMIT_URL, ':id', challengeId),
reviewAppUrl: config.REGISTRATION_EMAIL.REVIEW_APP_URL + challenge.id + '/challenge-details',
helpUrl: config.REGISTRATION_EMAIL.HELP_URL,
Expand Down