Skip to content

Commit

Permalink
Incorporate improvements suggested by PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
townxelliot committed Jun 13, 2024
1 parent 235fcbf commit d5ba4b3
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions lambda/update/confirm_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,38 @@ func (idcc IdCheckComplete) Apply(lpa *shared.Lpa) []shared.FieldError {
return nil
}

func validateConfirmIdentity(prefix string, actor idccActor, changes []shared.Change, lpa *shared.Lpa) (IdCheckComplete, []shared.FieldError) {
var existing IdCheckComplete
func validateConfirmIdentity(prefix string, actor idccActor, ic *shared.IdentityCheck, changes []shared.Change) (IdCheckComplete, []shared.FieldError) {
var idcc IdCheckComplete

identityCheckParser := func(actor idccActor) func(p *parse.Parser) []shared.FieldError {
return func(p *parse.Parser) []shared.FieldError {
if existing.Actor != "" {
return []shared.FieldError{{Source: "/", Detail: "id check for multiple actors is not allowed"}}
}

switch actor {
case donor:
existing.IdentityCheck = lpa.Donor.IdentityCheck
case certificateProvider:
existing.IdentityCheck = lpa.CertificateProvider.IdentityCheck
}
errors := parse.Changes(changes).
Prefix(prefix, func(p *parse.Parser) []shared.FieldError {
idcc.Actor = actor

if existing.IdentityCheck == nil {
existing.IdentityCheck = &shared.IdentityCheck{}
if ic == nil {
ic = &shared.IdentityCheck{}
}

existing.Actor = actor
idcc.IdentityCheck = ic

return p.
Field("/type", &existing.IdentityCheck.Type, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", existing.IdentityCheck.Type)
Field("/type", &ic.Type, parse.Validate(func() []shared.FieldError {
return validate.IsValid("", ic.Type)
}), parse.MustMatchExisting()).
Field("/checkedAt", &existing.IdentityCheck.CheckedAt, parse.Validate(func() []shared.FieldError {
return validate.Time("", existing.IdentityCheck.CheckedAt)
Field("/checkedAt", &ic.CheckedAt, parse.Validate(func() []shared.FieldError {
return validate.Time("", ic.CheckedAt)
}), parse.MustMatchExisting()).
Field("/reference", &existing.IdentityCheck.Reference, parse.Validate(func() []shared.FieldError {
return validate.Required("", existing.IdentityCheck.Reference)
Field("/reference", &ic.Reference, parse.Validate(func() []shared.FieldError {
return validate.Required("", ic.Reference)
}), parse.MustMatchExisting()).
Consumed()
}
}

errors := parse.Changes(changes).
Prefix(prefix, identityCheckParser(actor)).
Errors()

if existing.Actor == "" {
return existing, append(errors, shared.FieldError{Source: "/", Detail: "id check for unknown actor type"})
}
}).Errors()

return existing, errors
return idcc, errors
}

func validateDonorConfirmIdentity(changes []shared.Change, lpa *shared.Lpa) (IdCheckComplete, []shared.FieldError) {
return validateConfirmIdentity("/donor/identityCheck", donor, changes, lpa)
return validateConfirmIdentity("/donor/identityCheck", donor, lpa.Donor.IdentityCheck, changes)
}

func validateCertificateProviderConfirmIdentity(changes []shared.Change, lpa *shared.Lpa) (IdCheckComplete, []shared.FieldError) {
return validateConfirmIdentity("/certificateProvider/identityCheck", certificateProvider, changes, lpa)
return validateConfirmIdentity("/certificateProvider/identityCheck", certificateProvider, lpa.CertificateProvider.IdentityCheck, changes)
}

0 comments on commit d5ba4b3

Please sign in to comment.