feat(dashboard): add quick filter for origin

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-05 21:19:38 +02:00
parent ad3132478a
commit 9881f34e53
7 changed files with 124 additions and 80 deletions

View File

@@ -181,4 +181,24 @@ export const eventRouter = createTRPCRouter({
.query(async ({ input }) => {
return getTopPages(input);
}),
origin: protectedProcedure
.input(
z.object({
projectId: z.string(),
})
)
.query(async ({ input }) => {
const res = await chQuery<{ origin: string }>(
`SELECT DISTINCT origin FROM ${TABLE_NAMES.events} WHERE project_id = ${escape(
input.projectId
)} AND origin IS NOT NULL AND origin != '' AND toDate(created_at) > now() - INTERVAL 30 DAY ORDER BY origin ASC`
);
return res.sort((a, b) =>
a.origin
.replace(/https?:\/\//, '')
.localeCompare(b.origin.replace(/https?:\/\//, ''))
);
}),
});