-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test to show replacement attorney opt-out works * Add trust corporation opt-out update
- Loading branch information
Showing
7 changed files
with
244 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/shared" | ||
"github.com/ministryofjustice/opg-data-lpa-store/internal/validate" | ||
) | ||
|
||
type TrustCorporationOptOut struct { | ||
trustCorporationUID string | ||
} | ||
|
||
func (c TrustCorporationOptOut) Apply(lpa *shared.Lpa) []shared.FieldError { | ||
for i := range lpa.TrustCorporations { | ||
if lpa.TrustCorporations[i].UID == c.trustCorporationUID { | ||
if len(lpa.TrustCorporations[i].Signatories) > 0 && !lpa.TrustCorporations[i].Signatories[0].SignedAt.IsZero() { | ||
return []shared.FieldError{{Source: "/type", Detail: "trust corporation cannot opt out after signing"}} | ||
} | ||
|
||
lpa.TrustCorporations[i].Status = shared.AttorneyStatusRemoved | ||
return nil | ||
} | ||
} | ||
|
||
return []shared.FieldError{{Source: "/type", Detail: "trust corporation not found"}} | ||
} | ||
|
||
func validateTrustCorporationOptOut(update shared.Update) (TrustCorporationOptOut, []shared.FieldError) { | ||
if len(update.Changes) > 0 { | ||
return TrustCorporationOptOut{}, []shared.FieldError{{Source: "/changes", Detail: "expected empty"}} | ||
} | ||
|
||
author := update.Author.Details() | ||
|
||
if errs := validate.UUID("/author", author.UID); len(errs) > 0 { | ||
return TrustCorporationOptOut{}, errs | ||
} | ||
|
||
return TrustCorporationOptOut{trustCorporationUID: author.UID}, nil | ||
} |
Oops, something went wrong.