fix: bug
This commit is contained in:
@@ -605,6 +605,7 @@ export const enum AdminMessage {
|
||||
ADMIN_UPDATED = "مدیر با موفقیت به روز رسانی شد",
|
||||
ADMIN_NOT_FOUND = "مدیری با این شناسه یافت نشد",
|
||||
ADMIN_DELETED = "مدیر با موفقیت حذف شد",
|
||||
NOT_ALLOWED = "شما مجوز دسترسی به این عملیات را ندارید",
|
||||
}
|
||||
export const enum AdsMessage {
|
||||
TITLE_REQUIRED = "عنوان الزامی است",
|
||||
|
||||
@@ -111,8 +111,8 @@ export class BlogsController {
|
||||
@Delete(":id")
|
||||
@AdminRoute()
|
||||
@PermissionsDec(PermissionEnum.BLOGS)
|
||||
deleteBlog(@Param() paramDto: ParamDto) {
|
||||
return this.blogsService.deleteBlog(paramDto.id);
|
||||
deleteBlog(@Param() paramDto: ParamDto, @UserDec("id") userId: string) {
|
||||
return this.blogsService.deleteBlog(paramDto.id, userId);
|
||||
}
|
||||
|
||||
//-------------- comments --------------
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BadRequestException, Injectable } from "@nestjs/common";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
import { BlogMessage, CommonMessage } from "../../../common/enums/message.enum";
|
||||
import { AdminMessage, BlogMessage, CommonMessage } from "../../../common/enums/message.enum";
|
||||
import { CategoryListSearchQueryDto } from "../../danak-services/DTO/category-search-query.dto";
|
||||
import { UsersService } from "../../users/providers/users.service";
|
||||
import { BlogCommentQueryDto } from "../DTO/blog-comment-query.dto";
|
||||
@@ -56,7 +56,9 @@ export class BlogsService {
|
||||
//*********************************** */
|
||||
|
||||
async deleteCategory(id: string, userId: string) {
|
||||
console.log(userId);
|
||||
const isSuperAdmin = await this.usersService.isSuperAdmin(userId);
|
||||
if (!isSuperAdmin) throw new BadRequestException(AdminMessage.NOT_ALLOWED);
|
||||
|
||||
const category = await this.blogCategoriesRepository.findOneBy({ id });
|
||||
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
|
||||
|
||||
@@ -159,7 +161,10 @@ export class BlogsService {
|
||||
}
|
||||
//*********************************** */
|
||||
|
||||
async deleteBlog(id: string) {
|
||||
async deleteBlog(id: string, userId: string) {
|
||||
const isSuperAdmin = await this.usersService.isSuperAdmin(userId);
|
||||
if (!isSuperAdmin) throw new BadRequestException(AdminMessage.NOT_ALLOWED);
|
||||
|
||||
const blog = await this.blogsRepository.findOneBy({ id });
|
||||
if (!blog) throw new BadRequestException(BlogMessage.BLOG_NOT_FOUND);
|
||||
|
||||
|
||||
@@ -346,6 +346,7 @@ export class UsersService {
|
||||
const superAdmin = await this.userRepository.findOne({ where: { roles: { name: RoleEnum.SUPER_ADMIN } }, relations: { roles: true } });
|
||||
return superAdmin;
|
||||
}
|
||||
/************************************************************ */
|
||||
|
||||
async isSuperAdmin(adminId: string) {
|
||||
const user = await this.userRepository.findOne({ where: { id: adminId }, relations: { roles: true } });
|
||||
|
||||
Reference in New Issue
Block a user