vikunja-api/pkg/models/team_members_delete.go
2018-10-31 12:42:38 +00:00

16 lines
383 B
Go

package models
// Delete deletes a user from a team
func (tm *TeamMember) Delete() (err error) {
total, err := x.Where("team_id = ?", tm.TeamID).Count(&TeamMember{})
if err != nil {
return
}
if total == 1 {
return ErrCannotDeleteLastTeamMember{tm.TeamID, tm.UserID}
}
_, err = x.Where("team_id = ? AND user_id = ?", tm.TeamID, tm.UserID).Delete(&TeamMember{})
return
}