import { Prisma } from '@prisma/client' ; import { makeBooleanIterator } from './lib/util' ; import { prisma } from 'src/prisma' ; const setupRoles = async ( adminId , userIds , chapterIds ) : Promise < void > => { const data = [ ] ; const chapterIterator = makeBooleanIterator ( ) ; for ( const chapterId of chapterIds ) { const chapterUserData = { chapter_id : chapterId , user_id : adminId , role_name : 'organizer' , interested : true , } ; data . push ( chapterUserData ) ; const [ banned , ... others ] = userIds ; const banData = { users : { connect : { id : banned } } , chapters : { connect : { id : chapterId } } , } ; await prisma . user_bans . create ( { data : banData } ) ; const interestedIterator = makeBooleanIterator ( chapterIterator . next ( ) . value ) ; for ( const user of others ) { const chapterUserData = { chapter_id : chapterId , user_id : user , role_name : 'member' , interested : interestedIterator . next ( ) . value , } ; data . push ( chapterUserData ) ; } } await prisma . user_chapter_roles . createMany ( { data } ) ; } ; export default setupRoles ;