Skip to content

Commit

Permalink
fix: assorted hotfixes from demo review
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Dec 13, 2024
1 parent a1b6b5e commit 873dee0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/src/database/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (db *DB) GetStudentDashboardInfo(userID int, facilityID uint) (models.UserD
CASE
WHEN COUNT(o.type) > 0 THEN 100
WHEN COUNT(c.total_progress_milestones) = 0 THEN 0
ELSE COUNT(milestones.id) * 100.0 / c.total_progress_milestones
ELSE COUNT(milestones.id) * 100.0 / NULLIF(c.total_progress_milestones, 0)
END as course_progress`).
Joins("LEFT JOIN provider_platforms pp ON c.provider_platform_id = pp.id").
Joins("LEFT JOIN milestones ON milestones.course_id = c.id AND milestones.user_id = ?", userID).
Expand Down
17 changes: 8 additions & 9 deletions backend/src/database/seed_demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import (
func (db *DB) RunOrResetDemoSeed(facilityId uint) error {
// seeding data for demo will only seed user activity/milestones/open-content activity for existing users
activity := models.Activity{}
if err := db.Model(&models.Activity{}).Where("external_id = 'SEEDED_ACTIVITY'").First(&activity).Error; err != nil {
if err := db.Model(&models.Activity{}).Where("external_id = 'SEEDED_ACTIVITY'").Order("created_at DESC").First(&activity).Error; err != nil {
return db.RunDemoSeed(facilityId)
}
if err := db.Raw("DELETE from activities where created_at > ?", activity.CreatedAt).Error; err != nil {
if err := db.Raw("DELETE from activities WHERE created_at > ?", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "activities")
}
if err := db.Raw("DELETE from open_content_activities where request_ts > ?", activity.CreatedAt).Error; err != nil {
if err := db.Raw("DELETE from open_content_activities WHERE request_ts > ?", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "open_content_activities")
}
if err := db.Raw("DELETE from milestones where created_at > ?", activity.CreatedAt).Error; err != nil {
if err := db.Raw("DELETE from milestones WHERE created_at > ?", activity.CreatedAt).Error; err != nil {
return newDeleteDBError(err, "milestones")
}
return db.RunDemoSeed(facilityId)
Expand Down Expand Up @@ -51,7 +51,7 @@ func (db *DB) RunDemoSeed(facilityId uint) error {
}
sixMonthsAgo := time.Now().AddDate(0, 0, -180)
for _, user := range users {
// seed user activity for two weeks for each user
// seed user activity for six months for each user
for _, course := range courses {
courseTotalTime := int64(0)
for i := 0; i < 180; i++ {
Expand All @@ -62,12 +62,11 @@ func (db *DB) RunDemoSeed(facilityId uint) error {
} else {
externalID = uuid.NewString()
}
activity := models.Activity{CreatedAt: sixMonthsAgo.AddDate(0, 0, i).Add(time.Duration(i) * time.Minute), UserID: user.ID, CourseID: course.ID, ExternalID: externalID, Type: models.ContentInteraction, TotalTime: courseTotalTime, TimeDelta: randTime}
courseTotalTime += randTime
if err := db.Create(&activity).Error; err != nil {
if err := db.Exec("SELECT insert_daily_activity(?, ?, ?, ?, ?)", user.ID, course.ID, models.ContentInteraction, courseTotalTime, externalID).Error; err != nil {
continue
}
if i%5 == 0 {
courseTotalTime += randTime
if i%rand.Intn(30)+1 == 0 {
milestone := models.Milestone{UserID: user.ID, CourseID: course.ID, ExternalID: uuid.NewString(), Type: models.AssignmentSubmission, IsCompleted: false}
if err := db.Create(&milestone).Error; err != nil {
continue
Expand Down
4 changes: 2 additions & 2 deletions backend/src/handlers/provider_platform_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func (srv *Server) handleCreateProvider(w http.ResponseWriter, r *http.Request,
// in the redirect url, therefore this method will only return nil as its error
func (srv *Server) handleOAuthProviderCallback(w http.ResponseWriter, r *http.Request, log sLog) error {
const (
successRedirectUrl = "/provider-platform-management?status=success&message=Provider platform %s successfully"
errorRedirectUrl = "/provider-platform-management?status=error&message=Failed to configure provider platform"
successRedirectUrl = "/learning-platforms?status=success&message=Provider platform %s successfully"
errorRedirectUrl = "/learning-platforms?status=error&message=Failed to configure provider platform"
)
stateFromClient := r.FormValue("state")
if stateFromClient == "" { //state is an opaque value used by the client to maintain state between the request and callback
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Pages/OpenContentLevelDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function StudentLayer1() {
})}
</div>
</div>
<h2>Resources</h2>
<h2>Helpful Links</h2>
<div className="card card-row-padding grid grid-cols-5 gap-3">
{helpfulLinks.map((link: HelpfulLink) => (
<div
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,10 @@ export interface ProgramTag {
}

export enum FilterLibraries {
'All Libraries' = 'all'
'All Libraries' = 'all',
'Newest' = 'created_at DESC',
'Oldest' = 'created_at ASC',
'Favorited' = 'most_favorited'
}
export enum LibraryAdminVisibility {
'All Libraries' = 'all',
Expand Down

0 comments on commit 873dee0

Please sign in to comment.