Skip to content

Commit a1876d5

Browse files
authored
Merge pull request #136 from umc-commit/fix/home
2 parents e98d759 + a20e70f commit a1876d5

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/home/repository/home.repository.js

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ export const HomeRepository = {
66
* 사용자 선호 카테고리 조회
77
*/
88
async findUserCategories(userId) {
9+
// user.id로 account_id를 먼저 조회
10+
const user = await prisma.user.findUnique({
11+
where: { id: BigInt(userId) },
12+
select: { accountId: true }
13+
});
14+
15+
if (!user) return [];
16+
917
const result = await prisma.userCategory.findMany({
10-
where: { userId: BigInt(userId) },
18+
where: { accountId: BigInt(user.accountId) },
1119
select: { categoryId: true }
12-
});
20+
});
1321
return result.map(item => item.categoryId);
1422
},
1523

1624
/**
1725
* 섹션1: 추천 커미션
1826
*/
1927
async findRecommendedCommissions(userId, categoryIds, limit) {
20-
2128
const commissions = await prisma.commission.findMany({
2229
where: {
2330
id: {
@@ -45,7 +52,7 @@ export const HomeRepository = {
4552
}
4653
},
4754
bookmarks: {
48-
where: { userId: BigInt(userId) }
55+
where: { userId: BigInt(userId) }
4956
}
5057
}
5158
});
@@ -85,7 +92,7 @@ export const HomeRepository = {
8592
}
8693
},
8794
bookmarks: {
88-
where: { userId: BigInt(userId) }
95+
where: { userId: BigInt(userId) }
8996
}
9097
}
9198
});
@@ -98,7 +105,6 @@ export const HomeRepository = {
98105
* 섹션3: 신청폭주
99106
*/
100107
async findPopularCommissions(userId, categoryIds, limit) {
101-
102108
const commissions = await prisma.commission.findMany({
103109
where: {
104110
id: {
@@ -139,7 +145,6 @@ export const HomeRepository = {
139145
* 섹션4: 마감임박
140146
*/
141147
async findDeadlineCommissions(userId, categoryIds, limit) {
142-
143148
const commissions = await prisma.commission.findMany({
144149
where: {
145150
categoryId: { in: categoryIds.map(id => BigInt(id)) }
@@ -267,12 +272,20 @@ export const HomeRepository = {
267272
* 사용자가 팔로우한 작가들의 커미션 목록 조회
268273
*/
269274
async findFollowingCommissions(userId, offset, limit) {
275+
// user.id로 account_id를 먼저 조회
276+
const user = await prisma.user.findUnique({
277+
where: { id: BigInt(userId) },
278+
select: { accountId: true }
279+
});
280+
281+
if (!user) return [];
282+
270283
return await prisma.commission.findMany({
271284
where: {
272285
artist: {
273286
follows: {
274287
some: {
275-
userId: BigInt(userId)
288+
accountId: BigInt(user.accountId)
276289
}
277290
}
278291
}
@@ -306,12 +319,20 @@ export const HomeRepository = {
306319
* 사용자가 팔로우한 작가들의 커미션 총 개수 조회
307320
*/
308321
async countFollowingCommissions(userId) {
322+
// user.id로 account_id를 먼저 조회
323+
const user = await prisma.user.findUnique({
324+
where: { id: BigInt(userId) },
325+
select: { accountId: true }
326+
});
327+
328+
if (!user) return 0;
329+
309330
return await prisma.commission.count({
310331
where: {
311332
artist: {
312333
follows: {
313334
some: {
314-
userId: BigInt(userId)
335+
accountId: BigInt(user.accountId)
315336
}
316337
}
317338
}

0 commit comments

Comments
 (0)