({ chatId, name }: { chatId: string, name: string })
| 94 | ); |
| 95 | |
| 96 | export const updateChatName = async ({ chatId, name }: { chatId: string, name: string }) => sew(() => |
| 97 | withOptionalAuth(async ({ org, user, prisma }) => { |
| 98 | const chat = await prisma.chat.findUnique({ |
| 99 | where: { |
| 100 | id: chatId, |
| 101 | orgId: org.id, |
| 102 | }, |
| 103 | }); |
| 104 | |
| 105 | if (!chat) { |
| 106 | return notFound(); |
| 107 | } |
| 108 | |
| 109 | const isOwner = await isOwnerOfChat(chat, user); |
| 110 | |
| 111 | // Only the owner can rename chats |
| 112 | if (!isOwner) { |
| 113 | return notFound(); |
| 114 | } |
| 115 | |
| 116 | await prisma.chat.update({ |
| 117 | where: { |
| 118 | id: chatId, |
| 119 | orgId: org.id, |
| 120 | }, |
| 121 | data: { |
| 122 | name, |
| 123 | }, |
| 124 | }); |
| 125 | |
| 126 | return { |
| 127 | success: true, |
| 128 | } |
| 129 | }) |
| 130 | ); |
| 131 | |
| 132 | export const updateChatVisibility = async ({ chatId, visibility }: { chatId: string, visibility: ChatVisibility }) => sew(() => |
| 133 | withAuth(async ({ org, user, prisma }) => { |
no test coverage detected