diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 3b3d2804..207988c8 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -178,7 +178,7 @@ model Blog { slug String @unique @db.VarChar(200) content String @db.Text excerpt String? @db.Text - authorId String @map("author_id") @db.Uuid + authorId String? @map("author_id") @db.Uuid categoryId String? @map("category_id") @db.Uuid imageUrl String? @map("image_url") @db.Text imageAlt String? @map("image_alt") @db.VarChar(255) @@ -209,7 +209,7 @@ model Blog { createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz() updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz() - author User @relation(fields: [authorId], references: [id]) + author User? @relation(fields: [authorId], references: [id]) category BlogCategory? @relation(fields: [categoryId], references: [id], onDelete: SetNull) tags BlogTag[] comments BlogComment[] diff --git a/backend/src/blogs/blogs.service.spec.ts b/backend/src/blogs/blogs.service.spec.ts index d617785e..df3628a8 100644 --- a/backend/src/blogs/blogs.service.spec.ts +++ b/backend/src/blogs/blogs.service.spec.ts @@ -40,7 +40,7 @@ describe("BlogsService", () => { describe("findAll", () => { it("should query published blogs with pagination", async () => { const blogs = [ - { id: "1", title: "Blog 1", isPublished: true, status: "PUBLISHED" }, + { id: "1", title: "Blog 1", isPublished: true, status: "PUBLISHED", author: null }, ]; mockPrisma.blog.findMany.mockResolvedValue(blogs); mockPrisma.blog.count.mockResolvedValue(1); @@ -49,6 +49,8 @@ describe("BlogsService", () => { expect(mockPrisma.blog.findMany).toHaveBeenCalled(); expect(result.data).toEqual(blogs); expect(result.meta.total).toBe(1); + const query = mockPrisma.blog.findMany.mock.calls[0][0]; + expect(query.include.author).toBeUndefined(); }); it("should filter by categorySlug and search term", async () => { diff --git a/backend/src/blogs/blogs.service.ts b/backend/src/blogs/blogs.service.ts index 370c9758..edcbf302 100644 --- a/backend/src/blogs/blogs.service.ts +++ b/backend/src/blogs/blogs.service.ts @@ -68,9 +68,6 @@ export class BlogsService { [sortBy === "createdAt" ? "createdAt" : "publishedAt"]: sortOrder, }, include: { - author: { - select: { firstName: true, lastName: true }, - }, category: { select: { id: true, name: true, slug: true }, }, @@ -110,7 +107,6 @@ export class BlogsService { take: 4, orderBy: { publishedAt: "desc" }, include: { - author: { select: { firstName: true, lastName: true } }, category: { select: { id: true, name: true, slug: true } }, tags: { select: { id: true, name: true, slug: true } }, _count: { select: { comments: { where: { status: "APPROVED" } } } }, @@ -127,7 +123,6 @@ export class BlogsService { take: 4, orderBy: { publishedAt: "desc" }, include: { - author: { select: { firstName: true, lastName: true } }, category: { select: { id: true, name: true, slug: true } }, tags: { select: { id: true, name: true, slug: true } }, _count: { select: { comments: { where: { status: "APPROVED" } } } }, @@ -163,9 +158,6 @@ export class BlogsService { ], }, include: { - author: { - select: { firstName: true, lastName: true }, - }, category: { select: { id: true, name: true, slug: true }, },