fix(services): improve validation PUT /users/current

This commit is contained in:
Divlo
2022-01-29 22:31:37 +01:00
parent 32ac15c831
commit 2405b4951b
7 changed files with 890 additions and 1572 deletions

View File

@ -1,21 +1,25 @@
/**
* Parse a nullish string:
* - if `string === undefined`, it returns `defaultString`
* - if `string === null`, it returns `null`
* - if `string.length === 0`, it returns `null`
* - if `string == null`, it returns `defaultString`
* - if `string.length > 0`, it returns `string`
* - else, it returns `string`
* @param defaultString
* @param string
* @returns
*/
export const parseStringNullish = (
defaultString: string | null,
string?: string
string?: string | null
): string | null => {
if (string != null) {
if (string.length > 0) {
return string
}
if (string === undefined) {
return defaultString
}
if (string === null) {
return null
}
return defaultString
if (string.length === 0) {
return null
}
return string
}