HotTRDealsBackend/adapters/responses/comment.adapter.js
2026-01-25 17:50:56 +00:00

35 lines
882 B
JavaScript

const formatDateAsString = (value) =>
value instanceof Date ? value.toISOString() : value ?? null
function mapCommentToDealCommentResponse(comment) {
return {
id: comment.id,
text: comment.text, // eğer DB'de content ise burada text'e çevir
createdAt: formatDateAsString(comment.createdAt),
parentId:comment.parentId,
user: {
id: comment.user.id,
username: comment.user.username,
avatarUrl: comment.user.avatarUrl ?? null,
},
}
}
function mapCommentsToDealCommentResponse(comments) {
return comments.map(mapCommentToDealCommentResponse)
}
function mapCommentToUserCommentResponse(c) {
return {
...mapCommentToDealCommentResponse(c),
deal: { id: c.deal.id, title: c.deal.title },
}
}
module.exports = {
mapCommentToDealCommentResponse,
mapCommentsToDealCommentResponse,
mapCommentToUserCommentResponse
}