( context: GetServerSidePropsContext, isSubDomainRouting: boolean )
| 203 | } |
| 204 | |
| 205 | export async function getChannelsSettingsServerSideProps( |
| 206 | context: GetServerSidePropsContext, |
| 207 | isSubDomainRouting: boolean |
| 208 | ) { |
| 209 | const { props, notFound, ...rest } = await ssr(context, allowManagers); |
| 210 | |
| 211 | if (rest.redirect) { |
| 212 | return RedirectTo(rest.location); |
| 213 | } |
| 214 | |
| 215 | if (notFound || !props) { |
| 216 | return NotFound(); |
| 217 | } |
| 218 | |
| 219 | const channels = await prisma.channels.findMany({ |
| 220 | where: { |
| 221 | accountId: props.currentCommunity.id, |
| 222 | type: { |
| 223 | in: [ChannelType.PUBLIC, ChannelType.PRIVATE], |
| 224 | }, |
| 225 | }, |
| 226 | include: { |
| 227 | _count: { select: { threads: true, memberships: true } }, |
| 228 | }, |
| 229 | }); |
| 230 | |
| 231 | const counts = channels.map((channel) => { |
| 232 | return { |
| 233 | channelId: channel.id, |
| 234 | threadsCount: channel._count.threads, |
| 235 | usersCount: channel._count.memberships, |
| 236 | }; |
| 237 | }); |
| 238 | |
| 239 | return { |
| 240 | props: { |
| 241 | ...props, |
| 242 | channels: channels.map(serializeChannel).sort(sortByDisplayOrder), |
| 243 | isSubDomainRouting, |
| 244 | counts, |
| 245 | }, |
| 246 | }; |
| 247 | } |
no test coverage detected