AddGrade erase any previous grade recorded for the user
Some checks are pending
continuous-integration/drone/push Build is running
Some checks are pending
continuous-integration/drone/push Build is running
This commit is contained in:
parent
51a311f0b9
commit
107b17c11f
1 changed files with 13 additions and 0 deletions
13
works.go
13
works.go
|
|
@ -472,6 +472,19 @@ func (u *User) GetMyWorkGrade(w *Work) (g WorkGrade, err error) {
|
|||
}
|
||||
|
||||
func (w *Work) AddGrade(grade WorkGrade) error {
|
||||
u := User{Id: grade.IdUser}
|
||||
|
||||
// Search a previous record
|
||||
g, err := u.GetMyWorkGrade(w)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
return err
|
||||
} else if err == nil {
|
||||
_, err = g.Delete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return w.AddGrades([]WorkGrade{grade})
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue