update: add blog slug to the dto
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user