Connect sign-up to Sendico Facts intake (#46)
This commit is contained in:
1 parent
30f0455122
commit
a584c8189a
40 files changed
+1616
-35
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package sendico
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.sendico.io/tech/sxchnge/product/identity"
|
||||
merrors "git.sendico.io/tech/sxchnge/shared/errors"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// Only consumed wire fields are owned here; never import platform modules.
|
||||
type factsDTO struct {
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
CustomerRef string `json:"external_customer_ref"`
|
||||
}
|
||||
type submissionDTO struct {
|
||||
SubjectRef string `json:"subject_ref"`
|
||||
SourceRef string `json:"source_submission_ref"`
|
||||
Facts factsDTO `json:"facts"`
|
||||
}
|
||||
type receiptDTO struct {
|
||||
SubjectRef string `json:"subject_ref"`
|
||||
RegisteredAt time.Time `json:"registered_at"`
|
||||
SubmissionRef string `json:"submission_ref"`
|
||||
AcceptedAt time.Time `json:"accepted_at"`
|
||||
}
|
||||
type envelopeDTO struct {
|
||||
Status string `json:"status"`
|
||||
Data receiptDTO `json:"data"`
|
||||
}
|
||||
|
||||
func validRef(ref string) bool {
|
||||
id, err := bson.ObjectIDFromHex(ref)
|
||||
return err == nil && !id.IsZero() && id.Hex() == ref
|
||||
}
|
||||
func mapFacts(subject, source string, facts identity.Facts) submissionDTO {
|
||||
return submissionDTO{SubjectRef: subject, SourceRef: source, Facts: factsDTO{FullName: facts.FullName, Email: facts.Email, CustomerRef: facts.CustomerRef}}
|
||||
}
|
||||
func mapSubject(dto receiptDTO) (string, error) {
|
||||
if !validRef(dto.SubjectRef) || dto.RegisteredAt.IsZero() {
|
||||
return "", merrors.ServiceUnavailable("invalid Sendico registration receipt")
|
||||
}
|
||||
return dto.SubjectRef, nil
|
||||
}
|
||||
func mapReceipt(dto receiptDTO, subject string) (identity.Receipt, error) {
|
||||
if !validRef(dto.SubmissionRef) || dto.SubjectRef != subject || dto.AcceptedAt.IsZero() {
|
||||
return identity.Receipt{}, merrors.ServiceUnavailable("invalid Sendico intake receipt")
|
||||
}
|
||||
return identity.Receipt{SubmissionRef: dto.SubmissionRef, SubjectRef: dto.SubjectRef, AcceptedAt: dto.AcceptedAt}, nil
|
||||
}
|
||||
Reference in new issue
Block a user