({ chatId }: { chatId: string })
| 63 | ); |
| 64 | |
| 65 | export const getChatInfo = async ({ chatId }: { chatId: string }) => sew(() => |
| 66 | withOptionalAuth(async ({ org, user, prisma }) => { |
| 67 | const chat = await prisma.chat.findUnique({ |
| 68 | where: { |
| 69 | id: chatId, |
| 70 | orgId: org.id, |
| 71 | }, |
| 72 | }); |
| 73 | |
| 74 | if (!chat) { |
| 75 | return notFound(); |
| 76 | } |
| 77 | |
| 78 | const isOwner = await isOwnerOfChat(chat, user); |
| 79 | const isSharedWithUser = await isChatSharedWithUser({ prisma, chatId, userId: user?.id }); |
| 80 | |
| 81 | // Private chats can only be viewed by the owner or users it's been shared with |
| 82 | if (chat.visibility === ChatVisibility.PRIVATE && !isOwner && !isSharedWithUser) { |
| 83 | return notFound(); |
| 84 | } |
| 85 | |
| 86 | return { |
| 87 | messages: chat.messages as unknown as SBChatMessage[], |
| 88 | visibility: chat.visibility, |
| 89 | name: chat.name, |
| 90 | isOwner, |
| 91 | isSharedWithUser, |
| 92 | }; |
| 93 | }) |
| 94 | ); |
| 95 | |
| 96 | export const updateChatName = async ({ chatId, name }: { chatId: string, name: string }) => sew(() => |
| 97 | withOptionalAuth(async ({ org, user, prisma }) => { |
no test coverage detected