import { ManagingCompany } from 'nexus-plugin-prisma/client' import * as SendBirdController from '../../controllers/sendbird' import { prismaClient as prisma } from '../../prismaClient' /** * Just making sure residents are in their right property channel * IT's a protection so that we don't get complaints that some resident are in * property group chat that they aren't supposed to be in. Normally this should * never happen, but we might have forgot some use case */ prisma.managingCompany.findMany().then(async (managingCompanies: ManagingCompany[]) => { for await (const managingCompany of managingCompanies) { console.log(`Start processing ${managingCompany.shortName}`) const channels = await SendBirdController.getChannelsForUserId({ all: true, userId: managingCompany.id, show_member: true, }) const v2Channels = channels.filter((channel) => !channel.name.startsWith('chat')) console.log('v2Channels.length', v2Channels.length) for await (const channel of v2Channels) { const [projectId, propertyId] = channel.name.split('-') await SendBirdController.putGoodResidentsInPropertyChannel({ propertyId, projectId }) } console.log(`Done processing ${managingCompany.shortName}`) } })