Pass userId as a single value or an array
parent
77b89fda05
commit
372e188228
|
@ -32,7 +32,13 @@ async function createOrlistAllSchedules(
|
||||||
* description: No schedules were found
|
* description: No schedules were found
|
||||||
*/
|
*/
|
||||||
const data = await prisma.schedule.findMany({
|
const data = await prisma.schedule.findMany({
|
||||||
where: { userId: body.userId && isAdmin ? body.userId : userId },
|
// where: { userId: body.userId && isAdmin ? body.userId : userId },
|
||||||
|
where: {
|
||||||
|
...(Array.isArray(body.userId)
|
||||||
|
? { userId: { in: body.userId } }
|
||||||
|
: { userId: body.userId || userId }),
|
||||||
|
},
|
||||||
|
...(Array.isArray(body.userId) && { orderBy: { userId: "asc" } }),
|
||||||
});
|
});
|
||||||
const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule));
|
const schedules = data.map((schedule) => schemaSchedulePublic.parse(schedule));
|
||||||
if (schedules) res.status(200).json({ schedules });
|
if (schedules) res.status(200).json({ schedules });
|
||||||
|
|
Loading…
Reference in New Issue