fix: the get blog by slug for the users
This commit is contained in:
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
|
|||||||
username: configService.getOrThrow<string>("DB_USER"),
|
username: configService.getOrThrow<string>("DB_USER"),
|
||||||
password: configService.getOrThrow<string>("DB_PASS"),
|
password: configService.getOrThrow<string>("DB_PASS"),
|
||||||
autoLoadEntities: true,
|
autoLoadEntities: true,
|
||||||
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : false,
|
||||||
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||||
migrationsTableName: "typeorm_migrations",
|
migrationsTableName: "typeorm_migrations",
|
||||||
migrationsRun: false,
|
migrationsRun: false,
|
||||||
|
|||||||
@@ -50,15 +50,15 @@ export class BlogsController {
|
|||||||
@ApiOperation({ summary: "Get a blog by id" })
|
@ApiOperation({ summary: "Get a blog by id" })
|
||||||
@SkipAuth()
|
@SkipAuth()
|
||||||
@Get(":id")
|
@Get(":id")
|
||||||
getBlog(@Param() paramDto: ParamDto) {
|
getBlog(@Param() paramDto: ParamDto, @UserDec("isAdmin") isAdmin: boolean) {
|
||||||
return this.blogsService.getBlogById(paramDto.id);
|
return this.blogsService.getBlogById(paramDto.id, isAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation({ summary: "Get a blog by slug" })
|
@ApiOperation({ summary: "Get a blog by slug" })
|
||||||
@SkipAuth()
|
@SkipAuth()
|
||||||
@Get("slug/:slug")
|
@Get("slug/:slug")
|
||||||
getBlogBySlug(@Param() paramDto: BlogSlugDto) {
|
getBlogBySlug(@Param() paramDto: BlogSlugDto, @UserDec("isAdmin") isAdmin: boolean) {
|
||||||
return this.blogsService.getBlogBySlug(paramDto.slug);
|
return this.blogsService.getBlogBySlug(paramDto.slug, isAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation({ summary: "Get most visited blogs" })
|
@ApiOperation({ summary: "Get most visited blogs" })
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ export class BlogsService {
|
|||||||
const blog = await this.blogsRepository.findOneBySlug(slug);
|
const blog = await this.blogsRepository.findOneBySlug(slug);
|
||||||
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
||||||
|
|
||||||
if (!isAdmin) return { blog };
|
if (isAdmin) return { blog };
|
||||||
|
|
||||||
blog.viewCount += 1;
|
blog.viewCount += 1;
|
||||||
await this.blogsRepository.save(blog);
|
await this.blogsRepository.save(blog);
|
||||||
|
|||||||
Reference in New Issue
Block a user