Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: courses completion for teacher statistics #258

Merged

Conversation

wielopolski
Copy link
Collaborator

Jira issue(s)

417

Overview

This PR adds courses completion to teacher statistics endpoint.

@wielopolski wielopolski added the review me 👀 PR is ready to be reviewed label Nov 28, 2024
@wielopolski wielopolski self-assigned this Nov 28, 2024
@wielopolski wielopolski marked this pull request as ready for review November 28, 2024 04:01
Comment on lines +149 to +158
async getTotalCoursesCompletion(userId: string) {
return await this.db
.select({
totalCoursesCompletion: sql<number>`sum(courseStatisticsPerTeacherMaterialized.completedStudentCount)`,
totalCourses: sql<number>`sum(courseStatisticsPerTeacherMaterialized.studentCount)`,
})
.from(courseStatisticsPerTeacherMaterialized)
.where(eq(courseStatisticsPerTeacherMaterialized.teacherId, userId));
}

Copy link
Member

Choose a reason for hiding this comment

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

suggestion: How about using Drizzle's built-in .sum() method instead of raw SQL for better type safety and readability?

Suggested change
async getTotalCoursesCompletion(userId: string) {
return await this.db
.select({
totalCoursesCompletion: sql<number>`sum(courseStatisticsPerTeacherMaterialized.completedStudentCount)`,
totalCourses: sql<number>`sum(courseStatisticsPerTeacherMaterialized.studentCount)`,
})
.from(courseStatisticsPerTeacherMaterialized)
.where(eq(courseStatisticsPerTeacherMaterialized.teacherId, userId));
}
async getTotalCoursesCompletion(userId: string) {
return await this.db
.select({
totalCoursesCompletion: courseStatisticsPerTeacherMaterialized.completedStudentCount.sum(),
totalCourses: courseStatisticsPerTeacherMaterialized.studentCount.sum(),
})
.from(courseStatisticsPerTeacherMaterialized)
.where(eq(courseStatisticsPerTeacherMaterialized.teacherId, userId));
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not Rails to use .sum() at the end of an expression and get the finished result.
Drizzle is as hollow as Swiss cheese, and below I've included its “better type safety”:
image

@piotr-pajak piotr-pajak added new feedback 🎈 New feedback for PR requested and removed review me 👀 PR is ready to be reviewed labels Nov 28, 2024
@wielopolski wielopolski force-pushed the mw_feat_417_course_completion_for_teacher_statistics branch from 59f821e to 034fe84 Compare November 28, 2024 13:49
@wielopolski wielopolski added merge me 💚 PR is ready to be merged and removed new feedback 🎈 New feedback for PR requested labels Nov 28, 2024
@wielopolski wielopolski merged commit 9595276 into main Nov 28, 2024
6 checks passed
@wielopolski wielopolski deleted the mw_feat_417_course_completion_for_teacher_statistics branch November 28, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me 💚 PR is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants