chore: update referral logic
This commit is contained in:
@@ -13,73 +13,66 @@ export class BlogsRepository extends Repository<Blog> {
|
||||
}
|
||||
|
||||
async findOneById(id: string): Promise<Blog | null> {
|
||||
return this.findOne({
|
||||
where: { id, deletedAt: IsNull() },
|
||||
relations: {
|
||||
author: true,
|
||||
category: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
previewContent: true,
|
||||
metaTitle: true,
|
||||
metaDescription: true,
|
||||
imageUrl: true,
|
||||
slug: true,
|
||||
createdAt: true,
|
||||
content: true,
|
||||
tags: true,
|
||||
viewCount: true,
|
||||
isActive: true,
|
||||
isPinned: true,
|
||||
category: {
|
||||
id: true,
|
||||
title: true,
|
||||
iconUrl: true,
|
||||
description: true,
|
||||
},
|
||||
author: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
const queryBuilder = this.createQueryBuilder("blog")
|
||||
.leftJoinAndSelect("blog.author", "author")
|
||||
.leftJoinAndSelect("blog.category", "category")
|
||||
.where("blog.id = :id", { id })
|
||||
.andWhere("blog.deletedAt IS NULL")
|
||||
.select([
|
||||
"blog.id",
|
||||
"blog.title",
|
||||
"blog.previewContent",
|
||||
"blog.metaTitle",
|
||||
"blog.metaDescription",
|
||||
"blog.imageUrl",
|
||||
"blog.slug",
|
||||
"blog.createdAt",
|
||||
"blog.content",
|
||||
"blog.tags",
|
||||
"blog.viewCount",
|
||||
"blog.isActive",
|
||||
"blog.isPinned",
|
||||
"category.id",
|
||||
"category.title",
|
||||
"category.iconUrl",
|
||||
"category.description",
|
||||
"author.id",
|
||||
"author.firstName",
|
||||
"author.lastName",
|
||||
]);
|
||||
|
||||
return queryBuilder.getOne();
|
||||
}
|
||||
|
||||
async findOneBySlug(slug: string): Promise<Blog | null> {
|
||||
return this.findOne({
|
||||
where: { slug, deletedAt: IsNull(), isActive: true },
|
||||
relations: {
|
||||
author: true,
|
||||
category: true,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
previewContent: true,
|
||||
metaTitle: true,
|
||||
metaDescription: true,
|
||||
imageUrl: true,
|
||||
slug: true,
|
||||
createdAt: true,
|
||||
content: true,
|
||||
tags: true,
|
||||
viewCount: true,
|
||||
category: {
|
||||
id: true,
|
||||
title: true,
|
||||
iconUrl: true,
|
||||
description: true,
|
||||
},
|
||||
author: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
const queryBuilder = this.createQueryBuilder("blog")
|
||||
.leftJoinAndSelect("blog.author", "author")
|
||||
.leftJoinAndSelect("blog.category", "category")
|
||||
.where("blog.slug = :slug", { slug })
|
||||
.andWhere("blog.deletedAt IS NULL")
|
||||
.andWhere("blog.isActive = :isActive", { isActive: true })
|
||||
.select([
|
||||
"blog.id",
|
||||
"blog.title",
|
||||
"blog.previewContent",
|
||||
"blog.metaTitle",
|
||||
"blog.metaDescription",
|
||||
"blog.imageUrl",
|
||||
"blog.slug",
|
||||
"blog.createdAt",
|
||||
"blog.content",
|
||||
"blog.tags",
|
||||
"blog.viewCount",
|
||||
"category.id",
|
||||
"category.title",
|
||||
"category.iconUrl",
|
||||
"category.description",
|
||||
"author.id",
|
||||
"author.firstName",
|
||||
"author.lastName",
|
||||
]);
|
||||
|
||||
return queryBuilder.getOne();
|
||||
}
|
||||
|
||||
async fineOneByTitle(title: string): Promise<Blog | null> {
|
||||
|
||||
Reference in New Issue
Block a user