import { ManagingCompany, Project } from 'nexus-plugin-prisma/client' import * as SendBirdController from '../../controllers/sendbird' import { prismaClient as prisma } from '../../prismaClient' /** * This script is making sure that for every group conversation we also have the private * conversation created */ prisma.managingCompany .findMany({ where: { id: { equals: 'ck2ky8qyx01kj0866hsywksgr' } } }) .then(async (managingCompanies: ManagingCompany[]) => { for await (const managingCompany of managingCompanies) { console.log(`Start processing ${managingCompany.shortName}`) const managignCompanyProjects: Project[] = await prisma.managingCompany .findOne({ where: { id: managingCompany.id } }) .projects() for await (const project of managignCompanyProjects) { // All channels of project const channels = await SendBirdController.getChannelsForUserId({ all: true, userId: managingCompany.id, show_member: true, name_startswith: project.id, }) console.log(`Processing ${channels.length} channels for project ${project.id}`) for await (const channel of channels) { const privateChannel = await SendBirdController.getChannelByName({ name: `${channel.name}-private`, }) // Create if not exists if (!privateChannel) { console.log('Creating missing private channel') const [projectId, propertyId] = channel.name.split('-') await SendBirdController.createOrGetManagerChannel({ projectId, propertyId, }) } } } console.log(`Done processing ${managingCompany.shortName}`) } })