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

feature: allow to blacklist or whitelist country codes in the IsIBAN decorator #2048

Closed
spotlesscoder opened this issue Apr 16, 2023 · 6 comments
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.

Comments

@spotlesscoder
Copy link

spotlesscoder commented Apr 16, 2023

Description

I want to build an API that only accepts german IBANs for payments.

Proposed solution

Add options to the decorators that allow to either

  • whitelist country codes
  • blacklist country codes

Each of the two params should allow an array of ISO3166-2 country codes as strings (or maybe use an enum for TS?).

Should look something like this for the API

class MyClass {
  @IsIBAN({whitelistCountries: ["DE"]})
  germanIBAN: string;

  @IsIBAN({blacklistCountries: ["US"]})
  nonUSIBAN: string;
}

@spotlesscoder spotlesscoder added flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features. labels Apr 16, 2023
@edilson
Copy link

edilson commented Jun 14, 2023

@CodingSpiderFox looks like in order to achieve that it would be necessary to make some changes on library that checks the IBAN.

@spotlesscoder
Copy link
Author

I would just follow a naive approach (pseudocode)

let matchesValid = false;
whitelistCountries.forEach((country) => {
if(iban.startsWith(countryCode)) {
matchesValid = true;
}
)}

return matchesValid &&

@edilson
Copy link

edilson commented Jun 15, 2023

Maybe for now we could use your approach whilst the lib that checks the IBAN doesn't implement this feature.

@braaar
Copy link
Member

braaar commented Jul 19, 2023

I suggest you resubmit this in validator.js. This library is not in the habit of augmenting validators from validator.js with custom logic unless there is a particularly strong reason for it. In the meantime you can use a custom validator for this.

@braaar braaar closed this as not planned Won't fix, can't repro, duplicate, stale Jul 19, 2023
@edilson
Copy link

edilson commented Jul 19, 2023

Hey @braaar actually there's a PR opened in validator.js for that purpose, once it gets merged maybe we could implement it here.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.
Development

No branches or pull requests

3 participants