-
Notifications
You must be signed in to change notification settings - Fork 38
/
customer_support_remarks_updater.go
60 lines (47 loc) · 1.84 KB
/
customer_support_remarks_updater.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
package customersupportremarks
import (
"database/sql"
"time"
"github.com/gofrs/uuid"
"go.uber.org/zap"
"github.com/transcom/mymove/pkg/appcontext"
"github.com/transcom/mymove/pkg/apperror"
customersupportremarksop "github.com/transcom/mymove/pkg/gen/ghcapi/ghcoperations/customer_support_remarks"
"github.com/transcom/mymove/pkg/models"
"github.com/transcom/mymove/pkg/services"
)
type CustomerSupportRemarkUpdater struct {
}
func NewCustomerSupportRemarkUpdater() services.CustomerSupportRemarkUpdater {
return &CustomerSupportRemarkUpdater{}
}
func (o CustomerSupportRemarkUpdater) UpdateCustomerSupportRemark(appCtx appcontext.AppContext, params customersupportremarksop.UpdateCustomerSupportRemarkForMoveParams) (*models.CustomerSupportRemark, error) {
var remark models.CustomerSupportRemark
remarkID := params.CustomerSupportRemarkID
err := appCtx.DB().Find(&remark, remarkID)
if err != nil {
switch err {
case sql.ErrNoRows:
remarkID, _ := uuid.FromString(remarkID.String())
return nil, apperror.NewNotFoundError(remarkID, "customer support remark not found")
default:
return nil, apperror.NewQueryError("CustomerSupportRemark", err, "")
}
}
/*
https://dp3.atlassian.net/browse/MB-12730
MB-12730 udpdates to customer support remarks are restricted to the original remark creator
*/
sessionUserID := appCtx.Session().OfficeUserID
if remark.OfficeUserID != sessionUserID {
appCtx.Logger().Warn("Customer Support Remarks may only be edited by the user who created them.", zap.String("Customer Support RemarkID", remarkID.String()))
return nil, apperror.NewForbiddenError("Action not allowed")
}
remark.Content = *params.Body.Content
remark.UpdatedAt = time.Now()
verrs, err := appCtx.DB().Q().Connection.ValidateAndUpdate(&remark)
if verrs.Count() != 0 || err != nil {
return nil, err
}
return &remark, nil
}