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 ) {} async listLivePosts(): Promise { return this.blogPostRepo.find({ where: { isDraft: false }, order: { createdAt: 'DESC' } }); } async getLivePost(id: string): Promise { const post = await this.blogPostRepo.findOne({ where: { id, isDraft: false } }); if (!post) { throw new NotFoundException('We could not find that blog post.'); } return post; } }