- CommentAttachment link table (comment <-> file) + migration - fileIds in create/update comment; update replaces the whole set, synced in one transaction with the comment - CommentDto.attachments; empty for deleted comments - Soft delete drops attachments so GC can collect the files - Max 10 files per comment, ordered by upload time (uuid v7) - Registers comments as a file owner - Rename CommentAuthorExpanderService -> CommentExpanderService (expands authors and files) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { Comment } from '../../domain/entities/comment.entity.js';
|
|
import { CommentDto } from '../dto/comment.dto.js';
|
|
import { UserDto } from '../../../user/application/dto/user.dto.js';
|
|
import { FileDto } from '../../../file/application/dto/file.dto.js';
|
|
|
|
export class CommentApplicationMapper {
|
|
static toDto(
|
|
comment: Comment,
|
|
usersById: ReadonlyMap<string, UserDto>,
|
|
filesById: ReadonlyMap<string, FileDto> = new Map(),
|
|
): CommentDto {
|
|
return {
|
|
id: comment.id as string,
|
|
issueId: comment.issueId,
|
|
authorId: comment.authorId,
|
|
author: comment.authorId ? (usersById.get(comment.authorId) ?? null) : null,
|
|
content: comment.isDeleted ? null : comment.content,
|
|
// Файл могли удалить между запросами — такое вложение просто не показываем
|
|
attachments: comment.isDeleted
|
|
? []
|
|
: comment.fileIds.flatMap((fileId) => {
|
|
const file = filesById.get(fileId);
|
|
return file ? [file] : [];
|
|
}),
|
|
editedAt: comment.editedAt,
|
|
deletedAt: comment.deletedAt,
|
|
createdAt: comment.createdAt,
|
|
updatedAt: comment.updatedAt,
|
|
};
|
|
}
|
|
}
|