-
Notifications
You must be signed in to change notification settings - Fork 11
/
system_intake_update_lcid.go
139 lines (129 loc) · 4.01 KB
/
system_intake_update_lcid.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package email
import (
"bytes"
"context"
"errors"
"fmt"
"html/template"
"time"
"github.com/cmsgov/easi-app/pkg/apperrors"
"github.com/cmsgov/easi-app/pkg/models"
)
type systemIntakeUpdateLCIDEmailParameters struct {
LifecycleID string
LifecycleIssuedAt string
LifecycleExpiresAtPrev string
LifecycleExpiresAtNew string
LifecycleScopePrev template.HTML
LifecycleScopeNew template.HTML
LifecycleCostBaselinePrev string
LifecycleCostBaselineNew string
DecisionNextStepsPrev template.HTML
DecisionNextStepsNew template.HTML
ITGovernanceInboxAddress string
AmendmentDate string
Reason template.HTML
AdditionalInfo template.HTML
}
func (sie systemIntakeEmails) SystemIntakeUpdateLCIDBody(
lifecycleID string,
lifecycleIssuedAt *time.Time,
lifecycleExpiresAtPrev *time.Time,
lifecycleExpiresAtNew *time.Time,
lifecycleScopePrev *models.HTML,
lifecycleScopeNew *models.HTML,
lifecycleCostBaselinePrev string,
lifecycleCostBaselineNew string,
decisionNextStepsPrev *models.HTML,
decisionNextStepsNew *models.HTML,
amendmentDate time.Time,
reason *models.HTML,
additionalInfo *models.HTML,
) (string, error) {
var expiresAtPrev string
if lifecycleExpiresAtPrev != nil {
expiresAtPrev = lifecycleExpiresAtPrev.Format("01/02/2006")
}
var expiresAtNew string
if lifecycleExpiresAtNew != nil {
expiresAtNew = lifecycleExpiresAtNew.Format("01/02/2006")
}
var issuedAt string
if lifecycleIssuedAt != nil {
issuedAt = lifecycleIssuedAt.Format("01/02/2006")
}
data := systemIntakeUpdateLCIDEmailParameters{
LifecycleID: lifecycleID,
LifecycleIssuedAt: issuedAt,
LifecycleExpiresAtPrev: expiresAtPrev,
LifecycleExpiresAtNew: expiresAtNew,
LifecycleScopePrev: lifecycleScopePrev.ToTemplate(),
LifecycleScopeNew: lifecycleScopeNew.ToTemplate(),
LifecycleCostBaselinePrev: lifecycleCostBaselinePrev,
LifecycleCostBaselineNew: lifecycleCostBaselineNew,
DecisionNextStepsPrev: decisionNextStepsPrev.ToTemplate(),
DecisionNextStepsNew: decisionNextStepsNew.ToTemplate(),
ITGovernanceInboxAddress: sie.client.config.GRTEmail.String(),
AmendmentDate: amendmentDate.Format("01/02/2006"),
Reason: reason.ToTemplate(),
AdditionalInfo: additionalInfo.ToTemplate(),
}
var b bytes.Buffer
if sie.client.templates.systemIntakeUpdateLCID == nil {
return "", errors.New("update lcid template is nil")
}
err := sie.client.templates.systemIntakeUpdateLCID.Execute(&b, data)
if err != nil {
return "", err
}
return b.String(), nil
}
// SendUpdateLCIDNotification notifies user-selected recipients that a system intake form needs edits
func (sie systemIntakeEmails) SendUpdateLCIDNotification(
ctx context.Context,
recipients models.EmailNotificationRecipients,
lifecycleID string,
lifecycleIssuedAt *time.Time,
lifecycleExpiresAtPrev *time.Time,
lifecycleExpiresAtNew *time.Time,
lifecycleScopePrev *models.HTML,
lifecycleScopeNew *models.HTML,
lifecycleCostBaselinePrev string,
lifecycleCostBaselineNew string,
decisionNextStepsPrev *models.HTML,
decisionNextStepsNew *models.HTML,
amendmentDate time.Time,
reason *models.HTML,
additionalInfo *models.HTML,
) error {
subject := fmt.Sprintf("A Life Cycle ID (%s) has been updated", lifecycleID)
body, err := sie.SystemIntakeUpdateLCIDBody(
lifecycleID,
lifecycleIssuedAt,
lifecycleExpiresAtPrev,
lifecycleExpiresAtNew,
lifecycleScopePrev,
lifecycleScopeNew,
lifecycleCostBaselinePrev,
lifecycleCostBaselineNew,
decisionNextStepsPrev,
decisionNextStepsNew,
amendmentDate,
reason,
additionalInfo,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
err = sie.client.sender.Send(
ctx,
sie.client.listAllRecipients(recipients),
nil,
subject,
body,
)
if err != nil {
return &apperrors.NotificationError{Err: err, DestinationType: apperrors.DestinationTypeEmail}
}
return nil
}