update: add toggle status of blog

This commit is contained in:
mahyargdz
2025-04-12 16:30:10 +03:30
parent d76b9326e6
commit b1a41235d7
2 changed files with 35 additions and 7 deletions
+18 -7
View File
@@ -244,13 +244,6 @@ export class BlogsService {
return category;
}
//*********************************** */
private async findBlogById(id: string) {
const blog = await this.blogsRepository.findOneById(id);
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
return blog;
}
async incrementViewCount(id: string) {
const blog = await this.findBlogById(id);
blog.viewCount += 1;
@@ -267,6 +260,7 @@ export class BlogsService {
const blogs = await this.blogsRepository.getPinnedBlogs();
return { blogs };
}
//*********************************** */
async togglePinnedStatus(id: string) {
const blog = await this.findBlogById(id);
@@ -274,4 +268,21 @@ export class BlogsService {
await this.blogsRepository.save(blog);
return { message: CommonMessage.UPDATE_SUCCESS, blog };
}
//*********************************** */
async toggleBlogStatus(id: string) {
const blog = await this.findBlogById(id);
blog.isActive = !blog.isActive;
//
await this.blogsRepository.save(blog);
return { message: CommonMessage.UPDATE_SUCCESS, blog };
}
//*********************************** */
private async findBlogById(id: string) {
const blog = await this.blogsRepository.findOneById(id);
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
return blog;
}
}