Filter multiple value with getServerSideProps from query result

435 Views Asked by At

How to have filtered multiple results in a getServerSideProps. I send all my results the query parameter:

const filtersUsers = (changedValues, allValues) => {
    router.push({
        query : { ...allValues },
    })
}

In my URL I get this result when I start to filter: http://127.0.0.1:8082/users?lastname=lastnameFilter&firstname=firstnameFilter&email=&city=&zipcode=

export async function getServerSideProps(context) {
const res = await fetch(`http://my-project-api:8081/api/users/`)
console.log(res)
const users = await res.json()

if (!users) {
  return {
    notFound: true,
  }
}

return {
  props: {users},
}

}

How can I apply the query only to items that have a filled in field and update my url with those filled out fields, and how to use the context.query so that it automatically knows which field to look for in my table?

I have create an API factory and I can do that.

await api.getUsers(params)

Result: Request URL: http://127.0.0.1:8081/api/users/?lastname=lastnameTest&firstname=firstnameTest

And in param I have all fields for filters. I search how I can do this with getServerSideProps

0

There are 0 best solutions below