Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow empty params in csv file #200

Merged
merged 5 commits into from
May 12, 2020
Merged

feat: Allow empty params in csv file #200

merged 5 commits into from
May 12, 2020

Conversation

lshaowei18
Copy link
Contributor

@lshaowei18 lshaowei18 commented May 6, 2020

Problem

We want to allow users to upload csv with empty params as long as it is not in recipient column.

Closes #194

Solution

Features:

  • No longer throws an error when there are empty params in the csv file.

Improvements:

  • Validate the recipients to make sure that they are valid according to their channel type.

Validations:

  • SMS, only + and numbers allowed
  • Email, validator.isEmail

Tests

SMS

  • Can upload csv with empty params that are not in recipient column
  • 400 when there is invalid recipient(s) in the csv file

Email

  • Can upload csv with empty params that are not in recipient column
  • 400 when there is invalid recipient(s) in the csv file

What tests should be run to confirm functionality?

}

const hasInvalidEmailRecipient = (records: MessageBulkInsertInterface[]): boolean => {
return records.some((record) => !validator.isEmail(record.recipient))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is the best approach performance wise. I could do this while parsing csv or when we are test hydrating, but it will be messy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine for now.

const hasInvalidSmsRecipient = (records: MessageBulkInsertInterface[]): boolean => {
const re = /^[0-9+]+$/
Copy link
Contributor Author

@lshaowei18 lshaowei18 May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How strict should I be with this regex?

Copy link
Contributor

@jeantanzj jeantanzj May 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a + exists, it should be at the start of the string.

const hasInvalidSmsRecipient = (records: MessageBulkInsertInterface[]): boolean => {
const re = /^[0-9+]+$/
return records.some((record) => !record.recipient.match(re))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re.test(record.recipient) should be faster. match returns an array of matched strings

@lshaowei18 lshaowei18 marked this pull request as ready for review May 11, 2020 07:01
@jeantanzj jeantanzj merged commit 22740d5 into develop May 12, 2020
@jeantanzj jeantanzj deleted the template-errors branch May 12, 2020 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Show errors once the user uploads an excel file
2 participants