vikunja-api/models/teams_delete.go
2018-07-16 08:18:15 +02:00

32 lines
581 B
Go

package models
func (t *Team) Delete(id int64) (err error) {
// Check if the team exists
_, err = GetTeamByID(id)
if err != nil {
return
}
// Delete the team
_, err = x.ID(id).Delete(&Team{})
if err != nil {
return
}
// Delete team members
_, err = x.Where("team_id = ?", id).Delete(&TeamMember{})
if err != nil {
return
}
// Delete team <-> namespace relations
_, err = x.Where("team_id = ?", id).Delete(&TeamNamespace{})
if err != nil {
return
}
// Delete team <-> lists relations
_, err = x.Where("team_id = ?", id).Delete(&TeamList{})
return
}