update: add blog slug to the dto

This commit is contained in:
mahyargdz
2025-04-15 12:02:17 +03:30
parent 167cb15e32
commit a5976a3377
5 changed files with 17 additions and 4 deletions
+7 -2
View File
@@ -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 {