2023-09-20 15:26:52 +02:00
|
|
|
import prisma from '@typebot.io/lib/prisma'
|
2023-08-24 07:48:30 +02:00
|
|
|
import { ChatSession, sessionStateSchema } from '@typebot.io/schemas'
|
2022-11-29 10:02:40 +01:00
|
|
|
|
|
|
|
|
export const getSession = async (
|
|
|
|
|
sessionId: string
|
|
|
|
|
): Promise<Pick<ChatSession, 'state' | 'id'> | null> => {
|
2023-08-24 07:48:30 +02:00
|
|
|
const session = await prisma.chatSession.findUnique({
|
2022-11-29 10:02:40 +01:00
|
|
|
where: { id: sessionId },
|
|
|
|
|
select: { id: true, state: true },
|
2023-08-24 07:48:30 +02:00
|
|
|
})
|
|
|
|
|
if (!session) return null
|
|
|
|
|
return { ...session, state: sessionStateSchema.parse(session.state) }
|
2022-11-29 10:02:40 +01:00
|
|
|
}
|