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"),
|
||||
password: configService.getOrThrow<string>("DB_PASS"),
|
||||
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,
|
||||
migrationsTableName: "typeorm_migrations",
|
||||
migrationsRun: false,
|
||||
|
||||
@@ -50,15 +50,15 @@ export class BlogsController {
|
||||
@ApiOperation({ summary: "Get a blog by id" })
|
||||
@SkipAuth()
|
||||
@Get(":id")
|
||||
getBlog(@Param() paramDto: ParamDto) {
|
||||
return this.blogsService.getBlogById(paramDto.id);
|
||||
getBlog(@Param() paramDto: ParamDto, @UserDec("isAdmin") isAdmin: boolean) {
|
||||
return this.blogsService.getBlogById(paramDto.id, isAdmin);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Get a blog by slug" })
|
||||
@SkipAuth()
|
||||
@Get("slug/:slug")
|
||||
getBlogBySlug(@Param() paramDto: BlogSlugDto) {
|
||||
return this.blogsService.getBlogBySlug(paramDto.slug);
|
||||
getBlogBySlug(@Param() paramDto: BlogSlugDto, @UserDec("isAdmin") isAdmin: boolean) {
|
||||
return this.blogsService.getBlogBySlug(paramDto.slug, isAdmin);
|
||||
}
|
||||
|
||||
@ApiOperation({ summary: "Get most visited blogs" })
|
||||
|
||||
@@ -183,7 +183,7 @@ export class BlogsService {
|
||||
const blog = await this.blogsRepository.findOneBySlug(slug);
|
||||
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
||||
|
||||
if (!isAdmin) return { blog };
|
||||
if (isAdmin) return { blog };
|
||||
|
||||
blog.viewCount += 1;
|
||||
await this.blogsRepository.save(blog);
|
||||
|
||||
Reference in New Issue
Block a user