@@ -14,8 +14,9 @@ export async function POST(req: Request) {
1414 }
1515
1616 const data = await req . json ( ) ;
17- const { profile, image, name, interests = [ ] , connections = [ ] , coreValues = [ ] , causeAreas = [ ] } = data ;
17+ const { profile, image, name, interests = [ ] , connections = [ ] , coreValues = [ ] , books = [ ] , causeAreas = [ ] } = data ;
1818
19+ console . log ( 'books: ' , books )
1920 Object . keys ( profile ) . forEach ( key => {
2021 if ( profile [ key ] === '' || ! profile [ key ] ) {
2122 delete profile [ key ] ;
@@ -71,6 +72,8 @@ export async function POST(req: Request) {
7172 profileConnection : prisma . profileConnection ,
7273 value : prisma . value ,
7374 profileValue : prisma . profileValue ,
75+ book : prisma . book ,
76+ profileBook : prisma . profileBook ,
7477 causeArea : prisma . causeArea ,
7578 profileCauseArea : prisma . profileCauseArea ,
7679 } as const ;
@@ -79,7 +82,7 @@ export async function POST(req: Request) {
7982
8083 async function handleFeatures ( features : any , attribute : ModelKey , profileAttribute : string , idName : string ) {
8184 // Add new features
82- if ( features . length > 0 && updatedUser . profile ) {
85+ if ( features !== null && updatedUser . profile ) {
8386 // First, find or create all features
8487 console . log ( 'profile' , profileAttribute , profileAttribute ) ;
8588 const operations = features . map ( ( feat : { id ?: string ; name : string } ) =>
@@ -95,25 +98,31 @@ export async function POST(req: Request) {
9598 // Get the IDs of all created/updated features
9699 const ids = createdFeatures . map ( v => v . id ) ;
97100
98- // First, remove all existing interests for this profile
99- await modelMap [ profileAttribute ] . deleteMany ( {
100- where : { profileId : updatedUser . profile . id } ,
101+ const profileId = updatedUser . profile . id ;
102+ console . log ( 'profile ID:' , profileId ) ;
103+
104+ // First, remove all existing features for this profile
105+ const res = await modelMap [ profileAttribute ] . deleteMany ( {
106+ where : { profileId : profileId } ,
101107 } ) ;
108+ console . log ( 'deleted profile:' , profileAttribute , res ) ;
102109
103- // Then, create new connections
110+ // Then, create new features
104111 if ( ids . length > 0 ) {
105- await modelMap [ profileAttribute ] . createMany ( {
112+ const create_res = await modelMap [ profileAttribute ] . createMany ( {
106113 data : ids . map ( id => ( {
107- profileId : updatedUser . profile ! . id ,
114+ profileId : profileId ,
108115 [ idName ] : id ,
109116 } ) ) ,
110117 skipDuplicates : true ,
111118 } ) ;
119+ console . log ( 'created many:' , profileAttribute , create_res ) ;
112120 }
113121 }
114122 }
115123
116124 await handleFeatures ( interests , 'interest' , 'profileInterest' , 'interestId' )
125+ await handleFeatures ( books , 'book' , 'profileBook' , 'valueId' )
117126 await handleFeatures ( connections , 'connection' , 'profileConnection' , 'connectionId' )
118127 await handleFeatures ( coreValues , 'value' , 'profileValue' , 'valueId' )
119128 await handleFeatures ( causeAreas , 'causeArea' , 'profileCauseArea' , 'causeAreaId' )
0 commit comments