feat: complete app democking, fix types, add blogs api
This commit is contained in:
1 parent
6027e635db
commit
945c007a79
25 files changed
+557
-56
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Injectable()
|
||||
export class BlogsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll() {
|
||||
return this.prisma.blog.findMany({
|
||||
where: { isPublished: true },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: {
|
||||
author: {
|
||||
select: { firstName: true, lastName: true }
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async findOneBySlug(slug: string) {
|
||||
const blog = await this.prisma.blog.findUnique({
|
||||
where: { slug, isPublished: true },
|
||||
include: {
|
||||
author: {
|
||||
select: { firstName: true, lastName: true }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!blog) {
|
||||
throw new NotFoundException('مقاله یافت نشد');
|
||||
}
|
||||
|
||||
return blog;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user