Compare commits
1 Commits
NPI-error-
...
self-regis
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ebc056d5 |
@@ -2,6 +2,7 @@ package selfregisterroute
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
b64 "encoding/base64"
|
b64 "encoding/base64"
|
||||||
@@ -22,6 +23,10 @@ const (
|
|||||||
notificationSmsBody = "You have registered as a Visit Reporter for CHM NEMT. Login: https://portal.bcbsinstitute.com Reset PW: https://portal.bcbsinstitute.com/forgot"
|
notificationSmsBody = "You have registered as a Visit Reporter for CHM NEMT. Login: https://portal.bcbsinstitute.com Reset PW: https://portal.bcbsinstitute.com/forgot"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
phoneNumberMaxLength = 12
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
instance *controller
|
instance *controller
|
||||||
once sync.Once
|
once sync.Once
|
||||||
@@ -44,12 +49,34 @@ func controllerInstance(svc *applicationservice.Service, cfg *config.Config) *co
|
|||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeNonNumberChars(input string) string {
|
||||||
|
result := ""
|
||||||
|
for _, char := range input {
|
||||||
|
if char >= '0' && char <= '9' {
|
||||||
|
result += string(char)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func (c *controller) handle(ctx echo.Context) error {
|
func (c *controller) handle(ctx echo.Context) error {
|
||||||
var user viewmodel.User
|
var user viewmodel.User
|
||||||
if err := ctx.Bind(&user); err != nil {
|
if err := ctx.Bind(&user); err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//format phone number - max length in database is 12 chars
|
||||||
|
formatedPhoneNumber := strings.TrimSpace(*user.PhoneNumber)
|
||||||
|
formatedPhoneNumber = strings.Replace(formatedPhoneNumber, "+1", "", -1)
|
||||||
|
formatedPhoneNumber = removeNonNumberChars(formatedPhoneNumber)
|
||||||
|
|
||||||
|
if len(formatedPhoneNumber) > phoneNumberMaxLength {
|
||||||
|
formatedPhoneNumber = formatedPhoneNumber[:phoneNumberMaxLength]
|
||||||
|
}
|
||||||
|
|
||||||
|
*user.PhoneNumber = formatedPhoneNumber
|
||||||
|
|
||||||
authUser, err := c.svc.Users.GetByUUID("573c70ff-733d-11e7-ba8f-0a6ad3fcdeaa", "")
|
authUser, err := c.svc.Users.GetByUUID("573c70ff-733d-11e7-ba8f-0a6ad3fcdeaa", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
return routeutils.HandleAPIError(ctx, err)
|
||||||
@@ -132,10 +159,14 @@ func (c *controller) handle(ctx echo.Context) error {
|
|||||||
|
|
||||||
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
logger := ctx.Logger()
|
||||||
|
logger.Warnf("Application Error: Could not send email notification to user email : %s", *user.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Send sms notification to Authorized user
|
//Send sms notification to Authorized user
|
||||||
|
|
||||||
|
formatedPhoneNumber = *user.PhoneNumber
|
||||||
|
|
||||||
notification = viewmodel.Notification{
|
notification = viewmodel.Notification{
|
||||||
Type: applicationservice.NOtificationTypeSMS,
|
Type: applicationservice.NOtificationTypeSMS,
|
||||||
To: *user.PhoneNumber,
|
To: *user.PhoneNumber,
|
||||||
@@ -144,7 +175,8 @@ func (c *controller) handle(ctx echo.Context) error {
|
|||||||
|
|
||||||
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return routeutils.HandleAPIError(ctx, err)
|
logger := ctx.Logger()
|
||||||
|
logger.Warnf("Application Error: Could not send sms notification to user mobile : %s", *user.PhoneNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
return routeutils.ResponseAPIOK(ctx, user)
|
return routeutils.ResponseAPIOK(ctx, user)
|
||||||
|
|||||||
Reference in New Issue
Block a user