Updating UserCircle points when completing a chore
This commit is contained in:
parent
13d6cfd7e7
commit
33801b5004
2 changed files with 17 additions and 7 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
config "donetick.com/core/config"
|
||||
chModel "donetick.com/core/internal/chore/model"
|
||||
cModel "donetick.com/core/internal/circle/model"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
|
@ -118,6 +119,12 @@ func (r *ChoreRepository) CompleteChore(c context.Context, chore *chModel.Chore,
|
|||
if err := tx.Model(&chModel.Chore{}).Where("id = ?", chore.ID).Updates(updates).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
// Update UserCirclee Points :
|
||||
if chore.Points != nil && *chore.Points > 0 {
|
||||
if err := tx.Debug().Model(&cModel.UserCircle{}).Where("user_id = ? AND circle_id = ?", userID, chore.CircleID).Update("points", gorm.Expr("points + ?", chore.Points)).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
@ -270,6 +277,7 @@ func (r *ChoreRepository) GetChoreDetailByID(c context.Context, choreID int, cir
|
|||
chores.assigned_to,
|
||||
chores.created_by,
|
||||
chores.priority,
|
||||
chores.completion_window,
|
||||
recent_history.last_completed_date,
|
||||
recent_history.notes,
|
||||
recent_history.last_assigned_to as last_completed_by,
|
||||
|
|
|
@ -29,6 +29,8 @@ type UserCircle struct {
|
|||
IsActive bool `json:"isActive" gorm:"column:is_active;default:false"`
|
||||
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"` // Created at
|
||||
UpdatedAt time.Time `json:"updatedAt" gorm:"column:updated_at"` // Updated at
|
||||
Points int `json:"points" gorm:"column:points;default:0;not null"` // Points
|
||||
PointsRedeemed int `json:"pointsRedeemed" gorm:"column:points_redeemed;default:0;not null"` // Points Redeemed
|
||||
}
|
||||
|
||||
type UserCircleDetail struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue