@@ -72,37 +72,45 @@ export class SearchRepository {
7272 where . deadline = { lte : deadlineValue } ;
7373 }
7474
75- // 팔로잉 필터 - AND 조건이 있으면 배열에 추가, 없으면 바로 설정
75+ // 팔로잉 필터 - userId를 accountId로 변환
7676 if ( followingOnly && userId ) {
77- const followCondition = {
78- artist : {
79- follows : {
80- some : {
81- userId : userId
82- }
83- }
84- }
85- } ;
77+ // user.id로 account_id 조회
78+ const user = await prisma . user . findUnique ( {
79+ where : { id : BigInt ( userId ) } ,
80+ select : { accountId : true }
81+ } ) ;
8682
87- if ( where . AND ) {
88- // 태그 검색 + 팔로잉 필터
89- where . AND . push ( followCondition ) ;
90- } else if ( where . artist ) {
91- // 작가 검색 + 팔로잉 필터
92- where . artist . follows = {
93- some : {
94- userId : userId
83+ if ( user ) {
84+ const followCondition = {
85+ artist : {
86+ follows : {
87+ some : {
88+ accountId : BigInt ( user . accountId )
89+ }
90+ }
9591 }
9692 } ;
97- } else {
98- // 팔로잉 필터만
99- where . artist = {
100- follows : {
93+
94+ if ( where . AND ) {
95+ // 태그 검색 + 팔로잉 필터
96+ where . AND . push ( followCondition ) ;
97+ } else if ( where . artist ) {
98+ // 작가 검색 + 팔로잉 필터
99+ where . artist . follows = {
101100 some : {
102- userId : userId
101+ accountId : BigInt ( user . accountId )
103102 }
104- }
105- } ;
103+ } ;
104+ } else {
105+ // 팔로잉 필터만
106+ where . artist = {
107+ follows : {
108+ some : {
109+ accountId : BigInt ( user . accountId )
110+ }
111+ }
112+ } ;
113+ }
106114 }
107115 }
108116
@@ -121,6 +129,16 @@ export class SearchRepository {
121129 break ;
122130 }
123131
132+ // userId를 accountId로 변환 (팔로우 상태 확인용)
133+ let userAccountId = null ;
134+ if ( userId ) {
135+ const user = await prisma . user . findUnique ( {
136+ where : { id : BigInt ( userId ) } ,
137+ select : { accountId : true }
138+ } ) ;
139+ userAccountId = user ?. accountId ;
140+ }
141+
124142 // 데이터 조회
125143 const [ commissions , totalCount ] = await Promise . all ( [
126144 prisma . commission . findMany ( {
@@ -137,9 +155,9 @@ export class SearchRepository {
137155 id : true ,
138156 nickname : true ,
139157 profileImage : true ,
140- ...( userId && {
158+ ...( userAccountId && {
141159 follows : {
142- where : { userId } ,
160+ where : { accountId : BigInt ( userAccountId ) } ,
143161 select : { id : true }
144162 }
145163 } )
@@ -174,7 +192,7 @@ export class SearchRepository {
174192
175193 const bookmarks = await prisma . bookmark . findMany ( {
176194 where : {
177- userId : userId ,
195+ userId : BigInt ( userId ) ,
178196 commissionId : { in : commissionIds }
179197 } ,
180198 select : { commissionId : true }
@@ -192,7 +210,7 @@ export class SearchRepository {
192210 */
193211 static async categoryExists ( categoryId ) {
194212 const category = await prisma . category . findUnique ( {
195- where : { id : categoryId }
213+ where : { id : BigInt ( categoryId ) }
196214 } ) ;
197215 return ! ! category ;
198216 }
@@ -235,22 +253,22 @@ export class SearchRepository {
235253 // 동일한 검색어가 이미 있으면 삭제 후 새로 추가 (최신 순 유지)
236254 await prisma . searchHistory . deleteMany ( {
237255 where : {
238- userId : userId ,
256+ userId : BigInt ( userId ) ,
239257 keyword : keyword
240258 }
241259 } ) ;
242260
243261 // 새 검색어 저장
244262 await prisma . searchHistory . create ( {
245263 data : {
246- userId : userId ,
264+ userId : BigInt ( userId ) ,
247265 keyword : keyword
248266 }
249267 } ) ;
250268
251269 // 최대 10개까지만 유지 (오래된 검색어 삭제)
252270 const searchHistories = await prisma . searchHistory . findMany ( {
253- where : { userId : userId } ,
271+ where : { userId : BigInt ( userId ) } ,
254272 orderBy : { createdAt : 'desc' } ,
255273 skip : 10 // 최신 10개를 제외한 나머지
256274 } ) ;
@@ -270,7 +288,7 @@ export class SearchRepository {
270288 */
271289 static async getRecentSearches ( userId , limit = 10 ) {
272290 return await prisma . searchHistory . findMany ( {
273- where : { userId : userId } ,
291+ where : { userId : BigInt ( userId ) } ,
274292 orderBy : { createdAt : 'desc' } ,
275293 take : limit ,
276294 select : {
@@ -287,7 +305,7 @@ export class SearchRepository {
287305 static async deleteRecentSearch ( userId , keyword ) {
288306 await prisma . searchHistory . deleteMany ( {
289307 where : {
290- userId : userId ,
308+ userId : BigInt ( userId ) ,
291309 keyword : keyword
292310 }
293311 } ) ;
@@ -298,7 +316,7 @@ export class SearchRepository {
298316 */
299317 static async deleteAllRecentSearches ( userId ) {
300318 await prisma . searchHistory . deleteMany ( {
301- where : { userId : userId }
319+ where : { userId : BigInt ( userId ) }
302320 } ) ;
303321 }
304- }
322+ }
0 commit comments