Skip to content

Commit

Permalink
Sperre for refusjon høyere enn inntekten
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFjellstad committed Dec 19, 2024
1 parent 81ad166 commit d2e1368
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 21 deletions.
12 changes: 12 additions & 0 deletions schema/valideringDelvisInnsendingSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,16 @@ export default z
path: ['refusjon', 'refusjonPrMnd']
});
}

if (value.refusjon.harEndringer === 'Ja') {
value.refusjon.refusjonEndringer?.map((endring, index) => {
if ((endring.beloep ?? 0) > (value.inntekt?.beloep ?? 0) && value.inntekt.beloep !== 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Refusjon kan ikke være høyere enn brutto lønn.',
path: ['refusjon', 'refusjonEndringer', index, 'beloep']
});
}
});
}
});
51 changes: 30 additions & 21 deletions utils/mapErrorsObjectToFeilmeldinger.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import isObject from './isObject';

export default function mapErrorsObjectToFeilmeldinger(errors) {
const mapErrorsObject = (errors: any, subKey = ''): any[] => {
return Object.keys(errors).flatMap((key) => {
if (typeof errors[key] === 'string') {
if (isObject(errors)) {
return Object.keys(errors).flatMap((key) => {
if (typeof errors[key] === 'string') {
return {
key: subKey ? `${subKey}.${key}` : key,
message: errors[key]
};
}

if (!errors[key]?.message) {
return mapErrorsObject(errors[key], subKey ? `${subKey}.${key}` : key);
}

return {
key: subKey ? `${subKey}.${key}` : key,
message: errors[key]
message: errors[key]?.message
};
}

if (!errors[key].message) {
return mapErrorsObject(errors[key], subKey ? `${subKey}.${key}` : key);
}

return {
key: subKey ? `${subKey}.${key}` : key,
message: errors[key].message
};
});
});
}
};
const errorsMapped = mapErrorsObject(errors);

const feilmeldinger = errorsMapped.map((error) => {
return {
felt: error.key,
text: error.message
};
});
return feilmeldinger;
let feilmeldinger = [];
if (Array.isArray(errorsMapped)) {
feilmeldinger = errorsMapped.map((error) => {
if (error) {
return {
felt: error.key,
text: error.message
};
}
});
}
return feilmeldinger.filter((melding) => !!melding);
}

0 comments on commit d2e1368

Please sign in to comment.