♻️ (builder) Change to features-centric folder structure

This commit is contained in:
Baptiste Arnaud
2022-11-15 09:35:48 +01:00
committed by Baptiste Arnaud
parent 3686465a85
commit 643571fe7d
683 changed files with 3907 additions and 3643 deletions

View File

@@ -0,0 +1,44 @@
import { withSentry } from '@sentry/nextjs'
import { DashboardFolder } from 'db'
import prisma from '@/lib/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from '@/features/auth'
import { methodNotAllowed, notAuthenticated } from 'utils/api'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)
const id = req.query.id as string
if (req.method === 'GET') {
const folder = await prisma.dashboardFolder.findFirst({
where: {
id,
workspace: { members: { some: { userId: user.id } } },
},
})
return res.send({ folder })
}
if (req.method === 'DELETE') {
const folders = await prisma.dashboardFolder.deleteMany({
where: { id, workspace: { members: { some: { userId: user.id } } } },
})
return res.send({ folders })
}
if (req.method === 'PATCH') {
const data = (
typeof req.body === 'string' ? JSON.parse(req.body) : req.body
) as Partial<DashboardFolder>
const folders = await prisma.dashboardFolder.updateMany({
where: {
id,
workspace: { members: { some: { userId: user.id } } },
},
data,
})
return res.send({ typebots: folders })
}
return methodNotAllowed(res)
}
export default withSentry(handler)