Wire blogEnabled into shop render locals and expose public blog index and detail routes when the shop toggle is on.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
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
|
|
};
|
|
}
|
|
}
|