Skip to content

Commit

Permalink
hotfix: added in admin update shelter transform to remove empty strin… (
Browse files Browse the repository at this point in the history
  • Loading branch information
fagundesjg authored May 16, 2024
1 parent a7c22c7 commit 38f817e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/shelter/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import z from 'zod';

import { capitalize } from '../../utils';
import { removeEmptyStrings } from '@/utils/utils';

export interface DefaultSupplyProps {
category: string;
Expand Down Expand Up @@ -44,7 +45,9 @@ const FullUpdateShelterSchema = ShelterSchema.omit({
id: true,
createdAt: true,
updatedAt: true,
}).partial();
})
.partial()
.transform(removeEmptyStrings);

export {
ShelterSchema,
Expand Down
8 changes: 8 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,19 @@ function calculateGeolocationBounds({
};
}

function removeEmptyStrings(obj: Record<string, any>): Record<string, any> {
return Object.entries(obj).reduce(
(prev, [key, value]) => (value === '' ? prev : { ...prev, [key]: value }),
{},
);
}

export {
ServerResponse,
calculateGeolocationBounds,
capitalize,
deepMerge,
getSessionData,
removeNotNumbers,
removeEmptyStrings,
};

0 comments on commit 38f817e

Please sign in to comment.