Skip to content
Merged
Show file tree
Hide file tree
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
125 changes: 67 additions & 58 deletions src/commission/repository/commission.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const CommissionRepository = {
userId: BigInt(userId),
commissionId: BigInt(commissionId),
status: {
notIn: ['CANCELED', 'REJECTED', 'COMPLETED'] // 취소/거절/완료된 것은 제외 (재신청 가능)
notIn: ['CANCELED', 'REJECTED', 'COMPLETED']
}
}
});
Expand All @@ -149,15 +149,24 @@ export const CommissionRepository = {
* 커미션 ID로 작가 정보 조회 (팔로우 여부 포함)
*/
async findArtistInfoByCommissionId(commissionId, userId) {
let userAccountId = null;
if (userId) {
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});
userAccountId = user?.accountId;
}

return await prisma.commission.findUnique({
where: {
id: BigInt(commissionId)
},
include: {
artist: {
include: {
follows: userId ? {
where: { userId: BigInt(userId) }
follows: userAccountId ? {
where: { accountId: BigInt(userAccountId) }
} : false
}
}
Expand Down Expand Up @@ -277,61 +286,61 @@ export const CommissionRepository = {
},

/**
* 특정 월에 승인받은 사용자의 리퀘스트 조회 (커미션 리포트용)
*/
async findApprovedRequestsByUserAndMonth(userId, year, month) {
const startDate = new Date(year, month - 1, 1);
const endDate = new Date(year, month, 1);
* 특정 월에 승인받은 사용자의 리퀘스트 조회 (커미션 리포트용)
*/
async findApprovedRequestsByUserAndMonth(userId, year, month) {
const startDate = new Date(year, month - 1, 1);
const endDate = new Date(year, month, 1);

return await prisma.request.findMany({
where: {
userId: BigInt(userId),
approvedAt: {
gte: startDate,
lt: endDate
}
},
include: {
commission: {
select: {
id: true,
categoryId: true,
artist: {
select: {
id: true,
nickname: true,
profileImage: true
}
},
category: {
select: {
name: true
}
}
}
},
reviews: {
select: {
id: true
}
}
}
});
},
return await prisma.request.findMany({
where: {
userId: BigInt(userId),
approvedAt: {
gte: startDate,
lt: endDate
}
},
include: {
commission: {
select: {
id: true,
categoryId: true,
artist: {
select: {
id: true,
nickname: true,
profileImage: true
}
},
category: {
select: {
name: true
}
}
}
},
reviews: {
select: {
id: true
}
}
}
});
},

/**
* 사용자 닉네임 조회
*/
async findUserNicknameById(userId) {
const user = await prisma.user.findUnique({
where: {
id: BigInt(userId)
},
select: {
nickname: true
}
});
return user?.nickname || null;
}
/**
* 사용자 닉네임 조회
*/
async findUserNicknameById(userId) {
const user = await prisma.user.findUnique({
where: {
id: BigInt(userId)
},
select: {
nickname: true
}
});
return user?.nickname || null;
}
}
90 changes: 54 additions & 36 deletions src/search/repository/search.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,45 @@ export class SearchRepository {
where.deadline = { lte: deadlineValue };
}

// 팔로잉 필터 - AND 조건이 있으면 배열에 추가, 없으면 바로 설정
// 팔로잉 필터 - userId를 accountId로 변환
if (followingOnly && userId) {
const followCondition = {
artist: {
follows: {
some: {
userId: userId
}
}
}
};
// user.id로 account_id 조회
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});

if (where.AND) {
// 태그 검색 + 팔로잉 필터
where.AND.push(followCondition);
} else if (where.artist) {
// 작가 검색 + 팔로잉 필터
where.artist.follows = {
some: {
userId: userId
if (user) {
const followCondition = {
artist: {
follows: {
some: {
accountId: BigInt(user.accountId)
}
}
}
};
} else {
// 팔로잉 필터만
where.artist = {
follows: {

if (where.AND) {
// 태그 검색 + 팔로잉 필터
where.AND.push(followCondition);
} else if (where.artist) {
// 작가 검색 + 팔로잉 필터
where.artist.follows = {
some: {
userId: userId
accountId: BigInt(user.accountId)
}
}
};
};
} else {
// 팔로잉 필터만
where.artist = {
follows: {
some: {
accountId: BigInt(user.accountId)
}
}
};
}
}
}

Expand All @@ -121,6 +129,16 @@ export class SearchRepository {
break;
}

// userId를 accountId로 변환 (팔로우 상태 확인용)
let userAccountId = null;
if (userId) {
const user = await prisma.user.findUnique({
where: { id: BigInt(userId) },
select: { accountId: true }
});
userAccountId = user?.accountId;
}

// 데이터 조회
const [commissions, totalCount] = await Promise.all([
prisma.commission.findMany({
Expand All @@ -137,9 +155,9 @@ export class SearchRepository {
id: true,
nickname: true,
profileImage: true,
...(userId && {
...(userAccountId && {
follows: {
where: { userId },
where: { accountId: BigInt(userAccountId) },
select: { id: true }
}
})
Expand Down Expand Up @@ -174,7 +192,7 @@ export class SearchRepository {

const bookmarks = await prisma.bookmark.findMany({
where: {
userId: userId,
userId: BigInt(userId),
commissionId: { in: commissionIds }
},
select: { commissionId: true }
Expand All @@ -192,7 +210,7 @@ export class SearchRepository {
*/
static async categoryExists(categoryId) {
const category = await prisma.category.findUnique({
where: { id: categoryId }
where: { id: BigInt(categoryId) }
});
return !!category;
}
Expand Down Expand Up @@ -235,22 +253,22 @@ export class SearchRepository {
// 동일한 검색어가 이미 있으면 삭제 후 새로 추가 (최신 순 유지)
await prisma.searchHistory.deleteMany({
where: {
userId: userId,
userId: BigInt(userId),
keyword: keyword
}
});

// 새 검색어 저장
await prisma.searchHistory.create({
data: {
userId: userId,
userId: BigInt(userId),
keyword: keyword
}
});

// 최대 10개까지만 유지 (오래된 검색어 삭제)
const searchHistories = await prisma.searchHistory.findMany({
where: { userId: userId },
where: { userId: BigInt(userId) },
orderBy: { createdAt: 'desc' },
skip: 10 // 최신 10개를 제외한 나머지
});
Expand All @@ -270,7 +288,7 @@ export class SearchRepository {
*/
static async getRecentSearches(userId, limit = 10) {
return await prisma.searchHistory.findMany({
where: { userId: userId },
where: { userId: BigInt(userId) },
orderBy: { createdAt: 'desc' },
take: limit,
select: {
Expand All @@ -287,7 +305,7 @@ export class SearchRepository {
static async deleteRecentSearch(userId, keyword) {
await prisma.searchHistory.deleteMany({
where: {
userId: userId,
userId: BigInt(userId),
keyword: keyword
}
});
Expand All @@ -298,7 +316,7 @@ export class SearchRepository {
*/
static async deleteAllRecentSearches(userId) {
await prisma.searchHistory.deleteMany({
where: { userId: userId }
where: { userId: BigInt(userId) }
});
}
}
}