Skip to content

Commit

Permalink
Merge pull request #107 from beabee-communityrm/fix/test-vat-number
Browse files Browse the repository at this point in the history
fix: check for valid VAT number
  • Loading branch information
wpf500 authored Dec 11, 2024
2 parents 0ad67b4 + 3682ad9 commit bb794b6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"express": "^4.19.2",
"express-session": "^1.18.0",
"gocardless-nodejs": "^3.25.0",
"jsvat-next": "^3.0.4",
"module-alias": "^2.2.3",
"moment": "^2.30.1",
"passport": "^0.7.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/api/dto/SignupFlowDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
IsString
} from "class-validator";

import { UpdateAddressDto } from "@api/dto/AddressDto";
import { StartContributionDto } from "@api/dto/ContributionDto";
import { CompleteJoinFlowDto } from "@api/dto/JoinFlowDto";
import IsPassword from "@api/validators/IsPassword";
Expand All @@ -16,6 +15,7 @@ import IsUrl from "@api/validators/IsUrl";
import type { JoinForm } from "@beabee/core/models";

import { CompleteUrls } from "@beabee/core/type";
import IsVatNumber from "@api/validators/IsVatNumber";

export class StartSignupFlowDto implements CompleteUrls {
@IsUrl()
Expand Down Expand Up @@ -53,6 +53,6 @@ export class CompleteSignupFlowDto
lastname?: string;

@IsOptional()
@IsString()
@IsVatNumber()
vatNumber?: string;
}
25 changes: 25 additions & 0 deletions apps/backend/src/api/validators/IsVatNumber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ValidationOptions, ValidateBy, buildMessage } from "class-validator";
import { checkVAT, countries } from "jsvat-next";

export default function IsVatNumber(
validationOptions?: ValidationOptions
): PropertyDecorator {
return ValidateBy(
{
name: "isVatNumber",
validator: {
validate(value) {
return (
typeof value === "string" &&
checkVAT(value, countries).isValidFormat
);
},
defaultMessage: buildMessage(
(eachPrefix) => eachPrefix + "$property must be a valid VAT number",
validationOptions
)
}
},
validationOptions
);
}
5 changes: 5 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ __metadata:
express-session: "npm:^1.18.0"
gocardless-nodejs: "npm:^3.25.0"
jest: "npm:^29.7.0"
jsvat-next: "npm:^3.0.4"
module-alias: "npm:^2.2.3"
moment: "npm:^2.30.1"
passport: "npm:^0.7.0"
Expand Down Expand Up @@ -9889,6 +9890,13 @@ __metadata:
languageName: node
linkType: hard

"jsvat-next@npm:^3.0.4":
version: 3.0.4
resolution: "jsvat-next@npm:3.0.4"
checksum: 10c0/8c6a02ddfaaf6c912358626b510d59551eadb08224a2b394ce474bc2742ce1c3af09ab131acb739b38ca8e47a3a71943204da81f8bb4cc8893c206fc2a14a745
languageName: node
linkType: hard

"juice@npm:^10.0.0":
version: 10.0.1
resolution: "juice@npm:10.0.1"
Expand Down

0 comments on commit bb794b6

Please sign in to comment.