If you want to utilize filters in Prisma, it can be done as shown below:
prisma.user.findMany({
where: {
name: { contains: 'jeff' },
city: {
name: { contains: 'hol' },
state: {
acr: {
equals: 'vegas'
}
}
}
}
})
To create the necessary object structure:
{
name: '',
city: {
name: '',
state: {
acr: ''
}
}
}
The desired type output is:
type UserFilters = {
name_contains?: string,
name_equals?: string,
city_name_contains?: string
city_name_equals?: string
city_state_acr_contains?: string
city_state_acr_equals?: string
}
The code snippet that accomplishes this is:
type FilterR<Form> = Form extends object
? Partial<{
[Key in string & keyof Form as `${Key}_${'contains' | 'equals'}`]: FilterR<Form[Key]>
}>
: Form
This results in the following structure:
Partial<{
name_contains: "";
name_equals: "";
city_contains: Partial<{
name_contains: "";
name_equals: "";
state_contains: Partial<{
acr_contains: "";
acr_equals: "";
}>;
state_equals: Partial<{
acr_contains: "";
acr_equals: "";
}>;
}>;
city_equals: Partial<...>;
}>