Skip to content

Commit

Permalink
fix: 修正文章编辑时没有保存category和title
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Jan 4, 2024
1 parent 461c6f0 commit e47010d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/server/src/app/article/article.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {InjectModel} from '@bangbang93/utils/nest-mongo'
import {Injectable, NotFoundException} from '@nestjs/common'
import Bluebird from 'bluebird'
import htmlSubstring from 'html-substring'
import {compact} from 'lodash'
import {compact, pick} from 'lodash'
import {ObjectId} from 'mongoose-typescript'
import {CategoryModel} from '../category/category.model'
import {CommentModel} from '../comment/comment.model'
Expand All @@ -27,12 +27,15 @@ interface ICreate {
content: string
tags: string[]
slug: string
categories: string[]
}

interface IUpdate {
title: string
content: string
tags: string[]
slug: string
categories: string[]
}

const SUMMARY_LENGTH = 200
Expand All @@ -50,6 +53,7 @@ export class ArticleService {
const summary = htmlSubstring(html, SUMMARY_LENGTH)
const article = await this.articleModel.create({
title: data.title, content: data.content, tags: data.tags, author: data.author, summary, html,
categories: data.categories,
})
await this.articleSearchService.add(article.toObject())
return article
Expand Down Expand Up @@ -130,6 +134,7 @@ export class ArticleService {
const summary = htmlSubstring(html, SUMMARY_LENGTH)
article.html = html
article.summary = summary
article.set(pick(data, 'title', 'slug', 'categories'))
await article.save()
await this.articleSearchService.update(article.toObject())
return article
Expand Down

0 comments on commit e47010d

Please sign in to comment.