Skip to content

Commit

Permalink
Adds validation error to tax id creation & update
Browse files Browse the repository at this point in the history
  • Loading branch information
DanaNussair committed Nov 1, 2022
1 parent 9292105 commit 0e77cd2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
18 changes: 16 additions & 2 deletions npm-shrinkwrap.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kontist/mock-solaris",
"version": "1.0.56",
"version": "1.0.57",
"description": "Mock Service for Solaris API",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down Expand Up @@ -38,7 +38,8 @@
"redis-mock": "^0.49.0",
"swig": "^1.4.2",
"winston": "^2.4.4",
"winston-loggly-bulk": "2.0.3"
"winston-loggly-bulk": "2.0.3",
"validate-steuerid": "1.0.4"
},
"devDependencies": {
"@types/chai": "^4.2.11",
Expand Down
26 changes: 26 additions & 0 deletions src/routes/taxIdentifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@ import {
} from "../db";

import { createChangeRequest } from "./changeRequest";
import { isSteuerIdValid } from "validate-steuerid";

export const TIN_UPDATE = "Patch/tax-indentifications/id";

const deTaxIdValidationError = {
id: Date.now().toString(),
status: 400,
code: "invalid_model",
title: "Invalid Model",
detail:
"number is not a valid person tax identification number for country: DE",
source: {
field: "number",
message: "is not a valid person tax identification number for country: DE",
},
};

export const submitTaxIdentification = async (req, res) => {
const { person_id: personId } = req.params;

Expand Down Expand Up @@ -45,6 +59,12 @@ export const submitTaxIdentification = async (req, res) => {
});
}

if (!isSteuerIdValid(tin.number) && tin.country === "DE") {
return res.status(400).send({
errors: [deTaxIdValidationError],
});
}

if (tins.length) {
if (tins.find((tinRow) => tinRow.country === tin.country)) {
return res.status(400).send({
Expand Down Expand Up @@ -118,6 +138,12 @@ export const updateTaxIdentification = async (req, res) => {
});
}

if (!isSteuerIdValid(tin.number) && tin.country === "DE") {
return res.status(400).send({
errors: [deTaxIdValidationError],
});
}

if (!tin.primary) {
if (!tins.find((tinRow) => tinRow.primary === true)) {
return res.status(400).send({
Expand Down

0 comments on commit 0e77cd2

Please sign in to comment.