/
trb_request_trb_lead.go
112 lines (90 loc) · 3.55 KB
/
trb_request_trb_lead.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package email
import (
"bytes"
"context"
"path"
"github.com/google/uuid"
"golang.org/x/sync/errgroup"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/models"
)
// SendTRBRequestTRBLeadEmailInput contains the data needed to send an email to the TRB team
// indicating that a TRB lead has been assigned
type SendTRBRequestTRBLeadEmailInput struct {
TRBRequestID uuid.UUID
TRBRequestName string
RequesterName string
TRBLeadName string
Component string
TRBLeadEmail models.EmailAddress
}
// trbLeadAdminEmailTemplateParams contains the data needed for interpolation in the TRB lead admin email template
type trbLeadAdminEmailTemplateParams struct {
TRBLeadName string
TRBRequestName string
TRBRequestLink string
RequesterName string
}
// trbLeadAssigneeEmailTemplateParams contains the data needed for interpolation in the TRB lead
// assignee email template
type trbLeadAssigneeEmailTemplateParams struct {
TRBLeadName string
TRBRequestName string
TRBRequestLink string
RequesterName string
Component string
}
// SendTRBRequestTRBLeadAssignedEmails sends emails to the TRB team and the TRB lead when the lead
// is assigned to a TRB request
func (c Client) SendTRBRequestTRBLeadAssignedEmails(ctx context.Context, input SendTRBRequestTRBLeadEmailInput) error {
g := new(errgroup.Group)
g.Go(func() error {
return c.sendTRBRequestTRBLeadAdminEmail(ctx, input)
})
g.Go(func() error {
return c.sendTRBRequestTRBLeadAssigneeEmail(ctx, input)
})
return g.Wait()
}
// sendTRBRequestTRBLeadAdminEmail sends an email to the TRB team indicating that a TRB lead has been assigned
func (c Client) sendTRBRequestTRBLeadAdminEmail(ctx context.Context, input SendTRBRequestTRBLeadEmailInput) error {
subject := input.TRBRequestName + " is assigned to " + input.TRBLeadName
templateParams := trbLeadAdminEmailTemplateParams{
TRBLeadName: input.TRBLeadName,
TRBRequestName: input.TRBRequestName,
TRBRequestLink: c.urlFromPath(path.Join("trb", input.TRBRequestID.String(), "request")),
RequesterName: input.RequesterName,
}
var b bytes.Buffer
err := c.templates.trbRequestTRBLeadAdmin.Execute(&b, templateParams)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = c.sender.Send(ctx, []models.EmailAddress{c.config.TRBEmail}, nil, subject, b.String())
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}
// sendTRBRequestTRBLeadAssigneeEmail sends an email to a user indicating that they have been assigned
// as the TRB lead for a TRB request
func (c Client) sendTRBRequestTRBLeadAssigneeEmail(ctx context.Context, input SendTRBRequestTRBLeadEmailInput) error {
subject := "You have been assigned as the TRB lead for " + input.TRBRequestName
templateParams := trbLeadAssigneeEmailTemplateParams{
TRBLeadName: input.TRBLeadName,
TRBRequestName: input.TRBRequestName,
TRBRequestLink: c.urlFromPath(path.Join("trb", input.TRBRequestID.String(), "request")),
RequesterName: input.RequesterName,
Component: input.Component,
}
var b bytes.Buffer
err := c.templates.trbRequestTRBLeadAssignee.Execute(&b, templateParams)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = c.sender.Send(ctx, []models.EmailAddress{input.TRBLeadEmail}, nil, subject, b.String())
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}