import { User, UserGetPayload } from 'nexus-plugin-prisma/client' import { prismaClient as prisma } from '../../prismaClient' type UserWithRelations = UserGetPayload<{ include: { currentProject: true projects: true } }> prisma.user .findMany({ where: { role: 'RESIDENT', currentProject: null, }, include: { currentProject: true, projects: true }, }) .then(async (users: UserWithRelations[]) => { for await (const user of users) { if (!user.currentProject && user.projects.length) { await prisma.user.update({ where: { id: user.id, }, data: { currentProject: { connect: { id: user.projects[0].id, }, }, }, }) console.log('Resident updated', user.email) } } }) .catch(console.error)