Wire blogEnabled into shop render locals and expose public blog index and detail routes when the shop toggle is on.
32 lines
883 B
TypeScript
32 lines
883 B
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
import { Repository } from 'typeorm';
|
|
import { BlogPost } from '../../blog/entities/BlogPost';
|
|
|
|
@Injectable()
|
|
export class StorefrontBlogPostsService {
|
|
constructor(
|
|
@InjectRepository(BlogPost)
|
|
private readonly blogPostRepo: Repository<BlogPost>
|
|
) {}
|
|
|
|
async listLivePosts(): Promise<BlogPost[]> {
|
|
return this.blogPostRepo.find({
|
|
where: { isDraft: false },
|
|
order: { createdAt: 'DESC' }
|
|
});
|
|
}
|
|
|
|
async getLivePost(id: string): Promise<BlogPost> {
|
|
const post = await this.blogPostRepo.findOne({
|
|
where: { id, isDraft: false }
|
|
});
|
|
|
|
if (!post) {
|
|
throw new NotFoundException('We could not find that blog post.');
|
|
}
|
|
|
|
return post;
|
|
}
|
|
}
|