mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make empty array to return all the records when using `in`

drac94 opened this issue · comments

Right now when passing an empty array when using in does not return anything, is there a way to make it return everything instead? this will help to use dynamic properties

Or maybe there is another way of doing it, sorry if thats the case

const idParam = req.url.searchParams.getAll('id');

db.employee.findMany({
  where: { id: { in: idParam } },
  take: size,
  skip: (page - 1) * size,
}),

Above code returns empty if idParam is null, undefined or an empty array []

Right now I'm doing this instead

const idParam = req.url.searchParams.getAll('id');

if(idParam.length > 0){
  db.employee.findMany({
    where: { id: { in: idParam } },
    take: size,
    skip: (page - 1) * size,
  }),
} else {
  db.employee.findMany({
    take: size,
    skip: (page - 1) * size,
  }),
}

Thanks!