Skip to content

Commit

Permalink
Fix #237 Validate phone endpoints returns error
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 12, 2023
1 parent af21449 commit 58f4cbf
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/handlerv2/validatephonenumber_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func ValidatePhoneNumber(w http.ResponseWriter, r *http.Request) {

// validating request payload
valid, err := govalidator.ValidateStruct(validateReq)
if valid != true {
if !valid {
log.Printf("Missing mandatory params for validating phone number")
common.HandleErrorV2(w, http.StatusBadRequest, err.Error(), err)
return
Expand All @@ -49,7 +49,7 @@ func ValidatePhoneNumber(w http.ResponseWriter, r *http.Request) {
return
}

if exist == true {
if exist {
valResp.Result = false
valResp.Message = "Phone number is in use"
response, _ := json.Marshal(valResp)
Expand All @@ -62,16 +62,15 @@ func ValidatePhoneNumber(w http.ResponseWriter, r *http.Request) {
//Check whether the phone number is in otp colleciton
o, err := otp.PhoneNumberExist(sanitizedPhoneNumber)
if err != nil {
m := fmt.Sprintf("Failed to validate user phone number: %v", validateReq.Phone)
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
m := fmt.Sprintf("Failed to find otp for phone number: %v", err)
log.Println(m)
}

if o != (otp.Otp{}) {
if primitive.NewObjectID().Timestamp().Sub(o.ID.Timestamp()) > 2*time.Minute {
err = otp.Delete(o.ID.Hex())
if err != nil {
m := fmt.Sprintf("Failed to clear expired otp")
m := "Failed to clear expired otp"
common.HandleErrorV2(w, http.StatusInternalServerError, m, err)
return
}
Expand Down

0 comments on commit 58f4cbf

Please sign in to comment.