(
socket: WebSocket,
req: FastifyRequest<{
Params: {
organizationId: string;
};
}>
)
| 141 | } |
| 142 | |
| 143 | export async function wsOrganizationEvents( |
| 144 | socket: WebSocket, |
| 145 | req: FastifyRequest<{ |
| 146 | Params: { |
| 147 | organizationId: string; |
| 148 | }; |
| 149 | }> |
| 150 | ) { |
| 151 | guardSocket(socket, req); |
| 152 | const { params } = req; |
| 153 | const userId = req.session?.userId; |
| 154 | |
| 155 | if (!userId) { |
| 156 | socket.send('No active session'); |
| 157 | socket.close(); |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | const access = await getOrganizationAccess({ |
| 162 | userId, |
| 163 | organizationId: params.organizationId, |
| 164 | }); |
| 165 | |
| 166 | if (!access) { |
| 167 | socket.send('No access'); |
| 168 | socket.close(); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | const unsubscribe = subscribeToPublishedEvent( |
| 173 | 'organization', |
| 174 | 'subscription_updated', |
| 175 | (message) => { |
| 176 | socket.send(setSuperJson(message)); |
| 177 | } |
| 178 | ); |
| 179 | |
| 180 | socket.on('close', () => unsubscribe()); |
| 181 | } |
nothing calls this directly
no test coverage detected