🛂 (billing) Enable Published bot branding when plan cancelled
This commit is contained in:
@@ -7,7 +7,7 @@ import prisma from '@/lib/prisma'
|
|||||||
import { Plan } from '@typebot.io/prisma'
|
import { Plan } from '@typebot.io/prisma'
|
||||||
import { RequestHandler } from 'next/dist/server/next'
|
import { RequestHandler } from 'next/dist/server/next'
|
||||||
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
import { sendTelemetryEvents } from '@typebot.io/lib/telemetry/sendTelemetryEvent'
|
||||||
import { Typebot } from '@typebot.io/schemas'
|
import { PublicTypebot, Typebot } from '@typebot.io/schemas'
|
||||||
|
|
||||||
if (!process.env.STRIPE_SECRET_KEY || !process.env.STRIPE_WEBHOOK_SECRET)
|
if (!process.env.STRIPE_SECRET_KEY || !process.env.STRIPE_WEBHOOK_SECRET)
|
||||||
throw new Error('STRIPE_SECRET_KEY or STRIPE_WEBHOOK_SECRET missing')
|
throw new Error('STRIPE_SECRET_KEY or STRIPE_WEBHOOK_SECRET missing')
|
||||||
@@ -145,7 +145,8 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
isArchived: { not: true },
|
isArchived: { not: true },
|
||||||
},
|
},
|
||||||
})) as Typebot[]
|
include: { publishedTypebot: true },
|
||||||
|
})) as (Typebot & { publishedTypebot: PublicTypebot })[]
|
||||||
for (const typebot of typebots) {
|
for (const typebot of typebots) {
|
||||||
if (typebot.settings.general.isBrandingEnabled) continue
|
if (typebot.settings.general.isBrandingEnabled) continue
|
||||||
await prisma.typebot.updateMany({
|
await prisma.typebot.updateMany({
|
||||||
@@ -160,6 +161,20 @@ const webhookHandler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if (typebot.publishedTypebot.settings.general.isBrandingEnabled)
|
||||||
|
continue
|
||||||
|
await prisma.publicTypebot.updateMany({
|
||||||
|
where: { id: typebot.id },
|
||||||
|
data: {
|
||||||
|
settings: {
|
||||||
|
...typebot.publishedTypebot.settings,
|
||||||
|
general: {
|
||||||
|
...typebot.publishedTypebot.settings.general,
|
||||||
|
isBrandingEnabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return res.send({ message: 'workspace downgraded in DB' })
|
return res.send({ message: 'workspace downgraded in DB' })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user