Skip to content

Commit

Permalink
fix: modify query to allow resident to favorite featured libraries an…
Browse files Browse the repository at this point in the history
…d modified libaries query to display featured libraries to other admins at the same facility
  • Loading branch information
carddev81 committed Jan 7, 2025
1 parent 79523f9 commit c8e435a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions backend/src/database/videos.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ func (db *DB) FavoriteOpenContent(contentID int, ocpID uint, userID uint, facili
UserID: userID,
FacilityID: facilityID,
}
//use Unscoped method to ignore soft deletions
//added user id to query below to isolate favorite by user when facility id is passed in
tx := db.Where("content_id = ? AND open_content_provider_id = ?", contentID, ocpID)
if facilityID != nil {
tx = tx.Where("facility_id = ?", facilityID)
} else {
tx = tx.Where("user_id = ?", userID)
}
if tx.First(&models.OpenContentFavorite{}).RowsAffected > 0 {
delTx := db.Where("content_id = ? AND user_id = ? AND open_content_provider_id = ?", contentID, userID, ocpID)
delTx := db.Where("content_id = ? AND open_content_provider_id = ?", contentID, ocpID)
if facilityID != nil {
delTx = delTx.Where("facility_id = ?", facilityID)
} else {
delTx = delTx.Where("user_id = ?", userID)
}
if err := delTx.Delete(&fav).Error; err != nil {
return false, newDeleteDBError(err, "video_favorites")
return false, newDeleteDBError(err, "open_content_favorites")
}
return false, nil
} else {
Expand Down

0 comments on commit c8e435a

Please sign in to comment.