update: add blog slug to the dto
This commit is contained in:
@@ -673,6 +673,8 @@ export const enum BlogMessage {
|
||||
IS_ACTIVE_SHOULD_BE_1_0 = "وضعیت فعال بودن باید یکی از ۱ یا ۰ باشد",
|
||||
SEARCH_QUERY_STRING = "رشته جستجو باید یک رشته باشد",
|
||||
IS_PINNED_SHOULD_BE_A_BOOLEAN = "وضعیت سنجاق بودن باید یک بولین باشد",
|
||||
SLUG_REQUIRED = "اسلاگ بلاگ الزامی است",
|
||||
SLUG_MAX_LENGTH = "حداکثر طول اسلاگ بلاگ باید ۱۵۰ کاراکتر باشد",
|
||||
}
|
||||
|
||||
export const enum SliderMessage {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -10,6 +10,12 @@ export class CreateBlogDto {
|
||||
@ApiProperty({ description: "Title of the blog", example: "Blog Title" })
|
||||
title: string;
|
||||
|
||||
@IsNotEmpty({ message: BlogMessage.SLUG_REQUIRED })
|
||||
@IsString({ message: BlogMessage.SLUG_STRING })
|
||||
@MaxLength(150, { message: BlogMessage.SLUG_MAX_LENGTH })
|
||||
@ApiProperty({ description: "Slug of the blog", example: "blog-title" })
|
||||
slug: string;
|
||||
|
||||
@IsNotEmpty({ message: BlogMessage.PREVIEW_CONTENT_REQUIRED })
|
||||
@IsString({ message: BlogMessage.PREVIEW_CONTENT_STRING })
|
||||
@MaxLength(150, { message: BlogMessage.PREVIEW_CONTENT_MAX_LENGTH })
|
||||
|
||||
@@ -98,7 +98,7 @@ export class BlogsService {
|
||||
|
||||
const category = await this.findCategoryById(createBlogDto.categoryId);
|
||||
|
||||
const slug = this.generateSlug(createBlogDto.title);
|
||||
const slug = this.generateSlug(createBlogDto.slug);
|
||||
|
||||
const blog = this.blogsRepository.create({
|
||||
...createBlogDto,
|
||||
@@ -123,7 +123,6 @@ export class BlogsService {
|
||||
if (updateBlogDto.title) {
|
||||
const existBlog = await this.blogsRepository.findOne({ where: { title: updateBlogDto.title, id: Not(id) } });
|
||||
if (existBlog) throw new BadRequestException(BlogMessage.BLOG_ALREADY_EXISTS);
|
||||
blog.slug = this.generateSlug(updateBlogDto.title);
|
||||
}
|
||||
|
||||
if (updateBlogDto.categoryId) {
|
||||
@@ -131,6 +130,12 @@ export class BlogsService {
|
||||
blog.category = category;
|
||||
}
|
||||
|
||||
if (updateBlogDto.slug) {
|
||||
const existBlog = await this.blogsRepository.findOne({ where: { slug: updateBlogDto.slug, id: Not(id) } });
|
||||
if (existBlog) throw new BadRequestException(BlogMessage.BLOG_ALREADY_EXISTS);
|
||||
blog.slug = this.generateSlug(updateBlogDto.slug);
|
||||
}
|
||||
|
||||
await this.blogsRepository.save({ ...blog, ...updateBlogDto });
|
||||
|
||||
return {
|
||||
|
||||
@@ -39,7 +39,7 @@ export class BlogCategoriesRepository extends Repository<BlogCategory> {
|
||||
query.andWhere("blogCategory.isActive = :isActive", { isActive: queryDto.isActive });
|
||||
}
|
||||
|
||||
query.skip(skip).take(limit).orderBy({ createdAt: "DESC" });
|
||||
query.skip(skip).take(limit).orderBy("blogCategory.createdAt", "DESC");
|
||||
|
||||
return query.getManyAndCount();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user