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
8 changes: 6 additions & 2 deletions src/repositories/friend.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
selectRecentLetterByUserIds,
selectLetterDesignByLetterId,
} from "./letter.repository.js";
import { findUserByIdForProfile } from "./user.repository.js";

export async function userExistsFriendRequest(receiverUserId, requesterUserId) {
return await prisma.FriendRequest.findFirst({
Expand Down Expand Up @@ -209,9 +210,10 @@ export async function selectAllFriendsByUserId(userId) {
// 친구별 메타(편지수 + 최근편지 + 디자인) 캐싱
const letterMetaEntries = await Promise.all(
uniqueFriendIds.map(async (fid) => {
const [letterCount, recentLetter] = await Promise.all([
const [letterCount, recentLetter, profile] = await Promise.all([
selectLetterByUserIds(userId, fid), // letterCount 반환한다고 가정
selectRecentLetterByUserIds(userId, fid), // { id, createdAt } 반환한다고 가정
findUserByIdForProfile(fid)
]);

if (!recentLetter) {
Expand All @@ -220,6 +222,7 @@ export async function selectAllFriendsByUserId(userId) {
{
letterCount,
recentLetter: null,
profileImageUrl: profile.profileImageUrl
},
];
}
Expand All @@ -234,11 +237,11 @@ export async function selectAllFriendsByUserId(userId) {
createdAt: recentLetter.createdAt ?? null,
design,
},
profileImageUrl: profile.profileImageUrl
},
];
})
);

const letterMetaByFriendId = new Map(letterMetaEntries);

return rows.map((r) => {
Expand All @@ -252,6 +255,7 @@ export async function selectAllFriendsByUserId(userId) {
id: r.id,
friendUserId,
nickname: nicknameById.get(friendUserId) ?? null,
profileImageUrl: letterMeta.profileImageUrl,
letterCount: letterMeta.letterCount,
recentLetter: letterMeta.recentLetter, // null | { createdAt, letterPaperDesign, letterStampDesign }
};
Expand Down
1 change: 1 addition & 0 deletions src/repositories/user.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ export const findPolicyDocumentByKey = async (key) => {

// ========== Profile Repository ==========
export const findUserByIdForProfile = async (userId) => {
console.log("==================이게 왜 문제야=====================");
return prisma.user.findUnique({
where: { id: userId },
select: {
Expand Down
2 changes: 1 addition & 1 deletion src/services/friend.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const postFriendRequest = async (userId, targetUserId, sessionId) => {
// 2) 친구 목록 조회
export const getFriendsList = async (userId) => {
await userExistsOrThrow(userId);

try {
const friendsList = await selectAllFriendsByUserId(userId);
if (friendsList.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/user.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ALLOWED_JOBS = new Set(["WORKER", "STUDENT", "HOUSEWIFE", "FREELANC
export const toIntArray = (arr) => arr.map((v) => Number(v));

export const LETTER_TYPE_ANON = "TO_OTHER";
export const LETTER_TYPE_SELF = "SELF";
export const LETTER_TYPE_SELF = "TO_ME";

export const makePreview = (text, maxLen = 30) => {
if (!text) return "";
Expand Down