2
0

🛂 Add god rule to view typebots

This commit is contained in:
Baptiste Arnaud
2022-02-20 08:54:48 +01:00
parent 7a4b96ff7e
commit 5d9356bd9c
2 changed files with 16 additions and 4 deletions

View File

@ -5,6 +5,8 @@ import { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react'
import { methodNotAllowed } from 'utils'
const adminEmail = 'contact@baptiste-arnaud.fr'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getSession({ req })
@ -14,8 +16,11 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const typebotId = req.query.typebotId.toString()
const user = session.user as User
if (req.method === 'GET') {
const typebot = await prisma.typebot.findUnique({
where: { id_ownerId: { id: typebotId, ownerId: user.id } },
const typebot = await prisma.typebot.findFirst({
where: {
id: typebotId,
ownerId: user.email === adminEmail ? undefined : user.id,
},
include: {
publishedTypebot: true,
},
@ -26,7 +31,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
}
if (req.method === '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 })
}

View File

@ -6,6 +6,8 @@ import { getSession } from 'next-auth/react'
import { isFreePlan } from 'services/user'
import { methodNotAllowed } from 'utils'
const adminEmail = 'contact@baptiste-arnaud.fr'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getSession({ req })
@ -27,7 +29,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
: undefined,
where: {
typebotId,
typebot: { ownerId: user.id },
typebot: { ownerId: user.email === adminEmail ? undefined : user.id },
answers: { some: {} },
isCompleted: isFreePlan(user) ? false : undefined,
},