web: filter events by name (all events and profile events)

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-12-13 11:08:10 +01:00
parent 13d7ad2a8c
commit 0a15a773e2
7 changed files with 93 additions and 45 deletions

View File

@@ -16,27 +16,37 @@ export const eventRouter = createTRPCRouter({
take: z.number().default(100),
skip: z.number().default(0),
profileId: z.string().optional(),
events: z.array(z.string()).optional(),
})
)
.query(async ({ input: { take, skip, projectSlug, profileId } }) => {
const project = await db.project.findUniqueOrThrow({
where: {
slug: projectSlug,
},
});
return db.event.findMany({
take,
skip,
where: {
project_id: project.id,
profile_id: profileId,
},
orderBy: {
createdAt: 'desc',
},
include: {
profile: true,
},
});
}),
.query(
async ({ input: { take, skip, projectSlug, profileId, events } }) => {
const project = await db.project.findUniqueOrThrow({
where: {
slug: projectSlug,
},
});
return db.event.findMany({
take,
skip,
where: {
project_id: project.id,
profile_id: profileId,
...(events && events.length > 0
? {
name: {
in: events,
},
}
: {}),
},
orderBy: {
createdAt: 'desc',
},
include: {
profile: true,
},
});
}
),
});