🛂 Add god rule to view typebots
This commit is contained in:
@@ -5,6 +5,8 @@ import { NextApiRequest, NextApiResponse } from 'next'
|
|||||||
import { getSession } from 'next-auth/react'
|
import { getSession } from 'next-auth/react'
|
||||||
import { methodNotAllowed } from 'utils'
|
import { methodNotAllowed } from 'utils'
|
||||||
|
|
||||||
|
const adminEmail = 'contact@baptiste-arnaud.fr'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const session = await getSession({ req })
|
const session = await getSession({ req })
|
||||||
|
|
||||||
@@ -14,8 +16,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
const typebotId = req.query.typebotId.toString()
|
const typebotId = req.query.typebotId.toString()
|
||||||
const user = session.user as User
|
const user = session.user as User
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
const typebot = await prisma.typebot.findUnique({
|
const typebot = await prisma.typebot.findFirst({
|
||||||
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
|
where: {
|
||||||
|
id: typebotId,
|
||||||
|
ownerId: user.email === adminEmail ? undefined : user.id,
|
||||||
|
},
|
||||||
include: {
|
include: {
|
||||||
publishedTypebot: true,
|
publishedTypebot: true,
|
||||||
},
|
},
|
||||||
@@ -26,7 +31,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
}
|
}
|
||||||
if (req.method === 'DELETE') {
|
if (req.method === 'DELETE') {
|
||||||
const typebots = await prisma.typebot.delete({
|
const typebots = await prisma.typebot.delete({
|
||||||
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
|
where: {
|
||||||
|
id_ownerId: {
|
||||||
|
id: typebotId,
|
||||||
|
ownerId: user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
return res.send({ typebots })
|
return res.send({ typebots })
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { getSession } from 'next-auth/react'
|
|||||||
import { isFreePlan } from 'services/user'
|
import { isFreePlan } from 'services/user'
|
||||||
import { methodNotAllowed } from 'utils'
|
import { methodNotAllowed } from 'utils'
|
||||||
|
|
||||||
|
const adminEmail = 'contact@baptiste-arnaud.fr'
|
||||||
|
|
||||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
const session = await getSession({ req })
|
const session = await getSession({ req })
|
||||||
|
|
||||||
@@ -27,7 +29,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
: undefined,
|
: undefined,
|
||||||
where: {
|
where: {
|
||||||
typebotId,
|
typebotId,
|
||||||
typebot: { ownerId: user.id },
|
typebot: { ownerId: user.email === adminEmail ? undefined : user.id },
|
||||||
answers: { some: {} },
|
answers: { some: {} },
|
||||||
isCompleted: isFreePlan(user) ? false : undefined,
|
isCompleted: isFreePlan(user) ? false : undefined,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user