2
0
Files
bot/apps/builder/pages/api/folders/[id].ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2021-12-08 07:08:13 +01:00
import { DashboardFolder } from 'db'
2021-12-06 15:48:50 +01:00
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getSession } from 'next-auth/react'
import { methodNotAllowed } from 'utils'
2021-12-06 15:48:50 +01:00
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getSession({ req })
if (!session?.user)
return res.status(401).json({ message: 'Not authenticated' })
const id = req.query.id.toString()
if (req.method === 'GET') {
const folder = await prisma.dashboardFolder.findUnique({
where: { id },
})
return res.send({ folder })
}
if (req.method === 'DELETE') {
const folders = await prisma.dashboardFolder.delete({
where: { id },
})
return res.send({ folders })
}
if (req.method === 'PATCH') {
const data = JSON.parse(req.body) as Partial<DashboardFolder>
const folders = await prisma.dashboardFolder.update({
where: { id },
data,
})
return res.send({ typebots: folders })
}
return methodNotAllowed(res)
}
export default handler