feat(editor): ✨ Team workspaces
This commit is contained in:
42
apps/builder/pages/api/workspaces/[workspaceId]/members.ts
Normal file
42
apps/builder/pages/api/workspaces/[workspaceId]/members.ts
Normal file
@ -0,0 +1,42 @@
|
||||
import { withSentry } from '@sentry/nextjs'
|
||||
import prisma from 'libs/prisma'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { getAuthenticatedUser } from 'services/api/utils'
|
||||
import { methodNotAllowed, notAuthenticated, notFound } from 'utils'
|
||||
|
||||
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
const user = await getAuthenticatedUser(req)
|
||||
if (!user) return notAuthenticated(res)
|
||||
if (req.method === 'GET') {
|
||||
const id = req.query.workspaceId as string
|
||||
const workspace = await prisma.workspace.findFirst({
|
||||
where: {
|
||||
id,
|
||||
members: { some: { userId: user.id } },
|
||||
},
|
||||
include: {
|
||||
members: {
|
||||
include: {
|
||||
user: true,
|
||||
},
|
||||
},
|
||||
invitations: true,
|
||||
},
|
||||
})
|
||||
if (!workspace) return notFound(res)
|
||||
return res.send({
|
||||
members: workspace.members.map((member) => ({
|
||||
userId: member.userId,
|
||||
role: member.role,
|
||||
workspaceId: member.workspaceId,
|
||||
email: member.user.email,
|
||||
image: member.user.image,
|
||||
name: member.user.name,
|
||||
})),
|
||||
invitations: workspace.invitations,
|
||||
})
|
||||
}
|
||||
methodNotAllowed(res)
|
||||
}
|
||||
|
||||
export default withSentry(handler)
|
Reference in New Issue
Block a user