chore: add landing module
This commit is contained in:
@@ -25,6 +25,7 @@ export class CreateBlogDto {
|
||||
@IsNotEmpty({ message: BlogMessage.IMAGE_URL_REQUIRED })
|
||||
@IsString({ message: BlogMessage.IMAGE_URL_STRING })
|
||||
@MaxLength(150, { message: BlogMessage.IMAGE_URL_MAX_LENGTH })
|
||||
@ApiProperty({ description: "Image URL of the blog", example: "https://example.com/image.jpg" })
|
||||
imageUrl: string;
|
||||
|
||||
@IsNotEmpty({ message: BlogMessage.META_TITLE_REQUIRED })
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post, Put, Query } from "@nestjs/common";
|
||||
import { Body, Controller, Delete, Get, HttpCode, HttpStatus, Param, Patch, Post, Query } from "@nestjs/common";
|
||||
import { ApiOperation } from "@nestjs/swagger";
|
||||
|
||||
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
||||
@@ -32,6 +32,13 @@ export class BlogsController {
|
||||
return this.blogsService.getBlogsPublic(queryDto);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Get most visited and pinned blogs" })
|
||||
@SkipAuth()
|
||||
@Get("combined")
|
||||
getCombinedBlogs() {
|
||||
return this.blogsService.getCombinedBlogs();
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Get all blogs (admin route)" })
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.BLOGS)
|
||||
@@ -127,7 +134,7 @@ export class BlogsController {
|
||||
@ApiOperation({ summary: "Update the status of a comment (admin route)" })
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.BLOGS)
|
||||
@Put("comments/:id/status")
|
||||
@Patch("comments/:id/status")
|
||||
updateCommentStatus(@Param() paramDto: ParamDto, @Body() updateCommentStatusDto: UpdateCommentStatusDto) {
|
||||
return this.blogsService.updateCommentStatus(paramDto.id, updateCommentStatusDto);
|
||||
}
|
||||
@@ -162,7 +169,7 @@ export class BlogsController {
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Update a category (admin route)" })
|
||||
@Put("categories/:id")
|
||||
@Patch("categories/:id")
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.BLOGS)
|
||||
updateCategory(@Param() paramDto: ParamDto, @Body() updateCategoryDto: UpdateCategoryDto) {
|
||||
|
||||
@@ -175,8 +175,23 @@ export class BlogsService {
|
||||
//*********************************** */
|
||||
|
||||
async getBlogsPublic(queryDto: BlogSearchQueryDto) {
|
||||
const blogs = await this.blogsRepository.getBlogsForUserSide(queryDto);
|
||||
return { blogs };
|
||||
const [blogs, count] = await this.blogsRepository.getBlogsForUserSide(queryDto);
|
||||
|
||||
//;
|
||||
return {
|
||||
blogs,
|
||||
count,
|
||||
paginate: true,
|
||||
};
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
async getCombinedBlogs() {
|
||||
const [pinnedBlogs, mostVisitedBlogs] = await Promise.all([
|
||||
this.blogsRepository.getPinnedBlogs(),
|
||||
this.blogsRepository.getMostVisitedBlogs(),
|
||||
]);
|
||||
return { pinnedBlogs, mostVisitedBlogs };
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
@@ -244,17 +259,20 @@ export class BlogsService {
|
||||
return category;
|
||||
}
|
||||
|
||||
//*********************************** */
|
||||
async incrementViewCount(id: string) {
|
||||
const blog = await this.findBlogById(id);
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
return { message: "View count incremented successfully" };
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
async getMostVisitedBlogs() {
|
||||
const blogs = await this.blogsRepository.getMostVisitedBlogs();
|
||||
return { blogs };
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
async getPinnedBlogs() {
|
||||
const blogs = await this.blogsRepository.getPinnedBlogs();
|
||||
|
||||
Reference in New Issue
Block a user