Skip to content

Commit

Permalink
fix: changed name of priority to priorities, fixed zod priority schema (
Browse files Browse the repository at this point in the history
  • Loading branch information
fagundesjg authored May 29, 2024
2 parents adcb6cb + 2d3bb01 commit 55a1a9a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/shelter/ShelterSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class ShelterSearch {
}

priority(supplyIds: string[] = []): Prisma.ShelterWhereInput {
if (!this.formProps.priority?.length) return {};
if (!this.formProps.priorities?.length) return {};

return {
shelterSupplies: {
some: {
priority: {
in: this.formProps.priority,
in: this.formProps.priorities,
},
supplyId:
supplyIds.length > 0
Expand Down Expand Up @@ -81,7 +81,6 @@ class ShelterSearch {
return {
shelterSupplies: {
some: {
priority: undefined,
supply: {
supplyCategoryId: {
in: this.formProps.supplyCategoryIds,
Expand Down Expand Up @@ -179,7 +178,7 @@ class ShelterSearch {
search,
{ OR: this.shelterStatus },
this.priority(this.formProps.supplyIds),
this.supplyCategoryIds(this.formProps.priority),
this.supplyCategoryIds(this.formProps.priorities),
],
};

Expand Down
17 changes: 7 additions & 10 deletions src/shelter/types/search.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@ export type GeolocationFilter = z.infer<typeof GeolocationFilterSchema>;

export const ShelterSearchPropsSchema = z.object({
search: z.string().optional(),
priority: z.preprocess(
(value) =>
typeof value === 'string'
? value
.split(',')
.map((v) => Number(v))
.filter((v) => !isNaN(v))
: [],
z.array(z.nativeEnum(SupplyPriority)).optional(),
),
priorities: z
.array(z.string())
.optional()
.transform((values) =>
values ? values.map(parseInt).filter((v) => !isNaN(v)) : [],
)
.pipe(z.array(z.nativeEnum(SupplyPriority))),
supplyCategoryIds: z.array(z.string()).optional(),
supplyIds: z.array(z.string()).optional(),
shelterStatus: z.array(ShelterStatusSchema).optional(),
Expand Down

0 comments on commit 55a1a9a

Please sign in to comment.