change the blogs service

This commit is contained in:
Pouya Defaei
2026-05-22 21:07:51 +03:30
parent a94a46ad98
commit f36385c53f

View File

@@ -284,21 +284,15 @@ export class BlogsService {
async fetchLastBlogsByLanguage(language: LanguageEnum): Promise<Blog[]> { async fetchLastBlogsByLanguage(language: LanguageEnum): Promise<Blog[]> {
const blogs = await this.blogsRepository const blogs = await this.blogsRepository
.createQueryBuilder("b") .createQueryBuilder("blog")
.leftJoin("b.translations", "t", "t.language = :language", { language }) .select(["blog.id", "blog.featuredImage", "blog.gallery", "blog.href", "blog.publishedAt", "blog.createdAt"])
.leftJoin("b.writer", "w") .leftJoinAndSelect("blog.translations", "translation", "translation.language = :language", { language })
.select("b.id", "id") .leftJoinAndSelect("blog.writer", "writer")
.addSelect("b.featuredImage", "featuredImage") .where("blog.deletedAt IS NULL")
.addSelect("b.href", "href") .andWhere("blog.publishedAt IS NOT NULL")
.addSelect("b.publishedAt", "publishedAt") .orderBy("blog.publishedAt", "DESC")
.addSelect("t.title", "title")
.addSelect("t.description", "description")
.addSelect("w.username", "writer")
.where("b.deletedAt IS NULL")
.andWhere("b.publishedAt IS NOT NULL")
.orderBy("b.publishedAt", "DESC")
.limit(3) .limit(3)
.getRawMany(); .getMany();
return blogs; return blogs;
} }