File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { prisma } from "@calcom/prisma" ;
2+
3+ const reassignAttributes = async ( ) => {
4+ const orgId = 0 ;
5+
6+ // Add attribute option id that we want to search against
7+ const lookupAttributeId = "" ;
8+
9+ // Add attribute option ids that we want to assign to users
10+ const attributeIdsToAssign = [ ] ;
11+
12+ // Find all users who have the lookupAttributeId
13+ const usersWithAttribute = await prisma . attributeToUser . findMany ( {
14+ where : {
15+ attributeOptionId : lookupAttributeId ,
16+ member : {
17+ teamId : orgId ,
18+ } ,
19+ } ,
20+ select : {
21+ memberId : true ,
22+ } ,
23+ } ) ;
24+
25+ console . log ( `Found ${ usersWithAttribute . length } users with attribute ${ lookupAttributeId } ` ) ;
26+
27+ // Assign the new attributes to these users
28+ for ( const attributeId of attributeIdsToAssign ) {
29+ const results = await prisma . attributeToUser . createMany ( {
30+ data : usersWithAttribute . map ( ( user ) => ( {
31+ memberId : user . memberId ,
32+ attributeOptionId : attributeId ,
33+ } ) ) ,
34+ skipDuplicates : true , // Skip if user already has this attribute
35+ } ) ;
36+
37+ console . log ( `Assigned attribute ${ attributeId } to ${ results . count } users` ) ;
38+ }
39+ } ;
40+
41+ export default reassignAttributes ( ) ;
You can’t perform that action at this time.
0 commit comments