Skip to content

Commit

Permalink
fix(backend): Trim string when is optional for TransformString
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Aug 12, 2024
1 parent a861634 commit 3717d97
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/backend/src/utils/text-language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const IsTextLanguageInput = () => {
validator: {
validate(item: TextLanguageInput | TextLanguageInput[]) {
return (Array.isArray(item) ? item : [item]).every(
item => item.value.trim().length > 0,
item => item.value?.trim().length > 0,
);
},
},
Expand All @@ -51,7 +51,7 @@ export const MaxLengthLanguageInput = ({ length }: { length: number }) => {
validator: {
validate(item: TextLanguageInput | TextLanguageInput[]) {
return (Array.isArray(item) ? item : [item]).every(
item => item.value.trim().length <= length,
item => item.value?.trim().length <= length,
);
},
},
Expand All @@ -70,7 +70,7 @@ export const MinLengthLanguageInput = ({ length }: { length: number }) => {
validator: {
validate(item: TextLanguageInput | TextLanguageInput[]) {
return (Array.isArray(item) ? item : [item]).every(
item => item.value.trim().length >= length,
item => item.value?.trim().length >= length,
);
},
},
Expand All @@ -86,7 +86,7 @@ export const TransformTextLanguageInput = ({
if (Array.isArray(value)) {
let current = value.map(item => ({
...item,
value: item.value.trimStart().trimEnd(),
value: item.value?.trimStart().trimEnd(),
}));

// If is only one item and isn't english then change to english
Expand All @@ -104,14 +104,14 @@ export const TransformTextLanguageInput = ({

return {
...value,
value: value.value.trimStart().trimEnd(),
value: value.value?.trimStart().trimEnd(),
};
};

export const TransformString = ({ value }: { value: string[] | string }) => {
if (Array.isArray(value)) {
return value.map(item => item.trimStart().trimEnd());
return value.map(item => item?.trimStart().trimEnd());
}

return value.trimStart().trimEnd();
return value?.trimStart().trimEnd();
};

0 comments on commit 3717d97

Please sign in to comment.