Skip to content

Commit

Permalink
feat(my-teaching-v2): show ended courserealisations on active tab if …
Browse files Browse the repository at this point in the history
…there are any ongoing feedbacks
  • Loading branch information
HRemonen committed Mar 4, 2024
1 parent a7c1b34 commit 12440b6
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/server/routes/myTeaching/myTeachingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const getCourseUnitsForTeacher = async (req, res) => {
as: 'courseRealisation',
required: true,
attributes: ['id', 'name', 'startDate', 'endDate', 'userCreated'],
where: {
/* where: {
[Op.or]: [
query.status === 'active' && {
startDate: { [Op.lte]: new Date() },
Expand All @@ -81,7 +81,7 @@ const getCourseUnitsForTeacher = async (req, res) => {
endDate: { [Op.lt]: new Date() },
},
],
},
}, */
},
],
},
Expand Down Expand Up @@ -134,13 +134,39 @@ const getCourseUnitsForTeacher = async (req, res) => {
return acualCUR
})

const groupedCourseRealisations = courseRealisations.filter(courseRealisation => {
const now = new Date()

if (query.status === 'active') {
const activeCourseRealisation = courseRealisation.startDate <= now && courseRealisation.endDate >= now
const activeFeedbackTargets = courseRealisation.feedbackTargets.some(
fbt => fbt.opensAt <= now && fbt.closesAt >= now
)

return activeCourseRealisation || activeFeedbackTargets
}
if (query.status === 'upcoming') {
return courseRealisation.startDate > now
}
if (query.status === 'ended') {
const endedCourseRealisation = courseRealisation.endDate < now
const activeFeedbackTargets = courseRealisation.feedbackTargets.some(
fbt => fbt.opensAt <= now && fbt.closesAt >= now
)

return endedCourseRealisation && !activeFeedbackTargets
}

return null
})

return {
id: courseUnit.dataValues.id,
name: courseUnit.dataValues.name,
courseCode: courseUnit.dataValues.courseCode,
userCreated: courseUnit.dataValues.userCreated,
disabledCourse,
courseRealisations,
courseRealisations: groupedCourseRealisations,
}
})

Expand Down

0 comments on commit 12440b6

Please sign in to comment.