2
0

🔊 Add prisma metrics to prometheus endpoint (#1420)

This commit is contained in:
Baptiste Arnaud
2024-04-06 15:08:57 +02:00
committed by GitHub
parent d96f384e02
commit 6e0388c501
9 changed files with 92 additions and 75 deletions

View File

@@ -1,4 +1,5 @@
import prisma from '@typebot.io/lib/prisma'
import { Prisma } from '@typebot.io/prisma'
import { SessionState } from '@typebot.io/schemas'
type Props = {
@@ -6,7 +7,10 @@ type Props = {
state: SessionState
}
export const createSession = async ({ id, state }: Props) =>
export const createSession = ({
id,
state,
}: Props): Prisma.PrismaPromise<any> =>
prisma.chatSession.create({
data: {
id,

View File

@@ -1,4 +1,5 @@
import prisma from '@typebot.io/lib/prisma'
import { Prisma } from '@typebot.io/prisma'
import { SessionState } from '@typebot.io/schemas'
type Props = {
@@ -6,7 +7,10 @@ type Props = {
state: SessionState
}
export const updateSession = async ({ id, state }: Props) =>
export const updateSession = ({
id,
state,
}: Props): Prisma.PrismaPromise<any> =>
prisma.chatSession.updateMany({
where: { id },
data: {

View File

@@ -1,4 +1,5 @@
import prisma from '@typebot.io/lib/prisma'
import { Prisma } from '@typebot.io/prisma'
import { TypebotInSession } from '@typebot.io/schemas'
import { filterVariablesWithValues } from '@typebot.io/variables/filterVariablesWithValues'
@@ -8,37 +9,27 @@ type Props = {
hasStarted: boolean
isCompleted: boolean
}
export const upsertResult = async ({
export const upsertResult = ({
resultId,
typebot,
hasStarted,
isCompleted,
}: Props) => {
const existingResult = await prisma.result.findUnique({
}: Props): Prisma.PrismaPromise<any> => {
const variablesWithValue = filterVariablesWithValues(typebot.variables)
return prisma.result.upsert({
where: { id: resultId },
update: {
isCompleted: isCompleted ? true : undefined,
hasStarted,
variables: variablesWithValue,
},
create: {
id: resultId,
typebotId: typebot.id,
isCompleted: isCompleted ? true : false,
hasStarted,
variables: variablesWithValue,
},
select: { id: true },
})
const variablesWithValue = filterVariablesWithValues(typebot.variables)
if (existingResult) {
return prisma.result.updateMany({
where: { id: resultId },
data: {
isCompleted: isCompleted ? true : undefined,
hasStarted,
variables: variablesWithValue,
},
})
}
return prisma.result.createMany({
data: [
{
id: resultId,
typebotId: typebot.id,
isCompleted: isCompleted ? true : false,
hasStarted,
variables: variablesWithValue,
},
],
})
}