stash/pkg/performer/validate.go
julien0221 d673c4ce03
added details, deathdate, hair color, weight to performers and added details to studios (#1274)
* added details to performers and studios
* added deathdate, hair_color and weight to performers
* Simplify performer/studio create mutations
* Add changelog and recategorised

Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2021-04-16 16:06:35 +10:00

37 lines
856 B
Go

package performer
import (
"errors"
"github.com/stashapp/stash/pkg/models"
"github.com/stashapp/stash/pkg/utils"
)
func ValidateDeathDate(performer *models.Performer, birthdate *string, deathDate *string) error {
// don't validate existing values
if birthdate == nil && deathDate == nil {
return nil
}
if performer != nil {
if birthdate == nil && performer.Birthdate.Valid {
birthdate = &performer.Birthdate.String
}
if deathDate == nil && performer.DeathDate.Valid {
deathDate = &performer.DeathDate.String
}
}
if birthdate == nil || deathDate == nil || *birthdate == "" || *deathDate == "" {
return nil
}
f, _ := utils.ParseDateStringAsTime(*birthdate)
t, _ := utils.ParseDateStringAsTime(*deathDate)
if f.After(t) {
return errors.New("the date of death should be higher than the date of birth")
}
return nil
}