Skip to content

Commit adcb6cb

Browse files
authored
feat: add multi option for priority queryParam (#150)
Tenta resolver a issue #145
1 parent 38da306 commit adcb6cb

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

src/shelter/ShelterSearch.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ class ShelterSearch {
3131
}
3232

3333
priority(supplyIds: string[] = []): Prisma.ShelterWhereInput {
34-
if (!this.formProps.priority) return {};
34+
if (!this.formProps.priority?.length) return {};
3535

3636
return {
3737
shelterSupplies: {
3838
some: {
39-
priority: +this.formProps.priority,
39+
priority: {
40+
in: this.formProps.priority,
41+
},
4042
supplyId:
4143
supplyIds.length > 0
4244
? {
@@ -71,13 +73,31 @@ class ShelterSearch {
7173
}
7274

7375
supplyCategoryIds(
74-
priority?: SupplyPriority | null,
76+
priority?: SupplyPriority[] | null,
7577
): Prisma.ShelterWhereInput {
7678
if (!this.formProps.supplyCategoryIds) return {};
79+
80+
if (!priority || !priority.length) {
81+
return {
82+
shelterSupplies: {
83+
some: {
84+
priority: undefined,
85+
supply: {
86+
supplyCategoryId: {
87+
in: this.formProps.supplyCategoryIds,
88+
},
89+
},
90+
},
91+
},
92+
};
93+
}
94+
7795
return {
7896
shelterSupplies: {
7997
some: {
80-
priority: priority ? +priority : undefined,
98+
priority: {
99+
in: priority,
100+
},
81101
supply: {
82102
supplyCategoryId: {
83103
in: this.formProps.supplyCategoryIds,

src/shelter/types/search.types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,14 @@ export type GeolocationFilter = z.infer<typeof GeolocationFilterSchema>;
3232
export const ShelterSearchPropsSchema = z.object({
3333
search: z.string().optional(),
3434
priority: z.preprocess(
35-
(value) => Number(value) || undefined,
36-
z.nativeEnum(SupplyPriority).optional(),
35+
(value) =>
36+
typeof value === 'string'
37+
? value
38+
.split(',')
39+
.map((v) => Number(v))
40+
.filter((v) => !isNaN(v))
41+
: [],
42+
z.array(z.nativeEnum(SupplyPriority)).optional(),
3743
),
3844
supplyCategoryIds: z.array(z.string()).optional(),
3945
supplyIds: z.array(z.string()).optional(),

0 commit comments

Comments
 (0)