/
trb_request_reopened.go
69 lines (57 loc) · 2.11 KB
/
trb_request_reopened.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package email
import (
"bytes"
"context"
"html/template"
"path"
"github.com/google/uuid"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/models"
)
// SendTRBRequestReopenedEmailInput contains the data needed to to send the TRB advice
// letter submitted email
type SendTRBRequestReopenedEmailInput struct {
TRBRequestID uuid.UUID
TRBRequestName string
RequesterName string
Recipients []models.EmailAddress
CopyTRBMailbox bool
ReasonReopened models.HTML
}
// trbRequestReopenedEmailTemplateParams contains the data needed for interpolation in
// the TRB request re-opened email
type trbRequestReopenedEmailTemplateParams struct {
TRBRequestName string
ReasonReopened template.HTML
TRBRequestLink string
TRBAdminRequestLink string
RequesterName string
TRBEmail models.EmailAddress
}
// SendTRBRequestReopenedEmail sends an email to the EASI admin team indicating that a TRB request
// has been re-opened
func (c Client) SendTRBRequestReopenedEmail(ctx context.Context, input SendTRBRequestReopenedEmailInput) error {
subject := "The TRB request " + input.TRBRequestName + " has been re-opened."
allRecipients := input.Recipients
if input.CopyTRBMailbox {
allRecipients = append(input.Recipients, c.config.TRBEmail)
}
templateParams := trbRequestReopenedEmailTemplateParams{
TRBRequestName: input.TRBRequestName,
RequesterName: input.RequesterName,
ReasonReopened: input.ReasonReopened.ToTemplate(),
TRBRequestLink: c.urlFromPath(path.Join("trb", "task-list", input.TRBRequestID.String())),
TRBAdminRequestLink: c.urlFromPath(path.Join("trb", input.TRBRequestID.String(), "request")),
TRBEmail: c.config.TRBEmail,
}
var b bytes.Buffer
err := c.templates.trbRequestReopened.Execute(&b, templateParams)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = c.sender.Send(ctx, allRecipients, nil, subject, b.String())
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}