fix: remove soft delete from the blog category
This commit is contained in:
@@ -717,6 +717,7 @@ export const enum BlogMessage {
|
|||||||
IS_PINNED_SHOULD_BE_A_BOOLEAN = "وضعیت سنجاق بودن باید یک بولین باشد",
|
IS_PINNED_SHOULD_BE_A_BOOLEAN = "وضعیت سنجاق بودن باید یک بولین باشد",
|
||||||
SLUG_REQUIRED = "اسلاگ بلاگ الزامی است",
|
SLUG_REQUIRED = "اسلاگ بلاگ الزامی است",
|
||||||
SLUG_MAX_LENGTH = "حداکثر طول اسلاگ بلاگ باید ۲۵۵ کاراکتر باشد",
|
SLUG_MAX_LENGTH = "حداکثر طول اسلاگ بلاگ باید ۲۵۵ کاراکتر باشد",
|
||||||
|
CATEGORY_HAS_BLOGS = "دسته بندی مورد نظر دارای بلاگ میباشد",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum SliderMessage {
|
export const enum SliderMessage {
|
||||||
|
|||||||
@@ -189,8 +189,8 @@ export class BlogsController {
|
|||||||
@Delete("categories/:id")
|
@Delete("categories/:id")
|
||||||
@AdminRoute()
|
@AdminRoute()
|
||||||
@PermissionsDec(PermissionEnum.BLOGS)
|
@PermissionsDec(PermissionEnum.BLOGS)
|
||||||
deleteCategory(@Param() paramDto: ParamDto) {
|
deleteCategory(@Param() paramDto: ParamDto, @UserDec("id") userId: string) {
|
||||||
return this.blogsService.deleteCategory(paramDto.id);
|
return this.blogsService.deleteCategory(paramDto.id, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation({ summary: "toggle status of categories (admin route)" })
|
@ApiOperation({ summary: "toggle status of categories (admin route)" })
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Column, DeleteDateColumn, Entity, OneToMany } from "typeorm";
|
import { Column, Entity, OneToMany } from "typeorm";
|
||||||
|
|
||||||
import { Blog } from "./blog.entity";
|
import { Blog } from "./blog.entity";
|
||||||
import { BaseEntity } from "../../../common/entities/base.entity";
|
import { BaseEntity } from "../../../common/entities/base.entity";
|
||||||
@@ -19,7 +19,4 @@ export class BlogCategory extends BaseEntity {
|
|||||||
|
|
||||||
@OneToMany(() => Blog, (blog) => blog.category)
|
@OneToMany(() => Blog, (blog) => blog.category)
|
||||||
blogs: Blog[];
|
blogs: Blog[];
|
||||||
|
|
||||||
@DeleteDateColumn()
|
|
||||||
deletedAt?: Date;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,11 +55,15 @@ export class BlogsService {
|
|||||||
}
|
}
|
||||||
//*********************************** */
|
//*********************************** */
|
||||||
|
|
||||||
async deleteCategory(id: string) {
|
async deleteCategory(id: string, userId: string) {
|
||||||
|
console.log(userId);
|
||||||
const category = await this.blogCategoriesRepository.findOneBy({ id });
|
const category = await this.blogCategoriesRepository.findOneBy({ id });
|
||||||
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
|
if (!category) throw new BadRequestException(BlogMessage.CATEGORY_NOT_FOUND);
|
||||||
|
|
||||||
await this.blogCategoriesRepository.delete({ id });
|
const blogs = await this.blogsRepository.find({ where: { category: { id } }, take: 2 });
|
||||||
|
if (blogs.length > 0) throw new BadRequestException(BlogMessage.CATEGORY_HAS_BLOGS);
|
||||||
|
|
||||||
|
await this.blogCategoriesRepository.remove(category);
|
||||||
return {
|
return {
|
||||||
message: CommonMessage.DELETED,
|
message: CommonMessage.DELETED,
|
||||||
};
|
};
|
||||||
@@ -106,7 +110,6 @@ export class BlogsService {
|
|||||||
const category = await this.findCategoryById(createBlogDto.categoryId);
|
const category = await this.findCategoryById(createBlogDto.categoryId);
|
||||||
|
|
||||||
const slug = this.generateSlug(createBlogDto.slug);
|
const slug = this.generateSlug(createBlogDto.slug);
|
||||||
console.log(slug);
|
|
||||||
|
|
||||||
const blog = this.blogsRepository.create({
|
const blog = this.blogsRepository.create({
|
||||||
...createBlogDto,
|
...createBlogDto,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { InjectRepository } from "@nestjs/typeorm";
|
import { InjectRepository } from "@nestjs/typeorm";
|
||||||
import { IsNull, Repository } from "typeorm";
|
import { Repository } from "typeorm";
|
||||||
|
|
||||||
import { CategoryListSearchQueryDto } from "../../danak-services/DTO/category-search-query.dto";
|
import { CategoryListSearchQueryDto } from "../../danak-services/DTO/category-search-query.dto";
|
||||||
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
import { PaginationUtils } from "../../utils/providers/pagination.utils";
|
||||||
@@ -15,13 +15,13 @@ export class BlogCategoriesRepository extends Repository<BlogCategory> {
|
|||||||
|
|
||||||
async findOneById(id: string): Promise<BlogCategory | null> {
|
async findOneById(id: string): Promise<BlogCategory | null> {
|
||||||
return this.findOne({
|
return this.findOne({
|
||||||
where: { id, deletedAt: IsNull() },
|
where: { id },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCategoriesUserSide() {
|
async getCategoriesUserSide() {
|
||||||
return this.find({
|
return this.find({
|
||||||
where: { isActive: true, deletedAt: IsNull() },
|
where: { isActive: true },
|
||||||
order: { createdAt: "DESC" },
|
order: { createdAt: "DESC" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,8 +98,9 @@ export class CreateServiceDto {
|
|||||||
@ApiProperty({ description: "The images of the service", example: ["https://example.com/image1.png", "https://example.com/image2.png"] })
|
@ApiProperty({ description: "The images of the service", example: ["https://example.com/image1.png", "https://example.com/image2.png"] })
|
||||||
images: string[];
|
images: string[];
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
@IsNotEmpty({ message: ServiceMessage.COVER_URL_REQUIRED })
|
@IsNotEmpty({ message: ServiceMessage.COVER_URL_REQUIRED })
|
||||||
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.COVER_URL_SHOULD_BE_URL })
|
@IsUrl({ protocols: ["http", "https"], require_protocol: true }, { message: ServiceMessage.COVER_URL_SHOULD_BE_URL })
|
||||||
@ApiProperty({ description: "The cover url of the service", example: "https://example.com/cover.png" })
|
@ApiProperty({ description: "The cover url of the service", example: "https://example.com/cover.png" })
|
||||||
coverUrl: string;
|
coverUrl?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user