import { ManagingCompanyGetPayload } from 'nexus-plugin-prisma/client' import { prismaClient as prisma } from '../../prismaClient' type ManagingCompanyWithRelations = ManagingCompanyGetPayload<{ include: { projects: { include: { users: { include: { properties: true } } } } } }> /** * Custom script for when we import data from renting building * all residents need to be tenants but the import doesn't handle * that for now */ prisma.managingCompany .findOne({ where: { id: 'ckd7k64uz0qno0713tcjg6z3m' }, include: { projects: { include: { users: { include: { properties: true } } } } }, }) .then(async (managingCompany: ManagingCompanyWithRelations) => { for await (const project of managingCompany.projects) { for await (const user of project.users) { await prisma.user.update({ where: { id: user.id }, data: { projectsTenants: { connect: [{ id: project.id }], }, properties: { disconnect: user.properties.map((property) => ({ id: property.id })), }, }, }) } } console.log('Finish putting users to tenants') })