migrate to app dir and ssr
This commit is contained in:
@@ -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));
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user