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

Support multiple file upload validation #10343

Closed
wants to merge 3 commits into from

Conversation

blangley28
Copy link

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Currently file validation via the ParseFilePipe only works when validating a single file. When using an array of files it always throws an error.

Issue Number: N/A

What is the new behavior?

Single file validation continues to work unchanged, but now when uploading multiple files:

  1. fileIsRequired works
  2. Each file in the array is validated

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build eb1f30dd-90b6-4c45-9f27-fe86506c8ee6

  • 4 of 5 (80.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 93.787%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/pipes/file/parse-file.pipe.ts 4 5 80.0%
Totals Coverage Status
Change from base Build fe8b361f-7c4e-4666-8553-05c4501d57f0: -0.01%
Covered Lines: 6114
Relevant Lines: 6519

💛 - Coveralls

@@ -39,7 +39,7 @@ export class ParseFilePipe implements PipeTransform<any> {
}

async transform(value: any): Promise<any> {
if (isUndefined(value)) {
if (isUndefined(value) || (Array.isArray(value) && isEmpty(value))) {
Copy link
Member

Choose a reason for hiding this comment

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

@thiagomini I think you implemented this pipe, correct? 🙌 If so, could you verify this PR?

Copy link
Contributor

@thiagomini thiagomini left a comment

Choose a reason for hiding this comment

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

First, I would like to thank you for your time invested into this bug fix! I left some suggestions to improve the readability of the code, but of utmost importance is the addition of automated tests that cover this feature. Can you create such tests for the correspondent spec file? Thanks!

packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
@thiagomini
Copy link
Contributor

Hey @blangley28 , could you work on the changes I've asked? Thanks!

@blangley28
Copy link
Author

@thiagomini sorry for the delay. Just pushed some updated. I also found that while using FileFieldInterceptor the type of value is an object. So I added some handling to that here.
Because both the object and array use the same Promise.all snippet I wanted to break that out into a function. There are quite alot of validate% methods now... let me know if you have any name suggestions!

Copy link
Contributor

@Tony133 Tony133 left a comment

Choose a reason for hiding this comment

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

I have reported missing some semicolons in some code statements

packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
packages/common/pipes/file/parse-file.pipe.ts Outdated Show resolved Hide resolved
@thiagomini
Copy link
Contributor

@thiagomini sorry for the delay. Just pushed some updated. I also found that while using FileFieldInterceptor the type of value is an object. So I added some handling to that here. Because both the object and array use the same Promise.all snippet I wanted to break that out into a function. There are quite alot of validate% methods now... let me know if you have any name suggestions!

No problem @blangley28! Now you only have to fix the tests and add the new ones.

@PhelixTaken
Copy link

Hello,

Is this being continued? I really would like to have this since I need to validate multiple files.
I made my own implementation, but would rather not use that and just use the native stuff.

I hope it gets merged soon!

@thiagomini
Copy link
Contributor

Hey @PhelixTaken. We cannot merge this PR until it has all tests passing. You are welcome to create a branch that resolves this problem as well, I would be happy to review it! I can work on that issue too once I have some time, but I can't promise you a date.

@mahkassem
Copy link
Contributor

mahkassem commented Dec 7, 2022

Thank you for the great efforts.

I want to add that thereAreNoFilesIn() method is not working if the value is array but empty.
this worked for me:

private thereAreNoFilesIn(value: any): boolean {
    if (Array.isArray(value)) {
        return value.length === 0;
    } else if (isObject(value)) {
        return Object.keys(value).length === 0;
    } else {
        return isEmpty(value);
    }
}

also isUndefined() is deprecated, I have edited this to use value === undefined

my code passed test and test:cov, you can see it here:
Parse-File-Pipe-Fix

I would love to help in this PR. just let me know :)

@kamilmysliwiec
Copy link
Member

Let's track this here #10737

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.

None yet

7 participants