import { Injectable } from '@nestjs/common'; import { getBlogImagePublicUrl } from '../../../config/uploadPaths'; import { BlogPost } from '../../blog/entities/BlogPost'; import type { StorefrontBlogPostCardView } from '../types/StorefrontBlogPostCardView'; import type { StorefrontBlogPostDetailView } from '../types/StorefrontBlogPostDetailView'; @Injectable() export class StorefrontBlogViewService { toPostsIndexView(posts: BlogPost[]): StorefrontBlogPostCardView[] { return posts.map(post => ({ id: post.id, title: post.title, thumbnailUrl: post.thumbnailStorageKey ? getBlogImagePublicUrl(post.thumbnailStorageKey) : null, detailHref: `/shop/blog/${post.id}` })); } toPostDetailView(post: BlogPost): StorefrontBlogPostDetailView { return { id: post.id, title: post.title, bannerUrl: post.bannerStorageKey ? getBlogImagePublicUrl(post.bannerStorageKey) : null, thumbnailUrl: post.thumbnailStorageKey ? getBlogImagePublicUrl(post.thumbnailStorageKey) : null, contentHtml: post.contentHtml }; } }