fix: 🚑️ Webhook and instant updates
This commit is contained in:
@ -12,7 +12,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.status(401).json({ message: 'Not authenticated' })
|
||||
|
||||
const user = session.user as User
|
||||
const { code } = JSON.parse(req.body)
|
||||
const { code } =
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const coupon = await prisma.coupon.findFirst({
|
||||
where: { code, dateRedeemed: null },
|
||||
})
|
||||
|
@ -26,7 +26,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ folders })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Pick<DashboardFolder, 'parentFolderId'>
|
||||
const data = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as Pick<DashboardFolder, 'parentFolderId'>
|
||||
const folder = await prisma.dashboardFolder.create({
|
||||
data: { ...data, ownerId: user.id, name: 'New folder' },
|
||||
})
|
||||
|
@ -26,7 +26,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ folders })
|
||||
}
|
||||
if (req.method === 'PATCH') {
|
||||
const data = JSON.parse(req.body) as Partial<DashboardFolder>
|
||||
const data = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as Partial<DashboardFolder>
|
||||
const folders = await prisma.dashboardFolder.update({
|
||||
where: { id_ownerId: { id, ownerId: user.id } },
|
||||
data,
|
||||
|
@ -5,8 +5,9 @@ import { createTransport } from 'nodemailer'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
if (req.method === 'POST') {
|
||||
const { from, port, isTlsEnabled, username, password, host, to } =
|
||||
JSON.parse(req.body) as SmtpCredentialsData & { to: string }
|
||||
const { from, port, isTlsEnabled, username, password, host, to } = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as SmtpCredentialsData & { to: string }
|
||||
const transporter = createTransport({
|
||||
host,
|
||||
port,
|
||||
|
@ -12,7 +12,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
try {
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data =
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebot = await prisma.publicTypebot.create({
|
||||
data: { ...data },
|
||||
})
|
||||
|
@ -12,7 +12,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
const id = req.query.id.toString()
|
||||
if (req.method === 'PUT') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebots = await prisma.publicTypebot.update({
|
||||
where: { id },
|
||||
data,
|
||||
|
@ -10,7 +10,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
|
||||
apiVersion: '2020-08-27',
|
||||
})
|
||||
const { email, currency } = JSON.parse(req.body)
|
||||
const { email, currency } =
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
success_url: `${req.headers.origin}/typebots?stripe=success`,
|
||||
cancel_url: `${req.headers.origin}/typebots?stripe=cancel`,
|
||||
|
@ -26,7 +26,8 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data =
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebot = await prisma.typebot.create({
|
||||
data:
|
||||
'blocks' in data
|
||||
|
@ -41,7 +41,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'PUT') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebots = await prisma.typebot.update({
|
||||
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
|
||||
data: {
|
||||
@ -53,7 +53,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ typebots })
|
||||
}
|
||||
if (req.method === 'PATCH') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebots = await prisma.typebot.update({
|
||||
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
|
||||
data,
|
||||
|
@ -12,7 +12,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
|
||||
const id = req.query.id.toString()
|
||||
if (req.method === 'PUT') {
|
||||
const data = JSON.parse(req.body)
|
||||
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
const typebots = await prisma.user.update({
|
||||
where: { id },
|
||||
data,
|
||||
|
@ -23,7 +23,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ credentials })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Omit<Credentials, 'ownerId'>
|
||||
const data = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as Omit<Credentials, 'ownerId'>
|
||||
const { encryptedData, iv } = encrypt(data.data)
|
||||
const credentials = await prisma.credentials.create({
|
||||
data: {
|
||||
|
@ -22,7 +22,9 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
return res.send({ customDomains })
|
||||
}
|
||||
if (req.method === 'POST') {
|
||||
const data = JSON.parse(req.body) as Omit<CustomDomain, 'ownerId'>
|
||||
const data = (
|
||||
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
||||
) as Omit<CustomDomain, 'ownerId'>
|
||||
try {
|
||||
await createDomainOnVercel(data.name)
|
||||
} catch (err) {
|
||||
|
Reference in New Issue
Block a user