-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sperre for refusjon høyere enn inntekten
- Loading branch information
1 parent
81ad166
commit d2e1368
Showing
2 changed files
with
42 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |