feat(db): 🗃️ Remove duplicate fields in PublicTypebot

This commit is contained in:
Baptiste Arnaud
2022-06-04 11:05:46 +02:00
parent 8ec117aee4
commit ad32ae02ef
11 changed files with 29 additions and 47 deletions

View File

@@ -9,7 +9,7 @@ import { createResult, updateResult } from '../services/result'
import { ErrorPage } from './ErrorPage'
export type TypebotPageProps = {
typebot?: PublicTypebot
typebot?: PublicTypebot & { typebot: { name: string } }
url: string
isIE: boolean
customHeadCode: string | null
@@ -97,7 +97,7 @@ export const TypebotPage = ({
<div style={{ height: '100vh' }}>
<SEO
url={url}
typebotName={typebot.name}
typebotName={typebot.typebot.name}
metadata={typebot.settings.metadata}
/>
{showTypebot && (

View File

@@ -62,8 +62,9 @@ export const getServerSideProps: GetServerSideProps = async (
const getTypebotFromPublicId = async (publicId?: string) => {
if (!publicId) return null
const typebot = await prisma.publicTypebot.findUnique({
where: { publicId },
const typebot = await prisma.publicTypebot.findFirst({
where: { typebot: { publicId } },
include: { typebot: { select: { name: true } } },
})
if (isNotDefined(typebot)) return null
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')
@@ -71,7 +72,8 @@ const getTypebotFromPublicId = async (publicId?: string) => {
const getTypebotFromCustomDomain = async (customDomain: string) => {
const typebot = await prisma.publicTypebot.findFirst({
where: { customDomain },
where: { typebot: { customDomain } },
include: { typebot: { select: { name: true } } },
})
if (isNotDefined(typebot)) return null
return omit(typebot as unknown as PublicTypebot, 'createdAt', 'updatedAt')

View File

@@ -92,15 +92,12 @@ const parseTypebotToPublicTypebot = (
typebot: Typebot
): PublicTypebot => ({
id,
name: typebot.name,
blocks: typebot.blocks,
typebotId: typebot.id,
theme: typebot.theme,
settings: typebot.settings,
publicId: typebot.publicId,
variables: typebot.variables,
edges: typebot.edges,
customDomain: null,
createdAt: typebot.createdAt,
updatedAt: typebot.updatedAt,
})