2023-09-20 15:26:52 +02:00
|
|
|
import prisma from '@typebot.io/lib/prisma'
|
2023-07-18 14:31:20 +02:00
|
|
|
import { formatLogDetails } from './helpers/formatLogDetails'
|
2022-11-15 10:28:03 +01:00
|
|
|
|
2023-06-15 14:42:20 +02:00
|
|
|
type Props = {
|
|
|
|
status: 'error' | 'success' | 'info'
|
|
|
|
resultId: string | undefined
|
|
|
|
message: string
|
2022-11-15 10:28:03 +01:00
|
|
|
details?: unknown
|
2023-06-15 14:42:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const saveLog = ({ status, resultId, message, details }: Props) => {
|
2022-11-15 10:28:03 +01:00
|
|
|
if (!resultId || resultId === 'undefined') return
|
|
|
|
return prisma.log.create({
|
|
|
|
data: {
|
|
|
|
resultId,
|
|
|
|
status,
|
|
|
|
description: message,
|
2023-07-18 14:31:20 +02:00
|
|
|
details: formatLogDetails(details) as string | null,
|
2022-11-15 10:28:03 +01:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|