chore: update referral logic
This commit is contained in:
@@ -56,9 +56,13 @@ export class BlogsService {
|
||||
//*********************************** */
|
||||
|
||||
async deleteCategory(id: string) {
|
||||
await this.findCategoryById(id);
|
||||
const category = await this.blogCategoriesRepository.findOneBy({ id });
|
||||
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
|
||||
|
||||
await this.blogCategoriesRepository.softDelete(id);
|
||||
await this.blogCategoriesRepository.softDelete({ id });
|
||||
return {
|
||||
message: CommonMessage.DELETED,
|
||||
};
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
@@ -70,7 +74,10 @@ export class BlogsService {
|
||||
await this.blogCategoriesRepository.save(category);
|
||||
|
||||
//
|
||||
return { message: CommonMessage.UPDATE_SUCCESS, category };
|
||||
return {
|
||||
message: CommonMessage.UPDATE_SUCCESS,
|
||||
category,
|
||||
};
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
@@ -146,21 +153,24 @@ export class BlogsService {
|
||||
//*********************************** */
|
||||
|
||||
async deleteBlog(id: string) {
|
||||
await this.findBlogById(id);
|
||||
const blog = await this.blogsRepository.findOneBy({ id });
|
||||
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
||||
|
||||
await this.blogsRepository.softDelete(id);
|
||||
return { message: CommonMessage.DELETED };
|
||||
await this.blogsRepository.softDelete({ id });
|
||||
return {
|
||||
message: CommonMessage.DELETED,
|
||||
};
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
async getBlogById(id: string, isAdmin: boolean = false) {
|
||||
const blog = await this.findBlogById(id);
|
||||
const comments = await this.blogCommentsRepository.findBlogCommentsByBlogId(id);
|
||||
|
||||
if (!isAdmin) {
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
}
|
||||
if (isAdmin) return { blog };
|
||||
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
const comments = await this.blogCommentsRepository.findBlogCommentsByBlogId(id);
|
||||
|
||||
return { blog, comments };
|
||||
}
|
||||
@@ -170,12 +180,13 @@ export class BlogsService {
|
||||
const blog = await this.blogsRepository.findOneBySlug(slug);
|
||||
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
||||
|
||||
if (!isAdmin) {
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
}
|
||||
if (!isAdmin) return { blog };
|
||||
|
||||
return { blog };
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
const comments = await this.blogCommentsRepository.findBlogCommentsByBlogId(blog.id);
|
||||
|
||||
return { blog, comments };
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user