Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions src/home/repository/home.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ export const HomeRepository = {
* 사용자 선호 카테고리 조회
*/
async findUserCategories(userId) {
// user.id로 account_id를 먼저 조회
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});

if (!user) return [];

const result = await prisma.userCategory.findMany({
where: { userId: BigInt(userId) },
where: { accountId: BigInt(user.accountId) },
select: { categoryId: true }
});
});
return result.map(item => item.categoryId);
},

/**
* 섹션1: 추천 커미션
*/
async findRecommendedCommissions(userId, categoryIds, limit) {

const commissions = await prisma.commission.findMany({
where: {
id: {
Expand Down Expand Up @@ -45,7 +52,7 @@ export const HomeRepository = {
}
},
bookmarks: {
where: { userId: BigInt(userId) }
where: { userId: BigInt(userId) }
}
}
});
Expand Down Expand Up @@ -85,7 +92,7 @@ export const HomeRepository = {
}
},
bookmarks: {
where: { userId: BigInt(userId) }
where: { userId: BigInt(userId) }
}
}
});
Expand All @@ -98,7 +105,6 @@ export const HomeRepository = {
* 섹션3: 신청폭주
*/
async findPopularCommissions(userId, categoryIds, limit) {

const commissions = await prisma.commission.findMany({
where: {
id: {
Expand Down Expand Up @@ -139,7 +145,6 @@ export const HomeRepository = {
* 섹션4: 마감임박
*/
async findDeadlineCommissions(userId, categoryIds, limit) {

const commissions = await prisma.commission.findMany({
where: {
categoryId: { in: categoryIds.map(id => BigInt(id)) }
Expand Down Expand Up @@ -267,12 +272,20 @@ export const HomeRepository = {
* 사용자가 팔로우한 작가들의 커미션 목록 조회
*/
async findFollowingCommissions(userId, offset, limit) {
// user.id로 account_id를 먼저 조회
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});

if (!user) return [];

return await prisma.commission.findMany({
where: {
artist: {
follows: {
some: {
userId: BigInt(userId)
accountId: BigInt(user.accountId)
}
}
}
Expand Down Expand Up @@ -306,12 +319,20 @@ export const HomeRepository = {
* 사용자가 팔로우한 작가들의 커미션 총 개수 조회
*/
async countFollowingCommissions(userId) {
// user.id로 account_id를 먼저 조회
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});

if (!user) return 0;

return await prisma.commission.count({
where: {
artist: {
follows: {
some: {
userId: BigInt(userId)
accountId: BigInt(user.accountId)
}
}
}
Expand Down