update: add toggle status of blog
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user