2022-02-14 10:57:57 +01:00
|
|
|
import { withSentry } from '@sentry/nextjs'
|
2021-12-27 15:59:32 +01:00
|
|
|
import prisma from 'libs/prisma'
|
|
|
|
import { NextApiRequest, NextApiResponse } from 'next'
|
2022-03-04 17:21:01 +01:00
|
|
|
import { getAuthenticatedUser } from 'services/api/utils'
|
2022-09-18 09:46:42 +02:00
|
|
|
import { methodNotAllowed, notAuthenticated } from 'utils/api'
|
2021-12-27 15:59:32 +01:00
|
|
|
|
|
|
|
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
2022-03-04 17:21:01 +01:00
|
|
|
const user = await getAuthenticatedUser(req)
|
|
|
|
if (!user) return notAuthenticated(res)
|
2021-12-27 15:59:32 +01:00
|
|
|
|
2022-08-08 08:21:36 +02:00
|
|
|
const id = req.query.userId as string
|
2021-12-27 15:59:32 +01:00
|
|
|
if (req.method === 'PUT') {
|
2022-02-22 10:16:35 +01:00
|
|
|
const data = typeof req.body === 'string' ? JSON.parse(req.body) : req.body
|
2021-12-27 15:59:32 +01:00
|
|
|
const typebots = await prisma.user.update({
|
|
|
|
where: { id },
|
|
|
|
data,
|
|
|
|
})
|
|
|
|
return res.send({ typebots })
|
|
|
|
}
|
|
|
|
return methodNotAllowed(res)
|
|
|
|
}
|
|
|
|
|
2022-02-14 10:57:57 +01:00
|
|
|
export default withSentry(handler)
|