2018-07-26 09:58:48 +02:00
|
|
|
package models
|
|
|
|
|
|
|
|
// Delete deletes a user from a team
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Remove a user from a team
|
|
|
|
// @Description Remove a user from a team. This will also revoke any access this user might have via that team.
|
|
|
|
// @tags team
|
|
|
|
// @Produce json
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Param id path int true "Team ID"
|
|
|
|
// @Param userID path int true "User ID"
|
|
|
|
// @Success 200 {object} models.Message "The user was successfully removed from the team."
|
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /teams/{id}/members/{userID} [delete]
|
2018-07-26 09:58:48 +02:00
|
|
|
func (tm *TeamMember) Delete() (err error) {
|
2018-07-27 19:20:49 +02:00
|
|
|
|
|
|
|
total, err := x.Where("team_id = ?", tm.TeamID).Count(&TeamMember{})
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if total == 1 {
|
|
|
|
return ErrCannotDeleteLastTeamMember{tm.TeamID, tm.UserID}
|
|
|
|
}
|
|
|
|
|
2018-07-26 09:58:48 +02:00
|
|
|
_, err = x.Where("team_id = ? AND user_id = ?", tm.TeamID, tm.UserID).Delete(&TeamMember{})
|
|
|
|
return
|
|
|
|
}
|