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
1 change: 1 addition & 0 deletions src/chat/dto/chatroom.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ChatroomListResponseDto {
this.artist_profile_image = room.artist.profileImage;
this.commission_id = room.commission.id;
this.commission_title = room.commission.title;
this.commission_thumbnail = room.commission.thumbnail || null;
// 이미지가 있으면 이미지 URL, 없으면 텍스트 content
const lastMsg = room.chatMessages[0];
this.last_message = lastMsg?.imageUrl || lastMsg?.content || null;
Expand Down
15 changes: 11 additions & 4 deletions src/chat/service/chatroom.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,23 @@ export const ChatroomService = {

async getChatroomsByUserId(dto) {
const user = await UserRepository.findUserById(dto.userId);
if (!user) {
throw new UserNotFoundError({ userId: dto.userId });
}
if (!user) throw new UserNotFoundError({ userId: dto.userId });

const chatrooms = await ChatroomRepository.findChatroomsByUser(dto.userId);
console.log(dto.accountId)

// thumbnail 한 번에 조회
const commissionIds = chatrooms.map(r => r.commission.id);
const images = await CommissionRepository.findImagesByCommissionId(commissionIds);
const thumbnailMap = Object.fromEntries(images.map(img => [img.targetId.toString(), img.imageUrl]));

// DTO 생성
const result = [];
for (const room of chatrooms) {
room.commission.thumbnail = thumbnailMap[room.commission.id.toString()] || null;

// 방마다 unreadCount 조회
const unreadCount = await ChatRepository.countUnreadMessages(room.id, dto.accountId);

result.push(new ChatroomListResponseDto(room, unreadCount));
}

Expand Down
45 changes: 20 additions & 25 deletions src/commission/service/commission.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,30 @@ export const CommissionService = {
* S3 이미지 업로드 처리
*/
async uploadRequestImage(file) {
try {
// 1. 파일 존재 여부 확인
if (!file) {
throw new ImageUploadFailedError({ reason: '파일이 업로드되지 않았습니다' });
}

// 2. 파일 크기 검증
if (file.size > 10 * 1024 * 1024) {
throw new FileSizeExceededError({ fileSize: file.size });
}
// 1. 파일 존재 여부 확인
if (!file) {
throw new ImageUploadFailedError({ reason: '파일이 업로드되지 않았습니다' });
}

// 3. 파일 확장자 검증
const ext = path.extname(file.originalname).toLowerCase().replace('.', '');
if (!['jpeg', 'jpg', 'png'].includes(ext)) {
throw new UnsupportedImageFormatError({ fileType: file.mimetype });
}
// 2. 파일 크기 검증
if (file.size > 10 * 1024 * 1024) {
throw new FileSizeExceededError({ fileSize: file.size });
}

// 4. S3 업로드 (requests 폴더에 저장)
const imageUrl = await uploadToS3(file.buffer, 'requests', ext);
// 3. 파일 확장자 검증
const ext = path.extname(file.originalname).toLowerCase().replace('.', '');
if (!['jpeg', 'jpg', 'png'].includes(ext)) {
throw new UnsupportedImageFormatError({ fileType: file.mimetype });
}

return {
image_url: imageUrl,
file_size: file.size,
file_type: file.mimetype
};
// 4. S3 업로드
const imageUrl = await uploadToS3(file.buffer, 'requests', ext);

} catch (error) {
throw error;
}
return {
image_url: imageUrl,
file_size: file.size,
file_type: file.mimetype
};
},

/**
Expand Down
1 change: 1 addition & 0 deletions src/common/swagger/chat.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"artist_profile_image": { "type": "string", "example": "https://example.com/artist1.png" },
"commission_id": { "type": "string", "example": "1" },
"commission_title": { "type": "string", "example": "테스트 커미션 글" },
"commission_thumbnail": { "type": ["string", "null"], "example": "https://example.com/sample-thumbnail.png" },
"last_message": { "type": ["string", "null"], "example": null },
"last_message_time": { "type": ["string", "null"], "format": "date-time", "example": null },
"has_unread": { "type": "integer", "example": 0 }
Expand Down