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"
|
config "donetick.com/core/config"
|
||||||
chModel "donetick.com/core/internal/chore/model"
|
chModel "donetick.com/core/internal/chore/model"
|
||||||
|
cModel "donetick.com/core/internal/circle/model"
|
||||||
"gorm.io/gorm"
|
"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 {
|
if err := tx.Model(&chModel.Chore{}).Where("id = ?", chore.ID).Updates(updates).Error; err != nil {
|
||||||
return err
|
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
|
return nil
|
||||||
})
|
})
|
||||||
|
@ -270,6 +277,7 @@ func (r *ChoreRepository) GetChoreDetailByID(c context.Context, choreID int, cir
|
||||||
chores.assigned_to,
|
chores.assigned_to,
|
||||||
chores.created_by,
|
chores.created_by,
|
||||||
chores.priority,
|
chores.priority,
|
||||||
|
chores.completion_window,
|
||||||
recent_history.last_completed_date,
|
recent_history.last_completed_date,
|
||||||
recent_history.notes,
|
recent_history.notes,
|
||||||
recent_history.last_assigned_to as last_completed_by,
|
recent_history.last_assigned_to as last_completed_by,
|
||||||
|
|
|
@ -22,13 +22,15 @@ type CircleDetail struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserCircle struct {
|
type UserCircle struct {
|
||||||
ID int `json:"id" gorm:"primary_key"` // Unique identifier
|
ID int `json:"id" gorm:"primary_key"` // Unique identifier
|
||||||
UserID int `json:"userId" gorm:"column:user_id"` // User ID
|
UserID int `json:"userId" gorm:"column:user_id"` // User ID
|
||||||
CircleID int `json:"circleId" gorm:"column:circle_id"` // Circle ID
|
CircleID int `json:"circleId" gorm:"column:circle_id"` // Circle ID
|
||||||
Role string `json:"role" gorm:"column:role"` // Role
|
Role string `json:"role" gorm:"column:role"` // Role
|
||||||
IsActive bool `json:"isActive" gorm:"column:is_active;default:false"`
|
IsActive bool `json:"isActive" gorm:"column:is_active;default:false"`
|
||||||
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"` // Created at
|
CreatedAt time.Time `json:"createdAt" gorm:"column:created_at"` // Created at
|
||||||
UpdatedAt time.Time `json:"updatedAt" gorm:"column:updated_at"` // Updated 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 {
|
type UserCircleDetail struct {
|
||||||
|
|
Loading…
Add table
Reference in a new issue