migrate to app dir and ssr

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-01-20 22:54:38 +01:00
parent 719a82f1c4
commit 308ae98472
194 changed files with 4706 additions and 2194 deletions

View File

@@ -2,29 +2,37 @@ import { createTRPCRouter, protectedProcedure } from '@/server/api/trpc';
import { db } from '@/server/db';
import { z } from 'zod';
import type { Event, Profile } from '@mixan/db';
function transformEvent(
event: Event & {
profile: Profile;
}
) {
return {
...event,
properties: event.properties as Record<string, unknown>,
};
}
export const eventRouter = createTRPCRouter({
list: protectedProcedure
.input(
z.object({
projectSlug: z.string(),
projectId: z.string(),
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, events } }) => {
const project = await db.project.findUniqueOrThrow({
where: {
slug: projectSlug,
},
});
return db.event.findMany({
.query(async ({ input: { take, skip, projectId, profileId, events } }) => {
return db.event
.findMany({
take,
skip,
where: {
project_id: project.id,
project_id: projectId,
profile_id: profileId,
...(events && events.length > 0
? {
@@ -40,7 +48,7 @@ export const eventRouter = createTRPCRouter({
include: {
profile: true,
},
});
}
),
})
.then((events) => events.map(transformEvent));
}),
});