DoSomethingArchive / quicksilver-api

:postbox: API gateway to Quicksilver (Message Broker) functionality.
MIT License
0 stars 3 forks source link

Functional validation for one of three parameter #82

Closed deezone closed 8 years ago

deezone commented 8 years ago

Fixes #81

Adds validation to POST /api/v1/user/password for at least one of user_id, email, or mobile.

To Test:

{
  "email": "test@test.com",
  "application_id": "US",
  "email_template": "mb-user-password-reset"
}

✅ returns:

{
  "activity": "user_password",
  "email": "test@test.com",
  "uid": "1700142",
  "merge_vars": {
    "MEMBER_COUNT": "3.5 million",
    "FNAME": "Test",
    "RESET_LINK": null
  },
  "user_country": null,
  "user_language": null,
  "email_template": null,
  "email_tags": [
    "user_password"
  ],
  "activity_timestamp": null,
  "application_id": null
}
{
  "application_id": "US",
  "email_template": "mb-user-password-reset"
}

✅ returns:

{
  "reason": "3 attributes are invalid",
  "errors": {
    "user_id": [
      {
        "rule": "required",
        "message": "\"required\" validation rule failed for input: ''\nSpecifically, it threw an error.  Details:\n undefined"
      },
      {
        "rule": "hexadecimal",
        "message": "\"hexadecimal\" validation rule failed for input: ''\nSpecifically, it threw an error.  Details:\n undefined"
      }
    ],
    "email": [
      {
        "rule": "required",
        "message": "\"required\" validation rule failed for input: ''\nSpecifically, it threw an error.  Details:\n undefined"
      },
      {
        "rule": "email",
        "message": "\"email\" validation rule failed for input: ''\nSpecifically, it threw an error.  Details:\n undefined"
      }
    ],
    "mobile": [
      {
        "rule": "required",
        "message": "\"required\" validation rule failed for input: ''\nSpecifically, it threw an error.  Details:\n undefined"
      }
    ]
  }
}
deezone commented 8 years ago

@sergii-tkachenko Please advise on ES6 formatting. I can't seem to get functionality working / eslint passing using:

      required: () => {
        return !this.email && !this.mobile;
      },

vs

      required: function() {
        return !this.email && !this.mobile;
      },
deezone commented 8 years ago

@sergii-tkachenko : ready for review:

  ․․․․․․․

  4 passing (1s)
  3 pending
deezone commented 8 years ago

@sergii-tkachenko Is this good to go?

sergiitk commented 8 years ago

Perfecto 👍