Skip to content

Commit

Permalink
🛂 Add god rule to view typebots
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Feb 20, 2022
1 parent 7a4b96f commit 5d9356b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 13 additions & 3 deletions apps/builder/pages/api/typebots/[typebotId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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,
},
Expand All @@ -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 })
}
Expand Down
4 changes: 3 additions & 1 deletion apps/builder/pages/api/typebots/[typebotId]/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand All @@ -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,
},
Expand Down

2 comments on commit 5d9356b

@vercel
Copy link

@vercel vercel bot commented on 5d9356b Feb 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 5d9356b Feb 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-git-main-typebot-io.vercel.app
builder-v2-typebot-io.vercel.app
app.typebot.io

Please sign in to comment.