Skip to content

Commit 274e160

Browse files
authored
Merge pull request #144 from umc-commit/fix/search-and-commission
2 parents 08e36e4 + f26db54 commit 274e160

File tree

2 files changed

+121
-94
lines changed

2 files changed

+121
-94
lines changed

src/commission/repository/commission.repository.js

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const CommissionRepository = {
128128
userId: BigInt(userId),
129129
commissionId: BigInt(commissionId),
130130
status: {
131-
notIn: ['CANCELED', 'REJECTED', 'COMPLETED'] // 취소/거절/완료된 것은 제외 (재신청 가능)
131+
notIn: ['CANCELED', 'REJECTED', 'COMPLETED']
132132
}
133133
}
134134
});
@@ -149,15 +149,24 @@ export const CommissionRepository = {
149149
* 커미션 ID로 작가 정보 조회 (팔로우 여부 포함)
150150
*/
151151
async findArtistInfoByCommissionId(commissionId, userId) {
152+
let userAccountId = null;
153+
if (userId) {
154+
const user = await prisma.user.findUnique({
155+
where: { id: BigInt(userId) },
156+
select: { accountId: true }
157+
});
158+
userAccountId = user?.accountId;
159+
}
160+
152161
return await prisma.commission.findUnique({
153162
where: {
154163
id: BigInt(commissionId)
155164
},
156165
include: {
157166
artist: {
158167
include: {
159-
follows: userId ? {
160-
where: { userId: BigInt(userId) }
168+
follows: userAccountId ? {
169+
where: { accountId: BigInt(userAccountId) }
161170
} : false
162171
}
163172
}
@@ -277,61 +286,61 @@ export const CommissionRepository = {
277286
},
278287

279288
/**
280-
* 특정 월에 승인받은 사용자의 리퀘스트 조회 (커미션 리포트용)
281-
*/
282-
async findApprovedRequestsByUserAndMonth(userId, year, month) {
283-
const startDate = new Date(year, month - 1, 1);
284-
const endDate = new Date(year, month, 1);
289+
* 특정 월에 승인받은 사용자의 리퀘스트 조회 (커미션 리포트용)
290+
*/
291+
async findApprovedRequestsByUserAndMonth(userId, year, month) {
292+
const startDate = new Date(year, month - 1, 1);
293+
const endDate = new Date(year, month, 1);
285294

286-
return await prisma.request.findMany({
287-
where: {
288-
userId: BigInt(userId),
289-
approvedAt: {
290-
gte: startDate,
291-
lt: endDate
292-
}
293-
},
294-
include: {
295-
commission: {
296-
select: {
297-
id: true,
298-
categoryId: true,
299-
artist: {
300-
select: {
301-
id: true,
302-
nickname: true,
303-
profileImage: true
304-
}
305-
},
306-
category: {
307-
select: {
308-
name: true
309-
}
310-
}
311-
}
312-
},
313-
reviews: {
314-
select: {
315-
id: true
316-
}
317-
}
318-
}
319-
});
320-
},
295+
return await prisma.request.findMany({
296+
where: {
297+
userId: BigInt(userId),
298+
approvedAt: {
299+
gte: startDate,
300+
lt: endDate
301+
}
302+
},
303+
include: {
304+
commission: {
305+
select: {
306+
id: true,
307+
categoryId: true,
308+
artist: {
309+
select: {
310+
id: true,
311+
nickname: true,
312+
profileImage: true
313+
}
314+
},
315+
category: {
316+
select: {
317+
name: true
318+
}
319+
}
320+
}
321+
},
322+
reviews: {
323+
select: {
324+
id: true
325+
}
326+
}
327+
}
328+
});
329+
},
321330

322-
/**
323-
* 사용자 닉네임 조회
324-
*/
325-
async findUserNicknameById(userId) {
326-
const user = await prisma.user.findUnique({
327-
where: {
328-
id: BigInt(userId)
329-
},
330-
select: {
331-
nickname: true
332-
}
333-
});
334-
335-
return user?.nickname || null;
336-
}
331+
/**
332+
* 사용자 닉네임 조회
333+
*/
334+
async findUserNicknameById(userId) {
335+
const user = await prisma.user.findUnique({
336+
where: {
337+
id: BigInt(userId)
338+
},
339+
select: {
340+
nickname: true
341+
}
342+
});
343+
344+
return user?.nickname || null;
345+
}
337346
}

src/search/repository/search.repository.js

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)