replace simple with custom validation
This commit is contained in:
@@ -49,44 +49,20 @@ func (c *controller) handle(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
if user.PhoneNumber == nil || len(*user.PhoneNumber) == 0 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "phonenumber is required")
|
||||
}
|
||||
|
||||
if user.Email == nil || len(*user.Email) == 0 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "email is required")
|
||||
}
|
||||
|
||||
if len(user.Pass) == 0 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "password is required")
|
||||
}
|
||||
|
||||
pass, err := b64.StdEncoding.DecodeString(user.Pass)
|
||||
if err != nil {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "Invalid password")
|
||||
}
|
||||
user.Pass = string(pass)
|
||||
|
||||
if passwordValidationErrors := validation.ValidatePassword(&user); len(passwordValidationErrors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, "Password not strong enough", passwordValidationErrors)
|
||||
}
|
||||
|
||||
if len(user.Name) == 0 && len(user.First) == 0 && len(user.Last) == 0 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "name is required")
|
||||
if validationErrors := validation.ValidateSelfregistration(&user); len(validationErrors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, "Self registration failed", validationErrors)
|
||||
}
|
||||
|
||||
if len(user.First) != 0 && len(user.Last) != 0 {
|
||||
user.Name = fmt.Sprintf("%s %s", user.First, user.Last)
|
||||
}
|
||||
|
||||
if len(user.Provider.InternalID) == 0 || len(user.Provider.InternalID) > 10 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "Provider NPI is invalid")
|
||||
}
|
||||
|
||||
if len(user.Provider.OrganizatioName) == 0 {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "Provider Organization Name is invalid")
|
||||
}
|
||||
|
||||
provider, err := c.svc.Provider.GetByNPI(user.Provider.InternalID, authUser)
|
||||
if err != nil {
|
||||
fmt.Println("Error to create organization", err)
|
||||
|
||||
Reference in New Issue
Block a user