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
|
|
|
|
2023-09-22 17:12:15 +02:00
|
|
|
export const getSession = async (sessionId: string) => {
|
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 },
|
2023-09-22 17:12:15 +02:00
|
|
|
select: { id: true, state: true, updatedAt: 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
|
|
|
}
|