2
0

feat(editor): Team workspaces

This commit is contained in:
Baptiste Arnaud
2022-05-13 15:22:44 -07:00
parent 6c2986590b
commit f0fdf08b00
132 changed files with 3354 additions and 1228 deletions

View File

@ -0,0 +1,39 @@
import { withSentry } from '@sentry/nextjs'
import { WorkspaceInvitation, WorkspaceRole } from 'db'
import prisma from 'libs/prisma'
import { NextApiRequest, NextApiResponse } from 'next'
import { getAuthenticatedUser } from 'services/api/utils'
import { methodNotAllowed, notAuthenticated } from 'utils'
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const user = await getAuthenticatedUser(req)
if (!user) return notAuthenticated(res)
if (req.method === 'PATCH') {
const data = req.body as Omit<WorkspaceInvitation, 'createdAt'>
const invitation = await prisma.workspaceInvitation.updateMany({
where: {
id: data.id,
workspace: {
members: { some: { userId: user.id, role: WorkspaceRole.ADMIN } },
},
},
data,
})
return res.send({ invitation })
}
if (req.method === 'DELETE') {
const id = req.query.id as string
await prisma.workspaceInvitation.deleteMany({
where: {
id,
workspace: {
members: { some: { userId: user.id, role: WorkspaceRole.ADMIN } },
},
},
})
return res.send({ message: 'success' })
}
methodNotAllowed(res)
}
export default withSentry(handler)