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, filesById: ReadonlyMap = 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, }; } }